I'm trying to do lighting calculations for an array of point lights in HLSL. I simply want to pass light direction vectors from the vertex shader to the pixel shader. Here is sample code:
static const int MAXLIGHTS = 8;
float4 g_vLightPosition[MAXLIGHTS];
float4x4 mW : WorldTransform; // model to world
float4x4 mV : ViewTransform; // world to view
float4x4 mP : ProjectionTransform; // view to project
void VS_Lighting( in float4 PositionMS : POSITION0,
out float4 PositionCS : POSITION0,
out float4 Texcoord[MAXLIGHTS] : TEXCOORD )
{
// view-projection
float4x4 mVP = mul(mV, mP);
// world position
float4 vPosWS = mul(PositionMS, mW);
// clip space pos
PositionCS = mul(vPosWS, mVP);
// compute light direction vectors
for(int i = 0; i < g_nLightCount && i < MAXLIGHTS; ++i)
{
Texcoord[i].xyz = g_vLightPosition[i] - vPosWS;
}
}
The above code forces the loop to unroll and gives the following warning:
warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll
I would like for this code to be dynamic so as to reduce the instruction count. I understand that the problem is accessing the array in the loop. How can I rewrite this code to prevent unrolling during compilation? I am using ps 2.0 or 3.0.