Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Multiple raytracing acceleration structures in a raytrace shader gives wrong results

Discussion in 'General Graphics' started by Yacker, Oct 9, 2023.

  1. Yacker

    Yacker

    Joined:
    Oct 24, 2018
    Posts:
    34
    Essentially, only the latest set acceleration structure seems to work. Attempting to cast rays with any but the latest one set results in anything it hits simply eating the ray and not actually executing the closesthit shader. Note, this also prevents it from executing the miss shader, so it IS hitting it, just not executing the proper code.

    Is this a bug, limitation, or am I just missing something?
     
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    158
    Hi! Multiple acceleration structures are not supported. Only the last one set will be bound to shaders.
     
  3. Yacker

    Yacker

    Joined:
    Oct 24, 2018
    Posts:
    34
    This makes me sad, but I made a work around anyways. Just shoved off the things I needed in the second acceleration structure really far away and offset my rays over there when I needed to trace against them. It's not ideal, but I suppose it works anyways.
     
  4. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    158
    You can also use ray-instance masking. When you add instances to an acceleration structure you can specify an instance mask and when you cast rays with TraceRay HLSL function you can specify the same mask.
    For example:
    rtas.AddInstance(..., 1, ...) and
    rtas.AddInstance(..., 2, ...) for the mask argument and in HLSL you can mask the instances:
    TraceRay(..., 1, ...) or TraceRay(..., 2, ...) for InstanceInclusionMask argument.