You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 lenCHUNK_SIDE ^ 3
ofu32
s, eachu32
is an offset inghost_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.
The text was updated successfully, but these errors were encountered: