Value set for the InstanceID() intrinsics

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.

1 Like

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 +).

1 Like

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.

No problem!

I made another hobby project here GitHub - INedelcu/PathTracingDemo: A path tracing demo using hardware accelerated ray tracing in Unity 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 PathTracingDemo/Assets/Scripts/PathTracingDemo.cs at main · INedelcu/PathTracingDemo · GitHub - the script that drives the path tracer.

1 Like

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.

1 Like