- Home /
Gradient two shaders together?
Hi,
I have two shaders that I'd like to apply to the same material (side of an object) so that they blend like a gradient from one to the other.
Is there a way to do this? Or a work-around?
Thanks,
A
Answer by JonPQ · Jul 12, 2019 at 04:18 PM
If it really is 2 different materials, with 2 different shaders.... its tricky... you have to draw twice... make sure both shaders support alpha, I would recommend using vertex color/alpha for the blend gradient. Though texture alpha can work too, you might already be using the texture's alpha for something else... Draw the mesh once with the first shader... then draw the socond one on top, using 1-vertex alpha for the blend value in the shader.
If you can get away with the same shader , but 2 different textures that you want to blend.... then you can do it in 1 regular draw call. with a shader that blends 2 textures... based either on texture alpha or vertex alpha... you can probably find one like this searching on unity shader wiki
3rd option is to use a shader that uses a 3rd texture channel for the blend control.
https://wiki.unity3d.com/index.php/Shaders
https://forum.unity.com/threads/texture-blending.18395/
https://wiki.unity3d.com/index.php/Blend_2_Textures (if you are code savvy, you could modify this one in a line or two to use vertex alpha, or texture alpha as the blend, instead of the blend color input, to allow a gradient)
https://wiki.unity3d.com/index.php/Transparent_Cutout_Soft_Edge_Unlit_Texture_Blend
Your answer
Follow this Question
Related Questions
How to force the compilation of a shader in Unity? 5 Answers
Semi transparent Object behind walls? 1 Answer
Fresnel shader on raw image 0 Answers
DX11 shader model 5 unavailable 0 Answers
Cubemap on Android 1 Answer