Sign in to follow this  
adoado

Render Normals...

Recommended Posts

Hello all ^^ Firstly, I am still new to HLSL and this may seem completely obvious :P Basically I want to render the normals of the vertices into a texture - to create a 'normal render map' - similar to a depth map but with the normals encoded into the texture.. My question is, does anyone know how I can encode a normal into a texture and then reconstruct the normal vector later from the texture? Thanks in advance, Adrian ;)

Share this post


Link to post
Share on other sites
Hi,

A texture is an RGB pixel map... A vector is a tuple of 3 floats... Since a texture is composed of three (or four) floats inside HLSL, you can use the three colors to store the 3 vector component of your texture

pixel = (normal.x , normal.y, normal.z)

but there is one problem with domains... First, you'll have to normalize your normal vector (hence the name -- it's already normalized i assume)

But one problem remains, the normal components vary between -1 and 1, and a texture pixel have component between 0 and 1

You'll then just have to divide by two every component of your normal, making it vary between -0.5 and 0.5. You can then add 0.5 to every component to make it vary between 0 and 1

To do the inverse, just multiply by two, and subtract 1...

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