- Home /
Fade Shader- One texture fades in, the other fades out
Hey Everyone,
I am trying to making a shader that contains 2 textures and colors that support transparency. I want to use a coroutine to fade between the two textures as a transition effect. I looked over the documentation and the default shaders but I couldn't come up with anything substantial. I was wondering if you guys can help me complete my code and tell me what is wrong with it.
Shader "Custom/UnlitTransparent" {
Properties {
_Color ("Main Color", Color) = (1,0.5,0.5,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_OtherColor ("Other Color", Color) = (1,0.5,0.5,1)
_OtherTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
//ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Lighting Off
Material {
Diffuse [_Color]
}
SetTexture [_MainTex] { combine texture }
}
Pass
{
Lighting Off
Blend DstAlpha OneMinusSrcAlpha
Material {
Diffuse [_OtherColor]
}
SetTexture [_OtherTex] {
combine texture lerp (texture) previous
}
}
}
}
Answer by robertbu · Feb 03, 2013 at 03:36 PM
Here is a very simple example of what Owen Reynolds explained.
Shader "Custom/AlphaBlendTransition" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.0
_BaseTexture ("Base Texture", 2D) = "" {}
_OverlayTexture ("Texture 2 with alpha", 2D) = "" {}
}
SubShader {
Pass {
SetTexture[_BaseTexture]
SetTexture[_OverlayTexture] {
ConstantColor (0,0,0, [_Blend])
combine texture Lerp(constant) previous
}
}
}
}
This blends two textures.
Hey! this is sweet!
I'm a shader newb and was wondering.. is it possible to get this shader to not be self illu$$anonymous$$ated?
Thanks
@Gillespionage - These kinds of shaders typically use '_Blend' for the property, so you can search for "unity blend shader" or "unity shader blend diffuse". Here is one hit that might be what you are looking for:
http://answers.unity3d.com/questions/54837/how-to-make-a-diffuse-bump-blending.html
Awesome! That is what I was looking for! Thank you so much :D
Answer by Owen-Reynolds · Feb 02, 2013 at 10:54 PM
The goal is to have the script send the shader/Material its Lerp value going from 0 to 1. The thing is, this version of Lerp uses the alpha value of the 2nd input (the one in quotes.) Since you give it (texture) it's just doing a standard decal-blend.
So, you have to give it some fake input with the alpha set to the Lerp val you need. Can use (constant), which will use the MainColor you set. It still uses the alpha, but if you set color=new Color(1,1,1,myLerpVal) you can trick it into using your lerp val.
DISCLAIMER: I don't use shaderLab (I use surf shaders.)
Your answer
Follow this Question
Related Questions
Help with custom shader 0 Answers
layered texture with seperate alpha? 0 Answers
Opaque to Transparent animation effect on a textured object (Lerpz)? 1 Answer
Fading groups of objects to black 1 Answer
Opacity at Runtime - Fade Shader 0 Answers