Thursday, January 16, 2020

shaders - How to mix effects together?


Lets say I have got terrain effect, contains multitexturing, light. Now water effect. It must be different, but must be also affected by light. Other one, player effect, must also be affected by light, but doesn't share much stuff with others.


How all of these should be mixed together to create proper effect? Should I write multiple techniques in single effect file, or should I split it to as many as possibile and choose which are needed when rendering?



Answer



There are many ways to do it; you can write different techniques which stitch together many different shaders (you can use multiple passes to get what you want), you can write lots of pixel/vertex shaders and call lots of common functions and you can also write one massive pixel/vertex shader and use your fields to determine the flow through the algorithm (for example having a flag to determine if it should add lighting and water effects in the pixel shader). Not to mention the fact that you can apply lots of effects post process, even lighting (check out deferred rendering / deferred shading / deferred lighting, I guess deferred is the key word there). Post process effects involve rendering to a render target then running pixel shader passes on it like you would with a sprite.


However, if you want to just play around with a few different effects you can try rendering the object multiple times with different effects. To combine them all you have to do is render the first one normally and perform each subsequent render with blending turned on. It's not efficient at all, nor entirely accurate in all cases. But it's a good way to play around.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...