Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question [DXR] aabb structure depth sorting

Discussion in 'Graphics Experimental Previews' started by arTk_ev, Oct 16, 2021.

  1. arTk_ev

    arTk_ev

    Joined:
    Mar 24, 2013
    Posts:
    11
    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?

    Code (CSharp):
    1. [shader("raygeneration")]
    2. TraceRay(_RaytracingAccelerationStructure,  0, 0xFF, 0, 0, 0, rayDesc, rayPayload);
    Code (CSharp):
    1. [shader("intersection")]
    2. void IntersectionMain()
    3. {
    4.      float3 or = WorldRayOrigin();
    5.      float3 dir = WorldRayDirection();
    6.      const int pointId = PrimitiveIndex();
    7.      const int offsetId = InstanceID();
    8.      float hitDist = RayTCurrent();
    9.      const float3 col = colorsGB[pointId+offsetId];
    10.      AttributeData2 attr;
    11.      attr.color = col;
    12.      ReportHit(hitDist, 0, attr);
    13. }
    unity 2021.2.0b16, legacy pipline
     

    Attached Files:

    • dxr.png
      dxr.png
      File size:
      841.5 KB
      Views:
      267
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    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 https://iquilezles.org/www/articles/boxfunctions/boxfunctions.htm
    • 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!
     

    Attached Files:

    rz_0lento likes this.
  3. arTk_ev

    arTk_ev

    Joined:
    Mar 24, 2013
    Posts:
    11
    Thank you. It helped a lot.