So, I’ve been working on a project with a custom toon shader using the Universal render pipeline. Everything is working well except that when I build the game multiple effects within the shader graph stop working.
The most noticeable is the cast shadows disappearing. I am using a custom hlsl function within the unlit shadergraph to get the main light information. It works fine in editor but something with the shadow attenuation isn’t working in build. Shadows on URP default materials are showing up and other lit shadergraph materials, it is only my custom toon shaded materials that are encountering this issue which leads me to believe its either a bug with custom functions in shadergraph or something I have messed up. My custom function for intercepting SSAO is also not appearing in the build. I am assuming for similar reasons, but I can’t find out what those are for the life of me. I suspect it’s something to do with the multi-compile keywords but I’m not really well versed in shader code enough to say for sure. Any help would be appreciated.
Hey ! Did you ever find a solution to this ? I’ve been having the exact same issue, following a tutorial from the exact same channel. everything working fine in editor, and then not working on Build.
Edit : for anyone having the issue, found a solution from this thread
they changed the format of the keywords so the solution is to write it like this in the .hlsl file
Old keywords variant: #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
New variant: #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
Try to disable shader variant stripping in the project settings to see whether that is the cause. If yes, you’ll have to create a shader variant collection to avoid that used variants are getting stripped. Alternatively, you could also create a few dummy materials with the used variants.
This happens when you have variants that are only referenced in code. In that case, Unity doesn’t find a reference to the variant and strips it.