Hello Guest

Author Topic: How to combine tk2d shaders with my own shaders  (Read 5365 times)

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
How to combine tk2d shaders with my own shaders
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to combine tk2d shaders with my own shaders
« Reply #1 on: June 21, 2014, 08:13:38 pm »
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...

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: How to combine tk2d shaders with my own shaders
« Reply #2 on: June 22, 2014, 08:17:06 pm »
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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to combine tk2d shaders with my own shaders
« Reply #3 on: June 22, 2014, 10:33:10 pm »
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

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: How to combine tk2d shaders with my own shaders
« Reply #4 on: June 22, 2014, 11:20:48 pm »
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