Advertisement Jump to content
Sign in to follow this  

HLSL Vertex Shader - Whats wrong with this?

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

Hello all, I've just recently got a vertex shader in my program working and today I tried manipulating some things to get myself familiar with the whole programable stuff. I ran into a strange problem though and I'm not sure why it occurs. The shader compiles, but the program crashes (I'm at school at the moment and don't have the debug output available) and I'm not sure why. I was hoping someone could take a look and let me know what is wrong with what I'm doing.

float4x4 worldViewProj;
float4 vLight;

struct VS_OUTPUT
    float4 Pos  : POSITION;
    float4 Diff : COLOR0;
    float2 Tex1 : TEXCOORD0;
    float2 Tex2 : TEXCOORD1;
VS_OUTPUT vs_main(float4 inPos : POSITION, float3 inNormal : NORMAL, float2 Tex1 : TEXCOORD0, float2 Tex2 : TEXCOORD1 )
    VS_OUTPUT Out;
    Out.Pos = mul(inPos, worldViewProj);
    Out.Diff = float4(0, 0, 0, 0);     //the problem is with this line, 
    //Out.Diff = -dot( inNormal, vLight ); //this works, but the previous line doesn't

    Out.Diff.r = inPos.y/2;
    Out.Diff.g = inPos.y/4;
    Out.Diff.b = inPos.y/8;

    Out.Tex1 = Tex1;
    Out.Tex2 = Tex2;
    return Out;

The problem is with Out.Diff being initialized. If I try and set it to float4(0, 0, 0, 0), then the program crashes, but if I initially set it to -dot( inNormal, vLight ), then it works perfectly. Am I missing something here? Any help would be appreciated, thank you.

Share this post

Link to post
Share on other sites
that doesn't make much sense.

Diff is a float4, and you're saying when you set it to another float4 it doesn't work, whereas when u set it to a scalar it works? Because the output of the dot product is a scalar.


Output.Diff = float4(inPos.y/2, inPos.y/4, inPos.y/8, 1);

I really don't think it should crash though, although you might get nothing on the screen if alpha blending is enabled since you are setting your alpha component to 0.

Share this post

Link to post
Share on other sites
Try using float4(0,0,0,1) instead of float4(0,0,0,0)

Are you sure your program is crashing? Perhaps you are just not seeing any rendering? With Diff = float4(0,0,0,0) you are setting the alpha to 0 which may cause it to not render anything depending on your render state settings.

Share this post

Link to post
Share on other sites
Okay, I found the problem :)

It appears that once vLight wasn't being used in the shader, it was being removed from the constant table, even though it was being declared. So when I tried to set vLight, it didn't exist, and crashed.

Thanks for the help though guys :)

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!