Jump to content
  • Advertisement
Sign in to follow this  
the dodger uk

hlsl normalize a float9 ?

This topic is 1975 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 have a  float  data[9];

 

i need to normalize this 

but i tryed to do  

 

data = normalize(data)

 

which it did not like  , because its an array , 

 

how would i  code this please 

Share this post


Link to post
Share on other sites
Advertisement

What sort of data does the float[9] represent? Is it a 3x3 matrix? or perhaps 3 Vector3's?

Share this post


Link to post
Share on other sites

If data[9] is simply a 9 dimensional vector you can do it manually:

 

float z = 0;

for(int i = 0; i < 9; i++)
    z += pow(data, 2);

z = sqrt(z);

for(int i = 0; i < 9; i++)
    data /= z; //Or use a temporary vector if "data" is in a constant buffer

 

 

If data[9] is a 3x3 matrix divide each value by the determinant.

 

Do you have to normalize it in the shaders? It would be faster do normalize it in the CPU and send to the shaders.

Edited by TiagoCosta

Share this post


Link to post
Share on other sites

It depends on how you define 'normalize'. With regards to length, like Tiago posted, so their Pythagorean length is 1? With regards to weighting so they sum to 1?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!