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

[Raytracing] RayQuery and TraceInline

Discussion in 'Graphics Experimental Previews' started by okluckej_unity, Aug 30, 2020.

  1. okluckej_unity

    okluckej_unity

    Joined:
    Aug 30, 2020
    Posts:
    11
    Hi,

    have anyone tried to use inline raytracing in Unity? Currently I'm working on some side project, that requires unified handling of Miss/ClosestHit. I would love to resolve rayhits/miss localy in one shader instead of scattering logic across all viable raytracing shaders and making changes to Unity HDRP shaders.

    Problem is that shader compiler doesn't understand RayQuery and won't compile the raytracing shader.

    Thanks for any suggestions or answer
     
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    DXR 1.1 (RayQueries from compute shaders) is work in progress and will probably be available in 2021.1.
     
  3. okluckej_unity

    okluckej_unity

    Joined:
    Aug 30, 2020
    Posts:
    11
    Thanks for response, will be looking for that.

    How does Unity handles situations with multiple ClosestHit/Miss shaders defined in separate shaders/materials on single renderer?
     
  4. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    The shader Pass that is used during ray tracing setup is selected using RayTracingShader.SetShaderPass or CommandBuffer.SetRayTracingShaderPass depending whether you are working with command buffers or not.

    https://docs.unity3d.com/2020.2/Doc...Rendering.RayTracingShader.SetShaderPass.html
    https://docs.unity3d.com/2020.2/Doc...ng.CommandBuffer.SetRayTracingShaderPass.html

    You can have a Renderer that uses multiple materials (sub meshes). They just need to have a shader Pass with that name.

    You can have a .shader that has multiple shader Passes with different names with ray tracing shaders in them (closest hit / any hit / intersection shaders).

    Multiple closest hit / any hit shaders in the same shader Pass are not supported at this moment.

    You can check this post here for an example with a project from scratch that does ray tracing:
    https://forum.unity.com/threads/dxr-raytracing-effect-from-scratch.794928/#post-6266142
     
  5. okluckej_unity

    okluckej_unity

    Joined:
    Aug 30, 2020
    Posts:
    11
    Great, it's working :) informations verified as very usefull. I've made a great leap forward ;)
     
    INedelcu likes this.
  6. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Is there any plan to support inline ray tracing in raygeneration and closesthit shader? I tried that with Unity 2021.2.b4, however it's not support since ray tracing shaders was compiled with lib_6_3 target profile.
     
  7. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Hi @INedelcu any progress on DXR 1.1 and RayQueries from Compute Shaders support in Unity? The 2022.1 is already in late beta.
    Thanks!
     
    vx4 likes this.
  8. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi! DXR 1.1 support is not a priority anymore right now and was postponed. The priority is to add Terrain and VFX support to the acceleration structure and also perf. improvements.

    For DXR 1.1, binding Materials data to compute shaders is challenging since Unity doesn't use an unified Material system or uber shaders. Having access to just the acceleration structure in a compute shader can get you shadows or ambient occlusion for example if you have only opaque Materials in your scene but once you introduce alpha tested Materials you might want to sample some Material textures in you compute shader to perform alpha testing when a ray hits a geometry.
     
    vx4 likes this.
  9. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Thanks for your answear @INedelcu Actually, I am not interested in graphics rendering but using raytracing for physics simulation (collision detection for softbodies). So having possibility to do RayQueries straight from Compute Shaders would be excellent for me. I don't need any material data, just raw triangleId from the Acceleration Structure.

    Please keep upgrade to DXR 1.1 on your to-do list!

    Cheers
     
    vx4 likes this.
  10. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Is there any plan to support multiple closest/any hit within a shader pass?
     
  11. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi! Currently no.
     
  12. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    macrod and vx4 like this.
  13. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
  14. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    @korzen303 Check DXR specs here for the workflow of a RayQuery. Some examples are found here.
     
  15. vx4

    vx4

    Joined:
    Dec 11, 2012
    Posts:
    181
    thx for amazing update.
    Just i have some question.
    1- Are we still limited to bind only one acceleration structure in compute shader.
    2- Also is there a plan to be able to used inline ray tracing in VFX graph which is higly antcipted.
     
  16. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi!

    - In ComputeShader you can bind multiple acceleration structures.
    - I'm not familiar with VFX graph myself but inline ray tracing is not currently used by any other features.
     
    Last edited: Nov 7, 2022
    vx4 likes this.
  17. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Does it mean Unity uses a newer version of dxc compiler? Can we use HLSL 2021 with the new compiler? template function is very useful in advance shader programming.
     
  18. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    @hellkbd RayQuery is a class template so you should be able to use templates as you like when using dxcompiler. Check this thread for more information about dxcompiler in Unity.
     
  19. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    I think that's a different thing, in order to use user-defined template functions with dxc, you have to use compiler arguments "-HV 2021" based on dxc release note https://github.com/microsoft/DirectXShaderCompiler/releases
     
  20. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    When I try to use CommandBuffer.SetRayTracingAccelerationStructure(computeShader) on Alpha 20, I'm getting...

    Code (CSharp):
    1. Unknown RenderingCommandBuffer command: 22 (previous command: 11) in
    2. UnityEngine.Rendering.ScriptableRenderContext:ExecuteCommandBuffer (UnityEngine.Rendering.CommandBuffer)