After some messing around, I fixed it!
So I have 4 cel shaders for slightly different use cases.
The solution: In EACH cel shader, I have to define global, multi-compile boolean keywords
“_MAIN_LIGHT_SHADOWS” and “_MAIN_LIGHT_SHADOWS_CASCADE” . Otherwise shadows just don’t work.
On top of this, I think it’s necessary for me to use the MainLightRealtimeShadow function. Here’s the tricky part: over the past year figuring this stuff out, I found solutions that told me to copy-paste the code inside of MainLightRealtimeShadow, hence my code in previous posts.
I think what was happening was, because that code was being copied out of the function, it was being pasted into some place without the correct defines or accessible variables or something. I’m not sure, working in HLSL is honestly incomprehensible because there seem to be like 100 accessible magic variables and functions at any given time and my IDE doesn’t help with autocomplete.
This, combined with me having keywords not set to the magic values of “MULTI_COMPILE” and “GLOBAL” led to some insane cascade bug but only in the build process.
void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
Direction = half3(0.5,0.5,0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = MainLightRealtimeShadow(shadowCoord);
#endif
}
Anyways… I don’t know who writes the docs, but the definitions of “Global/Local” and "Multi compile’, etc… are very confusing to someone who has not been writing HLSL for years.
Moreover, writing custom shader code is confusing as well because of all the stuff that’s ‘magically there’… and there’s no real good way to teach myself this. It’s not even a matter of ‘okay sure, I can use these HLSL functions Unity made, and that makes sense’, but logically I don’t understand why/how they’re even accessible in the first place.
I forgot to mention that this is all for an Unlit Master Node using SG 7.4.1.This reminded me of this thread I found a year ago or so, where you DO have to define (in EACH shader) those two keywords I mentioned, set to Multi Compile and Global. (Not 100% sure on multi compile but it seems to make shadows disappear in builds if I don’t have it set to Multi Compile).
It’s possible that these keywords are now autodefined or something in later versions of Shader Graph, but I’m not sure.