# HLSL question - "For" loop not working properly...

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This code does not work:
void MapVS( in a2v IN, out v2p OUT)
{
OUT.position = mul(IN.position, worldViewProj);
OUT.texCoord = IN.texCoord;
OUT.color.rgb = 0.0f;

float LI;
float3 LV;
float3 LNormal;

for(int i=0; i<3; i++ )
{
LV = 1/(0.95*distance(worldLight.xyz, IN.position.xyz));
OUT.color.rgb += LV;
}

OUT.color.a = 1.0f;
}

It returns out's .rgb as 1.0f for all vertices if code has i<3 If I use for(int i=0; i<1; i++ ), it works correctly, but only takes the first light position into account. But, this code works
void MapVS( in a2v IN, out v2p OUT)
{
OUT.position = mul(IN.position, worldViewProj);
OUT.texCoord = IN.texCoord;
OUT.color.rgb = 0.0f;

float LI;
float3 LV;
float3 LNormal;

LV = 1/(0.95*distance(worldLight[0].xyz, IN.position.xyz));
OUT.color.rgb += LV;
LV = 1/(0.95*distance(worldLight[1].xyz, IN.position.xyz));
OUT.color.rgb += LV;
LV = 1/(0.95*distance(worldLight[2].xyz, IN.position.xyz));
OUT.color.rgb += LV;

OUT.color.a = 1.0f;
}

It returns out's .rgb correctly based on how far it is from the 3 lights. Does anyone know what I am doing wrong? Vertex shader version is VS_2_0

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633711
• Total Posts
3013488
×