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

Massive Ghost optimization #20

Open
jacopograndi opened this issue Dec 29, 2023 · 1 comment
Open

Massive Ghost optimization #20

jacopograndi opened this issue Dec 29, 2023 · 1 comment
Labels
performance Benchmarking and optimization

Comments

@jacopograndi
Copy link
Owner

The current ghost implementation checks the intersection for every ghost for every pixel. This is fine when the ghosts are less than 100. I plan to display much more than that, say 100k. We'll see.

The optimization is to construct a 3d grid of cubes with side 1m in which every cell is a bit. 1 if the bounding box of a Ghost is intersecting it, 0 if no Ghost is intersecting it. This grid is aligned with the one in Universe.
This grid can either be a bit in Block or have it's own buffer (it's 32 times smaller than the Universe, we can probably write it every frame).

Along with the grid, there is a hashmap. This hashmap, given a position within the grid, will provide a list of all Ghosts that are intersecting the cube at the position.
Hashmap aren't a type which is available in wgsl (the shading language), so we'll make our own.
A hashmap needs a hash function that maps a lot of inputs to a few outputs. The hash function i'm thinking of is (pos / CHUNK_SIDE).floor().
The list of Ghosts can be encoded as (list.len(), ghost_id0, ghost_id1, ..) into a buffer -> ghost_mask_lists.
The hashmap can be a buffer -> ghost_mask of len CHUNK_SIDE ^ 3 of u32s, each u32 is an offset in ghost_mask_lists

This way, when a ray is raytracing it's way inside the Universe, it can also check if this block has any Ghosts. It can then get a list of ghosts to check intersections given the position of the current ray.

If we don't have big Ghosts (like 3m wide, which we don't), then we are done. If we want another optimization we can cache the results of the checks agaist Ghosts we already did for each ray.

@jacopograndi jacopograndi added the performance Benchmarking and optimization label Dec 29, 2023
@jacopograndi
Copy link
Owner Author

Another crazy idea is to calculate a depth buffer when raytracing. After the trace step, run the normal 3d pipeline. The depth buffer will clip all the 3d geometry which is behind the raytraced scene. Very uncertain on feasibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Benchmarking and optimization
Projects
None yet
Development

No branches or pull requests

1 participant