How to stack shaders

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

I have a CanvasLayer singleton that I am using for transition effects between scenes in my game. This CavasLayer contains a screen-sized ColorRect child with a shader (canvas_type unshaded) that does various screen wipes when its uniforms are animated using an AnimationPlayer. This shader changes the COLOR of the screen depending on the values of its uniforms.

I also have a CRT shader (canvas_Type unshaded) that I want to use in my game, at
the same time that these screen transition effects are taking place.

I tried to add another ColorRect to my CanvasLayer, this time with the CRT shader on it, higher in the heierarchy than the other ColorRect I am using for the screen transitions.

Unfortunately, because both shaders change COLOR, the shader lower in the hierarchy always cancels out the shader higher up. Basically, only one shader can work at a time.

Is there a way to stack shaders using ColorRects similar to the way I’ve been trying?

If not, what’s an alternative solution? I really like the idea of keeping my shaders separate depending on what they do. I don’t want to combine them into a single shader if it can be avoided.

:bust_in_silhouette: Reply From: path9263

If you open your material in the inspector one option should be Next Pass. You can then specify the next shader/material to apply on top of the current material. If your second shader is still canceling out the first then maybe you need to adjust the alpha of your second shader so as to let some of the color from the first pass through.