• Advertisement
Sign in to follow this  

Render Normals...

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement