2D Toolkit Forum
2D Toolkit => Support => Topic started by: Afro-Ninja on June 20, 2014, 04:15:06 am
-
So far for all of my sprites I have used the 'LitBlendVertexColor' shader that comes with tk2d. This allows me to add basic lighting effects to my sprites.
What if I want to add custom effects in addition to the existing lighting shader? I understand that I can edit the shader and add my own snippets in. But what if I make a second shader? I would have to keep copy/pasting the original tk2d Shader code into it, which is very redundant.
I also understand I could implement my own decision tree inside of the shader (if effect = this, do that) but from what I understand, using conditionals in a shader is a bad idea. especially if I want to support many different effects.
Is there a way to "include" the necessary parts of the tk2d shader so I don't have to rewrite or copy paste it every time I want to work on a new effect?
-
You can only include the CG part of the shader in Unity AFAIK - but the tk2d shaders are like the most basic shader you could build in Unity - return texture * vcol... You could use unity shader keywords to help, but with a shader so simple I don't think theres the need for the added complexity...
-
from my understanding in a shader such as 'litblendvertexcolor', the top part of the shader takes care of mapping the uv coords, and the bottom part takes care of the lighting.
As long as I leave the bottom part alone I should be able to modify anything in the top part and retain the lighting afterwards?
-
No, not really. Thats a surface shader - the code there is pretty much standard in any surface shader. http://docs.unity3d.com/Manual/SL-SurfaceShaders.html
-
Gotcha. I was just confused because the second part of that shader has a subshader and inside it doesn't seem to make use of a surface, vert, or fragment function
http://pastebin.com/pACwRVwK