My improved dynamic lighting shader would be
perfect if it wasn't for this problem I've run into. Basically, the vertex shader precalculates light direction factors for each of 8 possible dynamic lights and passes that data to the pixel shader to perform the actual attenuation so as to make a nice round light instead of one that clings to the model vertices. The effect looks absolutely beautiful... except for one problem.
Passing the light data requires transmitting 8 float values between vertex and pixel shader. As there is no such data type as a float8, I had to divide it up into two float4s, inLight1 and inLight2. The problem is, they don't overflow. Trying to access inLight1(4) does not give me the value of inLight2(0). I can "solve" the problem with an IF statement and a temp variable, but this puts me over the arithmetic limit and apparently mandates shader model 3.0 (???) which provides a prohibitive performance penalty.
For what it's worth, here's my pixel shader. Is there a more efficient way to access an array of 8?
float4 mainPS (
in float2 inCoord:TEXCOORD0,
in float3 inPos:TEXCOORD1,
in float3 inNormal:TEXCOORD2,
in float4 inLight1:TEXCOORD3,
in float4 inLight2:TEXCOORD4
) : COLOR
{
float4 light = 0;
for (int i = 0; i<iLights; ++i)
{
float angle;
if(i > 3)
{
int j = i - 4;
angle = inLight2[j];
}
else
{
angle = inLight1[i];
}
light += saturate(angle * saturate(dot(inNormal, normalize(vecLightPos[i].xyz - inPos)))) * vecLightColor[i];
}
return tex2D(basemap,inCoord) * light;
}