Jump to content
  • Advertisement
Sign in to follow this  
bryguy512

GLSL : packing normals into 2 bytes

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

Hey, I have a deferred lighting question. My lighting looks kinda ugly. I know I need to pack my normal information into 2 channels of my RGBA texture to increase precision. I've scoured the internet for how to do this but have so far been unsuccessful. I've tried (packing): vec3 normal = normal_info; gl_FragData[1] = (normal.x, normal.x * 256.0 - floor(normal.x * 256.0), normal.y, normal.y * 256.0 - floor(normal.y * 256.0)); Unpacking: normal.x = normaltex.x + normaltex.y * 256.0; normal.y = normaltex.z + normaltex.a * 256.0; This doesn't work and it fact looks worse. What is the proper way to do this without bitwise operations?

Share this post


Link to post
Share on other sites
Advertisement
Thanks, Farto. Thats an awesome link but I guess my question is actually more general.

How do you put the first 2 bytes of any float, into two channels of a texture?

Share this post


Link to post
Share on other sites
I've linked a site that has shader code for (un)packing a float to a vec4. It can easily be modified to handle vec3 and vec2 packing as well.

http://www.ozone3d.net/blogs/lab/20080604/glsl-float-to-rgba8-encoder/

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!