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

## Recommended Posts

hy, i have this PART OF shader:
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;

}


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.

##### Share on other sites
Quote:
 Original post by giugiohy, 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.

##### Share on other sites
Quote:
 Original post by deadstarYou 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.

##### Share on other sites
Quote:
Original post by DieterVW
Quote:
 Original post by deadstarYou 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 ;)

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by n3Xusoutput.normal=mul(input.Normal,(float3x3)worldMatrix); <- if you use float3x3 this uses just the rotation part of the matrix, this is what you needThis 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.