Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualkauna

Posted 09 December 2012 - 10:05 AM

You may declare your normals as float3 from the beginning. Ie. for the input vertex structure.

Also, when using HLSL it is more or less pointless to write code such as :

float3 tmp_norm = float3(input.norm.x, ....) since you may as well write just float3 tmp_norm = input.norm.xyz.

Since your normal is still declared as float4, it will be rotated AND translated by the world matrix, which will give you wrong normals. It doesn't help to set the w-component to 0 in this case.

Here is the code which works for me: (i.vNormal is defined as float3 ):

float3 vNormal = mul(i.vNormal,(float3x3)mWorld);
vNormal = normalize(vNormal);

Cheers!

#3kauna

Posted 09 December 2012 - 10:05 AM

You may declare your normals as float3 from the beginning. Ie. for the input vertex structure.

Also, when using HLSL it is more or less pointless to write code such as :

float3 tmp_norm = float3(input.norm.x, ....) since you may as well write just float3 tmp_norm = input.norm.xyz.

Since your normal is still declared as float4, it will be rotated AND translated the world matrix, which will give you wrong normals. It doesn't help to set the w-component to 0 in this case.

Here is the code which works for me: (i.vNormal is defined as float3 ):

float3 vNormal = mul(i.vNormal,(float3x3)mWorld);
vNormal = normalize(vNormal);

Cheers!

#2kauna

Posted 09 December 2012 - 07:43 AM

Just to give you some hints :

You may declare your normals as float3 from the beginning. Ie. for the input vertex structure.

Also, when using HLSL it is more or less pointless to write code such as :

float3 tmp_norm = float3(input.norm.x, ....)

since you may as well write just

float3 tmp_norm = input.norm.xyz.

Since your normal is still declared as float4, it will be rotated AND translated the world matrix, which will give you wrong normals. It doesn't help to set the w-component to 0 in this case.

Here is the code which works for me: (i.vNormal is defined as float3 ):

float3 vNormal = mul(i.vNormal,(float3x3)mWorld);
vNormal = normalize(vNormal);

Cheers!

#1kauna

Posted 09 December 2012 - 07:41 AM

Just to give you some hints :

You may declare your normals as float3 from the beginning. Ie. for the input vertex structure.

Also, when using HLSL it is more or less pointless to write code such as :

float3 tmp_norm = float3(input.norm.x, ....)

since you may as well write just

float3 tmp_norm = input.norm.xyz.

Since your normal is still declared as float4, it will be rotated AND translated the world matrix, which will give you wrong normals. It doesn't help to set the w-component to 0 in this case.

Here is the code which works for me: (i.vNormal is a float3 structure)-

float3 vNormal = mul(i.vNormal,(float3x3)mWorld);
vNormal = normalize(vNormal);

Cheers!

PARTNERS