This project demonstrates how to create a Custom Pass in Unity's High Definition Render Pipeline (HDRP) that uses a Compute Shader to process and render a texture on the camera's output in real-time.
- Create a GameObject in your scene.
- Add a
Custom Pass Volumecomponent to the GameObject:- Menu path:
GameObject > Volume > Custom Pass Volume.
- Menu path:
- Enable “Is Global” on the Custom Pass Volume if you want it to affect all cameras.
- Add the
MyComputeShaderPass.csscript as a Custom Pass in the Custom Pass Volume’s list. - In the Inspector, assign your Compute Shader to the
computeShaderfield. - Run the scene — the compute shader will process and render to the camera output in real-time.
-
The
RenderTextureis created and resized automatically based on the camera’s current resolution. -
The script uses
ctx.hdCamera.camerato access the correctCamerainstance during rendering. -
You can enable or disable the writing of the processed texture using the
enableWritingboolean. -
Make sure your compute shader has a kernel named
CSMainand a RWTexture2D namedResult.