- Home /
Diffuse Lighting into my Fixed Function shader?
Hi am a little stuck, I am trying to get the diffuse lighting to work with my fixed function shader, I think its my lerp that is removing the lighting?
I am trying to create a color mask shader that will use the main textures alpha to mask out any color tint, but it also seems to be removing the lighting from the same area.
Any help please?
Shader "Specular Colour Mask"
{
Properties
{
_Color ("Color", Color) = (1,1,1)
_SpecColor ("Specular Color", Color) = (1,1,1)
_Shininess ("Shininess", Range(0.01, 1)) = 0.5
_MainTex ("Main Texture", 2D) = "white"
}
SubShader
{
Lighting On
SeparateSpecular On
Pass
{
Material
{
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
//Emission [_Emission]
}
SetTexture [_MainTex]
{
ConstantColor [_Color]
combine texture * primary Double
}
SetTexture [_MainTex]
{
combine previous lerp(texture) texture
}
}
}
}
Answer by Earlybird · Jun 25, 2014 at 11:51 PM
Solved, the problem was that by using the lerp i was alphaing out my lighting from the effected area, the solution was to re-apply the diffuse lighting again afterwards.
the first set texture pulls in the texture and combines it with my color tint the second set texture uses the textures alpha to mask out the desired area using the lerp function and the third set texture (which was where i was going wrong) finally re-applies the diffuse lighting back into the material. oh I left the 3rd set texture blank "[_]" so as to not reapply the texture again which is something i didn't realise you could do before.
hope that makes sense?
Shader "Custom/FixedFunction/ColorMask Specular"
{
Properties
{
_Color ("Color", Color) = (1,1,1)
_SpecColor ("Specular Color", Color) = (1,1,1)
_Shininess ("Shininess", Range(0.01, 1)) = 0.5
_MainTex ("Main Texture", 2D) = "white"
}
SubShader
{
Lighting On
SeparateSpecular On
Pass
{
Material
{
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
Shininess [_Shininess]
Specular [_SpecColor]
}
SetTexture [_MainTex]
{
constantcolor [_Color]
combine texture * constant
}
SetTexture [_MainTex]
{
combine texture lerp(texture) previous
}
SetTexture [_]
{
combine previous * primary
}
}
}
}