[DXR] aabb structure depth sorting

Hello.
I use multiple aabb structure. Its working, but hits not sorting. Working like function AcceptHitAndEndSearch();
Also Anyhit shader not working, just do anything.
How can I fix it?

[shader("raygeneration")]
TraceRay(_RaytracingAccelerationStructure,  0, 0xFF, 0, 0, 0, rayDesc, rayPayload);
[shader("intersection")]
void IntersectionMain()
{
     float3 or = WorldRayOrigin();
     float3 dir = WorldRayDirection();
     const int pointId = PrimitiveIndex();
     const int offsetId = InstanceID();
     float hitDist = RayTCurrent();
     const float3 col = colorsGB[pointId+offsetId];
     AttributeData2 attr;
     attr.color = col;
     ReportHit(hitDist, 0, attr);
}

unity 2021.2.0b16, legacy pipline

Hi!

Here’s a test project - BuiltInRP_AABBs.zip

  • RayTracingTest.cs generates an acceleration structure out of a list of AABBs.

  • Check the Camera where the script is attached together with other setup.

  • The intersection shader is the one that calculates the intersection t based on a ray-box intersection test.

  • The ray-box intersection test is based on Inigo Quilez :: computer graphics, mathematics, shaders, fractals, demoscene and more

  • The intersection shader reads from a texture to do an alpha test to figure out if it was an actual hit and reports the hit.

  • The intersection shader passes a normal to the closest hit shader for basic lighting calculation.

  • Check the Material that’s attached to the script (on the main Camera) and uses the intersection shader. The Texture with an alpha channel is there.

  • You can click on Play and navigate through the scene with WASD keys + hold right mouse button down.

  • You can also change the light direction.

Hope this helps!


7581700–939781–BuiltInRP_AABBs.zip (8.13 MB)

1 Like

Thank you. It helped a lot.