Sign in to follow this  
the dodger uk

hlsl normalize a float9 ?

Recommended Posts

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[i], 2);

z = sqrt(z);

for(int i = 0; i < 9; i++)
    data[i] /= 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this