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
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

If your ray tracing anyhit shaders aren't getting called...

Discussion in 'Graphics Experimental Previews' started by zf_jon, Jan 14, 2022.

  1. zf_jon

    zf_jon

    Joined:
    Aug 15, 2018
    Posts:
    41
    If you set your RayTracingAccelerationStructure to ManagementMode.Automatic, your any hit shaders will not be called at all.

    You need to use Manual mode + AddInstance with flags/settings that will allow anyhit shaders. Or have the material set to "RenderType"="Transparent". If you have issues, set that tag on all passes! I found that if the first (raster) pass is "RenderType"="Opaque" then my anyhit shader still won't be called on my raytrace pass! (Unity 2021.2.7f1)

    Really wish that was documented somewhere (obvious?) before spending so long figuring it out.
     
    mgear and berbecarul like this.
  2. berbecarul

    berbecarul

    Joined:
    Apr 7, 2017
    Posts:
    2
    Thank you for posting this!
     
  3. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    176
    Hi!

    In Unity 2022, a new function called RayTracingAccelerationStructure.CullInstances was added. It offers many filtering and culling parameters. You can for example specify which materials are considered transparent or alpha tested and it can do efficient SIMD/multithreaded culling. It's orders of magnitude faster than adding Renderers one by one using AddInstance.
     
    hugokostic and Invertex like this.