Jump to content
  • Advertisement
Sign in to follow this  
mishal153

HLSL behaviour when float4 declared inside main function and outside

This topic is 3080 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

Hi, I am seeing a weird issue. I have this shader:

// Vertex shader input structure
struct VS_INPUT
{
    float4 Position   : POSITION;
    float2 Texture    : TEXCOORD0;
    float4 DiffuseColor : COLOR0;
    float3 Normal       : NORMAL;
};


// Vertex shader output structure
struct VS_OUTPUT
{
    float4 Position   : POSITION;
    float2 Texture    : TEXCOORD0;
    float4 DiffuseColor : COLOR0;
};


// Global variables
float4x4 WorldViewProj;

float4 LightColor = {1.0f, 0.0f, 0.0f, 1.0f};

VS_OUTPUT vs_main( in VS_INPUT In )
{
    VS_OUTPUT Out;                      //create an output vertex
    float4 colorContibutedbyLight = float4(0.0f, 1.0f, 0.0f, 0.0f);
    
    colorContibutedbyLight = LightColor * 0.5f;
    
    Out.Position = mul(In.Position,
                       WorldViewProj);  //apply vertex transformation
    Out.Texture  = In.Texture;          //copy original texcoords
    Out.DiffuseColor = colorContibutedbyLight;

    return Out;                         //return output vertex
}

Notice that here LightColor is declared just outside vs_main. If i use this shader i always get black diffuse color. It seems that LightColor is not getting initialized properly. But if I just move the line "float4 LightColor = {1.0f, 0.0f, 0.0f, 1.0f};" inside vs_main, then all works as expected. Is this some HLSL thing I dont know ? or is this a driver bug ?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!