# HLSL Vertex Shader - Whats wrong with this?

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

## 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 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.

Try:

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 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 on other sites
wasn't that kinda redundant? :P just a thought.

##### Share on other sites
yes, the program actually crashes, null pointer error. I just got home now, so i'll load the debugger up and find out whats going on.

##### 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 :)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633300
• Total Posts
3011267
• ### Who's Online (See full list)

There are no registered users currently online

×