Jump to content
  • Advertisement
Sign in to follow this  
CadeF

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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!