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

Value set for the InstanceID() intrinsics

Discussion in 'HDRP Ray Tracing' started by qjero, Jan 28, 2021.

  1. qjero

    qjero

    Joined:
    Mar 28, 2016
    Posts:
    2
    Hi,

    I am probably missing something simple but is there a way to know what value unity passed to the system inside RayTracingAccelerationStructure.AddInstance for what becomes the InstanceID() shader code intrinsics value?

    I understand InstanceID() to be a user defined id so I expected to be able to set it myself in AddInstance, or perhaps have AddInstance tell me what it set... it didn't seem to be the call order.

    I need to know on the C# side so I can setup lookup tables indexable by InstanceID() in shader. As a temporary workaround I am doing a cumbersome id resolve pass that allows me to read those ids back for all the objects I have.
     
    MaxBellot likes this.
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi!

    Currently every instance in DXR has an unique instance ID associated and they are ranging from 0 up to the number of instances in the acceleration structure. Unfortunately they are not configurable at the moment. We can add the ID to the AddInstance function and we can also make another function for setting it separately, similarly to RayTracingAccelerationStructure.UpdateInstanceMask (2021.1 +).
     
    MaxBellot likes this.
  3. qjero

    qjero

    Joined:
    Mar 28, 2016
    Posts:
    2
    Hi,

    Thanks for the confirmation. For the current version, in the context of quick testing if the id allocation algorithm currently used internally is simple enough and predictable, just being able to reproduce it in user code to mirror the id allocation sequence would still be quite helpful, even if temporary.

    For making it configurable, what you said sounds good. Setting separately anytime sure sounds flexible but I don't know what the implications are for you... personally for now I don't plan to change the id I pass to a newly added instance...

    By the way thanks a lot for the BuiltInRP sample you posted in another thread, it has been really helpful.
     
  4. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    No problem!

    I made another hobby project here https://github.com/INedelcu/PathTracingDemo if you are interested. It's a bare bone path tracer and it has its own (very simple) material definition - one for opaque and one for transparent surfaces (glass). It supports only emissive surfaces and env. lighting that comes from the cubemap that is set up on the main camera.

    Check https://github.com/INedelcu/PathTracingDemo/blob/main/Assets/Scripts/PathTracingDemo.cs - the script that drives the path tracer.
     
    qjero likes this.
  5. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    Hi!

    Starting with 2021.2.0a9 there will be 2 new functions available in RayTracingAccelerationStructure : UpdateInstanceID and GetInstanceCount. Also, AddInstance will have an additional instanceID parameter.
     
    Q-Ted likes this.