• Advertisement
Sign in to follow this  

normalize() producing different results

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've come across something weird in HLSL. Well, maybe it's not that weird, but it was unexpected for me. There's probably a simple explanation. Anyway...

 

when I do this in my normal mapping shader:

 

float3 normal = normalize(2.0f*tex2D(TextureSamplerN, PSIn.TexCoords) - 1.0f);

 

...I get a different result to if I do this:

 

float3 normal = 2.0f*tex2D(TextureSamplerN, PSIn.TexCoords) - 1.0f;
normal = normalize(normal);

 

It seems like the latter one produces the correct result when I run my program, but I have no idea why they're different. Any ideas?

 

Thanks!
 

Share this post


Link to post
Share on other sites
Advertisement

Is it ever meaningful to normalize a float4 anyway? Apart from the perspective division I can't think of a situation where you'd want to do that rather than normalize the underlying float3.

Share this post


Link to post
Share on other sites

Is it ever meaningful to normalize a float4 anyway? Apart from the perspective division I can't think of a situation where you'd want to do that rather than normalize the underlying float3.

For normalizing a vector (or turning a position into a vector), you'd use a float3, for normalizing a quaternion you'd use a float4.

 

Often in graphics you want to normalize a bunch of weights -- if you've got 4 and your weighting system is based on Euclidean distance, you might find normalizing a float4 handy too biggrin.png

Though usually normalizing weights looks more like weights /= dot(weights, (float4)1)...

Share this post


Link to post
Share on other sites


For normalizing a vector (or turning a position into a vector), you'd use a float3, for normalizing a quaternion you'd use a float4.
 
Often in graphics you want to normalize a bunch of weights -- if you've got 4 and your weighting system is based on Euclidean distance, you might find normalizing a float4 handy too 
Though usually normalizing weights looks more like weights /= dot(weights, (float4)1)...

 

I hadn't thought of quaternions, good point!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement