I am writing a shader that will interpolate between two sets of lightmaps (night and day). I have it working correctly as a vertex/fragment shader. I realized recently, that I also need dynamic lights as well. I found the Normal-Diffuse.shader and it works perfectly - it just needs the custom interpolation code.
What I need now is to have the Normal-Diffuse (Legacy Diffuse) as a vertex/fragment shader. I clicked “Show Generated Code”, copied the results of this back into the shader and it still works (the file is around 1750 lines of code).
The problem I am having is that when I edit the code, the changes don’t seem to be reflected. The generated shader contains the original surface shader code. When I edit this, it changes. But when I edit the generated fragment and vertex code (the stuff I need to change), nothing changes. Even introducing errors doesn’t seem to affect anything. Is it incorrectly thinking it is still a surface shader? Is there any way to fix this? Is this even a possible way to do this?
You don’t want to use the generated code. Download the “Built-in shaders” package for your given Unity version, and browse through the CGINC files that the shaders use, you’ll find all the vert/frag functions that the surface shaders end up using and can adapt them for your own usage.
Do a “Search for Text” in files, for that whole built-in shaders folder, and just search for the term “Lambert”. You’ll find all the Lambert related sections.
If you look at the Standard.shader, you can see how it doesn’t even have any surface shaders in it, it just has passes that references CGINC files. In these CGINC files you can find the vert/frag passes for these types of shader passes and figure out how they’re working and then implement them how you like. This is the “template” for a surface shader basically. But the Lambert shader just has a different Lighting Model set on it, so it will have some lighting functions swapped out for Lambert labelled versions.