Does Raytracing support instancing in HDRP 12.1?

Awesome with append buffer support. Looking forward to this.

@INedelcu hows the progress so far. Cant wait to play with this. Any chance to share a sample code? :blush:

Hi!

Currently, the low level PS5 support is being implemented by the PS team. The target for landing the feature is between October and December.

Here’s some snippets from the project with many cubes. I will upload the project to git when the feature is finally available.

The main cs script using the new AddInstancesIndirect function: IndirectInstancingDemo.cs (18.5 KB)

This is the compute shader that does instance culling (I can’t attach the file)


#pragma kernel main

StructuredBuffer<float4x4> InstanceMatricesBeforeCulling;

RWStructuredBuffer<float4x4> InstanceMatricesAfterCulling;
RWStructuredBuffer<uint> InstanceIndices;

// Not reading or writing into the buffer. Just using the internal counter.
RWStructuredBuffer<uint> InstanceCount;

float4 CameraPosAndRadius2;
uint TotalInstanceCount;

[numthreads(64,1,1)]
void main (uint3 id : SV_DispatchThreadID)
{	
    if (id.x >= TotalInstanceCount)
        return;
		
	float4x4 instanceMatrix = InstanceMatricesBeforeCulling[id.x];

	float3 instancePos = float3(instanceMatrix[0][3], instanceMatrix[1][3], instanceMatrix[2][3]);

	if (dot(instancePos - CameraPosAndRadius2.xyz, instancePos - CameraPosAndRadius2.xyz) < CameraPosAndRadius2.w)
    {
        uint currentInstanceIndex = InstanceCount.IncrementCounter();
        InstanceMatricesAfterCulling[currentInstanceIndex] = instanceMatrix;
        InstanceIndices[currentInstanceIndex] = id.x;

    }
}

There will be a similar AddInstancesIndirect function that takes a mesh config RayTracingMeshInstanceConfig

Any news of this coming out for Unity 6 sometime? Would really love to use it!

Hi! AddInstancesIndirect was merged into Unity 6.1 alpha 2.

I uploaded a test project here: GitHub - INedelcu/AddInstancesIndirect: RayTracingAccelerationStructure.AddInstancesIndirect test

1 Like