- Home /
How to merge two shaders
Here is the situation: i have a shader and want to write another shader that is a slight modification of previous one - it takes result from first shader applies some modifications and outputs result.
For example: i have a shader that implements simple diffuse lightning and i want to a have shader that implements diffuse lighting and inverts colors(for example) but i don't want to reimplement diffuse lightning one more time.
Is there a way for such thing?
Answer by iwaldrop · Apr 02, 2013 at 09:30 PM
Actually, your question title tells you exactly what you need to do. You cannot feed data from one shader to another, but you can combine the work that is done from multiple shaders into one.
Computers don't care what you do or don't want to do. :)
But think of it this way; you don't need to reimplement your diffuse shader; just copy paste it into the new one!
Yeah this is an obvious option with obvious shortco$$anonymous$$gs - insane code duplication. I was hoping that unity shader preprocessor had a way of doing such task in smarter way.