Skip to content

Unity sample project using instancing and per-instance shader properties in Ray Tracing

Notifications You must be signed in to change notification settings

INedelcu/RayTracingMeshInstancingSimple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RayTracingMeshInstancingSimple

Unity sample project using instancing and per-instance shader properties in Ray Tracing.

Description

The project uses RayTracingAccelerationStructure.AddInstances function to add many ray tracing instances of a Mesh to an acceleration structure. The project doesn't use a render pipeline or rasterization.

Resource binding for hit shaders is done through shader tables and shader records. Writing shader records can be an expensive CPU operation when Materials are complex and use many resources and properties. When using AddInstances function, all ray tracing instances associated with the specified Mesh will use the same shader record which can notably improve CPU performance.

In hit shaders, per-instance shader properties are accessed using the difference between HLSL intrinsic InstanceIndex() and built-in shader variable unity_BaseInstanceID. For example:

uint instanceID = InstanceIndex() - unity_BaseInstanceID;

Check MeshInstancing.shader where per-instance color is read from a buffer.

RayTracingInstanceData.cs computes per-instance transformation matrices and colors.

After opening the project, switch to Game view and press Play to animate the geometries.

Prerequisites

Resources

About

Unity sample project using instancing and per-instance shader properties in Ray Tracing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published