I've written a vertex/fragment shader for my game. It uses 3 textures and represents a floating water on the wall (so I have 1 texture for water, 1 for geometry and the last one is mask) so it looks like this:
But I also need a spot light attached to the camera to lit my geometry, and this is the single dynamic light source on the stage.
Well, I can use a surface shader to take dynamic lighting into attention, but I want to avoid using them because: it will be much larger and its execution will be much slower. Besides, I need only one dynamic light source, so I can (can I?) just calculate its lighting in the shader, and pass a position/direction to the shader using material.SetVector(). It is something like:
float4 frag(FragmentInput i) : COLOR0
{
float4 col = i.col * tex2D(_Texture, i.uv);
col.a = tex2D(_AlphaMask, i.uv).r / 2;
if(col.a > 0.25f) // it's water, just return the scrolled texture color
{
float4 l1 = tex2D(_WaterTexture, float2(i.uv.x, i.uv.y - _Time.y / 16));
float4 l2 = tex2D(_WaterTexture, float2(i.uv.x, i.uv.y - _Time.y / 8));
return float4((l1 * l2).rgb, 0.5f);
}
else // it's geometry calculate spot light lighting
{
float lit = // ... calculations here ...
return col * lit;
}
}
Is it possible to do this? Will it work faster than the surface shader?