Unity Shader-Graph Custom Function - Where is the problem?

In my shadergraph, i am using a custom function that is compltely running fine on the previews of my nodes (as you can see on the image), but, the preview and result on a material makes it bug (you can also see it on the image)

Though I don’t understand what is wrong…

Here is my custom function:

#if defined(SHADERGRAPH_PREVIEW)
	Direction = half3(0.5, 0.5, 0);
	Color = 1;
#else
	Light light = GetMainLight();
	Direction = light.direction;
	Color = light.color;
#endif

The errors thrown are the following :
Shader error in 'Shader Graphs/ToonShader': 'MainLight_float': output parameter 'Direction' not completely initialized at line 312 (on d3d11)
Shader error in 'Master': 'MainLight_float': output parameter 'Direction' not completely initialized at line 344 (on d3d11)

NB : This is supposed to be a Toon Shader, I use this function by doing a Dot Product with the Direction outputed, and with the Normal Vector (In World space).


From what I've seen, it is probably because the "GetMainLight" function is only there on URP, and I am using the built-in renderer pipeline

In case this is your final observation/resolution it would be great if you could post it as not a comment but a regular post and mark it as a solution.

Sadly, it is not a solution yet... The error subsided even after switching to URP...

2 Answers

2

Based on your comment below your question it seems you’re using the built-in render pipeline. Shader Graph is only supported by SRPs (URP, HDRP, LWRP, …). Shader Graph had some backwards compatibility for some time for the built-in pipeline but that is not officially supported or maintained

I switched to URP just to test out everything... Still the error subsided. Now, the shader error comes from the 'Master'. Same output parameter 'Direction' being partially initialized

I just installed the URP in my test project, created a URP asset, assigned it in the graphics settings of my project settings, I copied your code into a custom function node and it seems to work. I don't have your shader, so I just used the light direction as the color for my object and I can see the color change as I rotate my main light.

The problem got solved, It is indeed because I was on the Built-In Render Pipeline.
Switching to URP and making a new graph (compatible with URP) solved the issue.