Jump to content
  • Advertisement
Sign in to follow this  
carew

OpenGL Compute Normal.z from Normal.x and Normal.y

This topic is 3706 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

Hi, I have problem with Normal in Deferred Shading. Because in OpenGL FBO MRTs I can't use different internal format, I can't use RGBA16F for Normal, bacause I will must use RGBA16F for all textures, so FPS will be go down. I have to use RGBA8 for all textures, so I have to pack Normal.x and Normal.y for it and compute Normal.z in shader. I try: Normal.z = sqrt(1 - Normal.x*Normal.x - Normal.y*Normal.y); // Normal in object space, but in View space etc. also not work properly How can I compute this Normal.z value? I currently don't test it with normal map from texture, I get Normals from standard calculation it in application.

Share this post


Link to post
Share on other sites
Advertisement
Notice that mathematically a square root results in a positive and a negative value, since a square supresses the sign of a number. So the result you are looking for is either
Normal.z = +sqrt(1 - Normal.x*Normal.x - Normal.y*Normal.y);
or else
Normal.z = -sqrt(1 - Normal.x*Normal.x - Normal.y*Normal.y);
You have to encode this case distinction, too, if you can't predict the sign otherwise.

Next, you have to consider that normals are of unit length, so that all of its components show an absolute value less than or equal to 1. Encoding this into an integer needs an up-scaling to take advantage of the full range, not to say to avoid to suffer from the value being clipped to 0. Later, in the shader program, the up-scaling has to be undone before or just after squaring the values.

Share this post


Link to post
Share on other sites
Thanks for answer, I solved my problem:)

[Edited by - carew on June 22, 2008 5:51:17 PM]

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!