I would like to be able to pass texture variables to a custom lighting function.
I would like to set an intensity value in the surf function. This is so that a texture can be used to set it.
If this isnt possible or the best way of doing this, is there anyway to use textures in the lighting function.
fixed4 LightingIncreaseIntensity(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed diff = max (0, dot (s.Normal, lightDir));
fixed4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2)*_Intensity;
//=============================What I would like to do ==============
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2)*s.Intensity
//Where s.Intensity is calculated in the surf function.
//=============================================================
c.a = s.Alpha;
return c;
}
Your best bet would be to create a CG shader and do the lighting calculations in a fragment program.
Or alternatively you could set your intensity to “SurfaceOutput.Gloss” and then your shader becomes:
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2) * s.Gloss;
You need to create a new struct for it to use then it’s just a matter of telling your shader to use that instead…
This is Unity’s default struct
struct SurfaceOutput {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
};
So you’d add your own to your shader and tell it to use that instead;
struct SurfaceOutputCustom {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
fixed Intensity;
};
void surf (Input IN, inout SurfaceOutputCustom o)
{
...
}
fixed4 LightingIncreaseIntensity(SurfaceOutputCustom s, fixed3 lightDir, fixed atten)
{
...
}
Bear in mind that (in Unity 3 at least, not sure about 4?) Unity requires that there’s slots there for some components - I think it needs to have Albedo, Alpha, Normal, Specular and Emission.