Newbie HLSL programmer here. I'm trying to create a very basic shader for directional light and i'm experiencing really bizarre behaviour trying to debug the shader code. I dont know if its my lack of understanding of how this all works or if something is really wrong.
This is the vertex shader
struct ShaderOutput
{
float4 Position : SV_POSITION;
float4 Normal: NORMAL;
float2 TexCoord: TEXCOORD;
float4 Colour: COLOR;
};
struct ShaderInput
{
float4 Position : POSITION;
float4 Normal: NORMAL;
float2 TexCoord: TEXCOORD;
};
ShaderOutput VShader(ShaderInput Input)
{
float NdotL;
ShaderOutput Output;
NdotL = max(0.0f, dot(Input.Normal, LightPosition));
Output.Colour = NdotL * LightColour;
Output.Position = mul(Input.Position, WorldMatrix);
Output.Position = mul(Output.Position, ViewMatrix);
Output.Position = mul(Output.Position, ProjectionMatrix);
Output.Normal = Input.Normal;
Output.TexCoord = Input.TexCoord;
return Output;
}
First issue, when I try to debug the shader code, the debugger starts on this line:
Output.Position = mul(Input.Position, WorldMatrix);
instead of this line:
NdotL = max(0.0f, dot(Input.Normal, LightPosition));
Which confused me, it only executes that first line after the vertex shader returns. Could someone explain why? Could this be the effect of parallel processing?
Second issue, following on from that, once this line is executed:
Output.Colour = NdotL * LightColour;
Output.Colour is blank (all values are NAN)
Third issue, these lines:
Output.Normal = Input.Normal;
Output.TexCoord = Input.TexCoord;
dont seem to be executed, it skips right over them and jumps to the function return, I dont know why. setting the position values seems to work fine though.
Any ideas?