Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Octree ray tracing #2442

Closed
wants to merge 88 commits into from
Closed

Conversation

cphyc
Copy link
Member

@cphyc cphyc commented Feb 5, 2020

Implements a ray tracer for octree.
See the tests for how to use it.

The datasets are RAMSES datasets, with a single CPU and an AMR structure with levelmin=1, i.e. the octree is complete from the root node.

TODO

  • make it work for sparse octrees,
  • handle multiple domains (need to switch the ray from one octree to another one),
  • handle leaf cells that are not selected,
  • make this work for rays sent in negative directions (-x, -y, -z),
  • wire things together with the volume renderer.

@ngoldbaum
Copy link
Member

Wow cool!

Note for reviewers that this depends on the octree ghost zones PR and that should be merged first.

Have any eye candy from a RAMSES output?

@cphyc
Copy link
Member Author

cphyc commented Feb 5, 2020

ipyvolume
In blue, the result of a YTRay and in red (with a small offset), the result from the ray tracing algorithm!

@cphyc
Copy link
Member Author

cphyc commented Feb 6, 2020

Here's a somehow nicer example. This is a Kelvin-Helmoltz instability with RAMSES (only a single AMR domain for now). The shader is simply the maximum of the density field along the ray.
plot

In this specific case, a simple mip projection could have been done with yt.(OffAxis)ProjectionPlot, but this demonstrates that the machinery works correctly.


Let's imagine you have a 3D data source (ds.all_data(), ds.sphere(...), ...) and let us call it ad.
The way the algorithm works is as follows:

  1. Compute the mapping from oct and cell index (in-memory index) to index within data source (the order it appears in ad),
  2. Cast a ray through the entire domain: this yields a list of oct and cell index, as well as t-values (coordinate along the line of sight),
  3. Reconstruct the index of the data in the data source and extract data. We now have two vectors t and data along the line of sight (their size will be different for each ray),
  4. Apply some shader to the vector(s)
  5. Display the image.

In the example above, the shader is simply the function lambda data: data.max(). Note that step 1 need only be done once per domain and steps 2-4 are embarrassingly parallel. The computation time scales linearly with the number of pixels. I think the algorithm scales as N log(N), with N the number of octs in the whole domain. This could easily be reduced to n log(n) with n the number of octs in ad.

Regarding performance, the above picture (256² pixels) has been computed in 3s, and the dataset is made of 500,000 octs (~2,000,000 leaf cells).

@cphyc
Copy link
Member Author

cphyc commented Feb 10, 2020

A bit more eye candy (in the extent of my artistic capacities): this is a volume rendering of a RAMSES cosmological simulation (64²). Red green and blue indicate the 10⁻²⁹, 10⁻²⁸ and 10⁻²⁷ g/cm³ contours (normalized so that the maximum intensity is 100% in each channel).
index

One main caveat is that the low-order of the integration makes the result look very boxy when going towards higher resolutions. Here's the same image, now with 512² pixels (and a slightly different integration).
index_512

The origin of the boxy look is probably the fact that the interpolation is only performed along the line of sight and does not make use of the neighbouring cell's values. This could in principle be solved using e.g. a trilinear interpolation with the vertices values obtained from ghost zones (see #2425).

@cphyc cphyc added help wanted Contributions from external projects' maintainers is particularly appreciated ! new feature Something fun and new! viz: volume rendering labels Feb 19, 2020
@cphyc cphyc mentioned this pull request May 27, 2020
8 tasks
@cphyc
Copy link
Member Author

cphyc commented May 27, 2020

Closing this one in favour of #2610 .

@cphyc cphyc closed this May 27, 2020
@cphyc cphyc deleted the octree-ray-tracing branch January 13, 2021 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions from external projects' maintainers is particularly appreciated ! new feature Something fun and new! viz: volume rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants