For the last 3 days, I have been working on a shader for a small project of mine.
It runs through the Built-In rendering pipeline for those who wonders.
To make things easier for me, I’m usually using Toon Color Pro 2 asset which really helps creating an optimized and simplified shader to start with. (It’s especially useful as it allow me to implement the relevant codes for some third party plugins like Curved World 2020 and so on.)
Long story short, my shader is custom made to allows me to generate “snow” and “dampness” in my scene by simply using 2 global float value. I’m using the simple trick of checking the angle of each faces (via the shader) to compare if the level is alright to display the snow or the texture colors. Dampness is a bit similar, but instead it make the color slightly darker. (The game visual has no specular… or at least for now, but the infrastructure for it is already in if I ever need it.)
At one point, I decided to scrap the basic color selection for something a bit more controllable: The vertex color.
This is so that I can change the color of the snow or regular colors by changing the vertex colors from things like explosions or blood. The game is a low polygon styled game. (It’s rather simple to modify the color of a vertex from white to red, when a character is shot for example or to add some “dark” spot at the point of an explosion.)
Still, when I tried to switch the color for the vertex color, I couldn’t see any change in the scene and all my previous work on the weather effects stopped working. In case I broke something, I tried to undo my work and even as the code was exactly as before I tried to change the color source, the weather effect was still not visible. (To make it clear, the weather effects were working 100% prior to the small changes that I did undo after the bug started.)
At one point, I was at a lost of words as to what I could do to fix it or where the problem was.
I decided to do a funky thing and check if it had any effects: I delete the whole content of the Surface function (the line under the surf() function where you check up the colors from colors pickers and textures.) This means that the model would be, normally, pure black since no color data or alpha data or normal data are being calculated.
But strangely, that had no effect at all. It was as if the scene’s materials were stuck with an old version of the shader.
Following this, I tried to copy my shader and give its copy a new name. The copy appears in the list of shader for my materials, but the result of selecting it was still the same as before: no change.
I also tried to restart Unity, but the bug was still present.
For some reason the Color selection (that I previously attempted to remove) was still working, but some of the other parameters in the material weren’t working (or more like were updating anymore as they were also stuck with the old textures, colors and colors)
As a last resort, I created a new shader from scratch.
Initially, I attempted to do a small visible change to see if the bug was affecting the new shader.
The first good news in a the bunch of hours I wasted on this bug: The small change worked perfectly!
I opened the old shader and the new shader and copy/pasted the additional bits and changes I made in the old one (that doesn’t work) into the new one (that works) and the changes and code now work properly in the new shader.
The old shader is still bugged. I’ll put it as a attached file for anyone who might want to check it out and try it out (you’ll need at least Curved World 2020 + Toon Color Pro 2 from the asset store to make it work.)
Have anyone faced this kind of issue before where materials wouldn’t update anymore after modifying the shader? I’m posting about it because this was really wrecking my nerves as I was trying to find how to fix this. There might have been a simpler solution than remaking the shader from scratch?
6697492–768514–WorldShaderv2.shader (9.38 KB)