Files
2026-11-01 23:39:55 +02:00

1.4 KiB

Release your ray tracing objects

You must free up the memory your ray tracing objects use after you finish with them.

Dispose of the following:

Note: Unity automatically disposes of RayTracingResources and IRayTracingShader.

For example:

RayTracingContext rtContext = new RayTracingContext(rtResources);
IRayTracingShader rtShader = rtContext.LoadRayTracingShader("Assets/yourShader.urtshader");
IRayTracingAccelStruct rtAccelStruct = rtContext.CreateAccelerationStructure(new AccelerationStructureOptions());
GraphicsBuffer rtScratchBuffer = RayTracingHelper.CreateScratchBufferForBuild(rtAccelStruct);

// ... create and dispatch your ray tracing command buffers ...

rtScratchBuffer.Dispose();
rtAccelStruct.Dispose();
rtContext.Dispose();