Sign in to follow this  
giugio

normalize of 0 crash

Recommended Posts

Hy. I'm still learn cg shader. My first problem is to avoid the normalization of 0,0,0,0 component that cause a NaN error in the shader. How i must involve when i do a normalization of a 0,0,0,0 vector component? Thanks.

Share this post


Link to post
Share on other sites
A normalization operation can also be expressed in the following form:
vector = vector/length(vector)

If you calculate the vector's length first you can check if it's close to or exactly zero. Divide only if not. Otherwise you might want to set it to some custom vector of length 1 (e.g. (1,0,0,0)). Depends on what you intend to do with the vector and how a vector of length 0 should be interpreted

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