Shader Graph - Sample Custom Color Buffer From Custom Function

I am trying to make a fullscreen shader that requires sampling the custom color buffer multiple times, so I figured the best way to do that loop is via a custom function - but I’ve been unable to figure out how to sample the buffer from HLSL, specifically with a Shader Graph custom function.

“SampleCustomColor” errors out as an “undeclared identifier”. Same as, “CustomPassLoadCustomColor”, or “CustomPassSampleCustomColor”.

The dependencies are included (#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl), and the shader works as expected in a .shader, but not in a .hlsl referenced in Shader Graph.

Am I (hopefully) missing something, or is this functionality not available in custom functions?

Using:

  • Unity 2022.3.48f1
  • HDRP 14.0.11
  • Shader Graph 14.0.11

Hey,

The function “SampleCustomColor” should work fine in a custom node but unfortunately, you’ll not be able to use the preview of the node as it doesn’t have access to HDRP-specific data. In the ShaderGraph editor, your shader will appear broken but it should work in the game/scene view and have 0 errors in the inspector.

Other functions like CustomPassLoadCustomColor or CustomPassSampleCustomColor are in the CustomPassSampling.hlsl source file which is not included by default. If you want to use those, you need to set your custom function node to “File” mode and include this file at the top of your HLSL file before writing your functions.

2 Likes

Got it, thanks Antoinel!

1 Like