Sarroxxie / vk_procedural_displacement

The goal is to create tesselation free procedural displacement.
Apache License 2.0
0 stars 0 forks source link

BLAS construction #16

Open Sarroxxie opened 2 years ago

Sarroxxie commented 2 years ago

BLAS construction has to be done via Affine Arithmetics -> should be recomputed on "displacement-amount" change! This will result in tighter bounding boxes.

ib00 commented 1 year ago

Where and how do you construct BLAS right now?

Sarroxxie commented 1 year ago

AABB creation for a triangle is done here (I was referring to this with BLAS, the Vulkan part works just fine): https://github.com/Sarroxxie/vk_procedural_displacement/blob/master/ray_tracing__displacement/hello_vulkan.cpp#L1334C56-L1334C56

The bounding box for a triangle is currently just calculated by adding the max displacement amount to the vertices of the triangle in world space and then taking the min-max of the displaced vertices and the triangle vertices. This bounding box is guaranteed to be big enough to fit any possible displacement into the AABB as long as the per vertex normals of the triangle point in the same direction. However, this can fail for triangles with per vertex normals. I quickly put together a 2D example in Inkscape, hope it helps. As the displacement is applied to interpolated normals, they have to be considered when creating the AABB. The affine arithmetics (that are also used inside the intersection shader) have the property to guarantee just that. If you want details on the math behind this, I recommend reading Appendix A of the paper Tessellation-Free Displacement Mapping. AABB_explaination

ib00 commented 1 year ago

Thanks for explanation!