Render Normals...

Started by
1 comment, last by adoado 15 years, 6 months ago
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 ;)
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...
_____My little engine : I.E.
Thankyou! :D

It works perfectly ;)

Cheers!
Adrian ;)

This topic is closed to new replies.

Advertisement