View Full Version : Generating normal field from a specific viewpoint

02-23-2008, 11:57 PM
My apologies for my awkward usage of terms, as I am a complete newbie.

Let's say I have a model with all normals calculated, and a canvas (window) that renders it from a specific viewpoint.
I'd like to create a matrix, the same size of the canvas, in which each cell contains the normal of the object in the corresponding canvas position. In other words, I want to know, for each pixel that is rendered, what is the corresponding normal of the object.

For example, if I have a plane, whose normal(s) are all (0,0,1), and it is rendered parallel to the canvas, then my matrix would contain (0,0,1) for each cell that corresponds to a point on the canvas that shows the plane, and null for empty (black) points in the canvas.

Of course, I intend to use this on more complex objects, possibly concave ones.

Thanks in advance,

02-24-2008, 03:06 AM
I suggest you use shaders and just write the normal to the output, than you can readback the pixels and will have the normals.

02-24-2008, 04:48 AM
You'll probably want to write the output to a framebuffer object (http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt) with a floating point texture or renderbuffer attached.