PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(input.Pos,worldMatrix);
output.Pos = mul( output.Pos, ViewMatrix );
output.Pos = mul( output.Pos, projMatrix );
output.normal=mul(input.Normal,worldMatrix);
output.normal=normalize(mul(output.normal,ViewMatrix));
output.normal=normalize(mul(output.normal,projMatrix));
return output;
}
float4 PS( PS_INPUT In) : SV_Target
{
float4 colLight = float4(1, 1, 1, 1);
float4 MaterialColor = float4(0, 1, 0, 1);
float3 lightDirection = float3(0,0,-21);
float3 L = normalize(lightDirection.xyz);
float4 D = saturate( dot(In.normal,L) * colLight * MaterialColor);
return D;
}
shader and matrix transform
hy, i have this PART OF shader:
i disabled the cull mode but some faces appear black , i think is a normal problem , is correct to multiply the normal in the VS for the word , view and projection matrix?
Thanks.
Quote:Original post by giugio
hy, i have this PART OF shader:
*** Source Snippet Removed ***
i disabled the cull mode but some faces appear black , i think is a normal problem , is correct to multiply the normal in the VS for the word , view and projection matrix?
Thanks.
You shouldn't be transforming a normal at all, it's just a directional vector.
Quote:Original post by deadstar
You shouldn't be transforming a normal at all, it's just a directional vector.
That is not true, your normal needs to be transformed by the rotational portion of the transformation matrix. There are many threads on gamedev and else where discussing how to do this.
Quote:Original post by DieterVWQuote:Original post by deadstar
You shouldn't be transforming a normal at all, it's just a directional vector.
That is not true, your normal needs to be transformed by the rotational portion of the transformation matrix. There are many threads on gamedev and else where discussing how to do this.
Ah of course, my mistake.
Don't listen to me giugio, it's been a long day ;)
output.normal=mul(input.Normal,(float3x3)worldMatrix); <- if you use float3x3 this uses just the rotation part of the matrix, this is what you need
This is all you need. Dont multiply your normal by the view-proj matrix at all, only the world transform is needed. And in case your input normal isnt normalized, normalize it.
This is all you need. Dont multiply your normal by the view-proj matrix at all, only the world transform is needed. And in case your input normal isnt normalized, normalize it.
Quote:Original post by n3Xus
output.normal=mul(input.Normal,(float3x3)worldMatrix); <- if you use float3x3 this uses just the rotation part of the matrix, this is what you need
This is all you need. Dont multiply your normal by the view-proj matrix at all, only the world transform is needed. And in case your input normal isnt normalized, normalize it.
This only works if your transformation matrix contains no scaling.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement