Unity 5.5.3f1, Win10, DirectX11, GTX1060 Intel Core i-7, forward rendering
I’m testing the gpu cost of spot/point light, I thought in forward rendering, if the engine decides to apply a spot/point light on a single mesh, it applies the light on all vertex and pixels of that mesh. So I originally thought that if only a corner is shed by the light, all pixels of the whole mesh need to calculate that pass. But after I changed the standard pbs code to this:
half4 fragForwardAddInternal (VertexOutputForwardAdd i)
{
#ifdef POINT
return fixed4(0.1, 0, 0, 1);
#elif SPOT
return fixed4(0, 0.1 , 0, 1);
#endif
FRAGMENT_SETUP_FWDADD(s)
UnityLight light = AdditiveLight (IN_LIGHTDIR_FWDADD(i), LIGHT_ATTENUATION(i));
UnityIndirect noIndirect = ZeroIndirect ();
half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, light, noIndirect);
UNITY_APPLY_FOG_COLOR(i.fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass
return OutputForward (c, s.alpha);
}
it appears that spot/point light in forward rendering seems to have a pre-generated screen space mask to skip pixels not in the light area:
To be specific, the mask is always screen aligned rectangle, so I guess the light’s world space bound box is calculated to screen space uv bound rectangle, so then in pixel shading, pixels outside the rectangle is skipped. It seems work this way, but I can not find any relevant implementation in builtin shaders.
I’m planing the mesh combination and batching strategy to avoid too much GPU cost for lights, I can not find any documentation of this “mask”, anyone could share some insight about this? Thanks.
