- Home /
Modifying shaders' snippets.
Greetings all!
I was wondering what is the best practice to modify some of Unity's existing shaders snippets. To be more precise, I'm currently looking at the Standard and Standard (Specular setup) shaders because I wish to change how their Opacity output is managed.
My goal is to build a ghost/spirit shader based on Unity 5 physically based shader, meaning I wish to make it so that the Z-buffer is read and only the first faces of the mesh is shown through the transparency. It's nothing that strange and it has been done plenty of times with the legacy shaders.
It's not only for my project, but also to learn more about Unity physically based shaders management so please, don't post anything about some shaders from the store asset as it's not the point of my question.
Okay. Now the thing is that I now understand how the default standard shader is working in Unity as I looked up the .shader and .cginc files. That much is clear and I'm able to work with it.
But the thing is that I would like to modify some of them for a project, but as .cginc files aren't directly within the project files like the ones you can get for learning purpose, I'm not sure how I can replace the content of the shaders' snippets within a project without risking some conflict between the hidden and modified snippets.
Does importing a .cginc file in the unity project with snippets automatically replace the existing default snippets or will I have to literally recreate the whole standard shader and its whole set of .cginc files with modified snippets references just for the sake of modifying a single part of the rendering process? (That's 1 shader + 9 .cginc files to recreate and modify with different snippets names. That's would be a huge pain in the butt to be honest and I'm not even thinking about the risk of errors.)
Thanks in advance!
P.S. The reason why I'm trying to do it this way instead of just building the shader from scratch is because I would like to add this within the Rendering Modes of the Standard and Standard (Specular Setup) shaders. I think about adding a X-Ray (0 to 1) slider that makes overlapping parts from the same mesh invisible if behind another part of the same mesh. (So that it's possible to make a material that is like the current fade or transparent, but using the same shader to make z-based fade and transparency.
If this is possible and I succeed, I'll add the file as free asset on the Asset Store. ;)
Answer by Max_Bol · May 15, 2016 at 05:41 PM
After testing things out, I have found out that you can modify snippets and any hidden content in Unity by using the same name convention within your own project. Any hidden system (or shader in this case) files functions are automatically replaced by those in the project's folder.
So, you can modify any shader snippets by creating .cginc file with the modified snippets properly named, but it seems like you have to copy the whole original file and then modify it for it to work properly as, once the reference within the .cginc files change, it "forget" about the original .cginc file.
That's the result of my tests. Due to this, I looked for a less perfect yet really useful solution you can find here : Link to the forum page
Your answer
![](https://koobas.hobune.stream/wayback/20220612080704im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making objects less transparent when light hits them (lighting only shader) 1 Answer
Grabpass 2D water reflection, UV issue 0 Answers
How to move alpha mask along the floor plane as the user (camera) moves 1 Answer
Is it possible to avoid writing to certain g-buffers? 1 Answer
My shader code is having an error with returns at lines 50 and 60. 1 Answer