PDA

View Full Version : How to get the normal of pixel?

ljz
03-27-2003, 05:53 PM
I wonder if the normal of each pixel should have been known before lighting in opengl. If so, how can I get it without lighting?

Ostsol
03-27-2003, 06:14 PM
Not sure what you mean. . . A context would help. You could find the normal via interpolation, though.

ljz
03-28-2003, 03:45 AM
I mean that I want to get the pixel normal of a model rendered by OpenGL, which is not modeled by myself but by other tools such as Unigraphics. The information I just know is the rendered scene of the model.

oliii
03-28-2003, 04:53 AM
Originally posted by ljz:
I mean that I want to get the pixel normal of a model rendered by OpenGL, which is not modeled by myself but by other tools such as Unigraphics. The information I just know is the rendered scene of the model.

you need the Zbuffer values for each pixels.

you need to convert each pixels into 3D first, by using the inverse of the projection matrix (is this right?), and using the pixel coordinates and its depth value.

then ....
Vector A = GetPixel3D(09, 10)
Vector B = GetPixel3D(11, 10)
Vector C = GetPixel3D(10, 09)
Vector D = GetPixel3D(10, 11)

Vector E = (B - A);
Vector F = (D - C);

Vector N = E x F;

No depth information (z buffer), no way to compute the normals.

oliii
03-28-2003, 04:57 AM
sorry, that's just dumb. it won't really work.

V-man
03-28-2003, 07:21 AM
pixels don't have normals in GL.

vertices have normals, and once lighting is applied in the TnL stage, they disappear.

Miguel_dup1
03-28-2003, 08:01 AM
Pixels dont have normals in general because they are points in space without a direction... Unless if you are assuming that a pixel is a vector of the form OP, where O is at the origin and P is the pixel (point in space).

Are you trying to ask how lighting affects the pixels on a surface..??

La Mancha

[This message has been edited by mancha (edited 03-28-2003).]

SirKnight
03-28-2003, 11:22 AM
If you want normals for each pixel then you need a normal map. This for each fragment encodes a normal in RGB format and is used for bump-mapping and stuff. To make these you need to either generate one from a texture map or run some kind of "render-bump" program that computes normals per pixel from a highres model. ATI has a program that does this on their site, and I have seen a few more around on the net too. I don't know if this is what you want or not.

For a crude and crappy approximation of a normal for each fragment on a model you can take the vertex normal and interpolate it across the polygons. Not my method of choice though. If I want normals for each pixel of my model I'll just take a high res and low res version of my model and run them through a "render-bump" program.

-SirKnight

ljz
03-31-2003, 06:03 PM
Hi,everyone,
I think that a pixel do not have normals when treated as a point and has when treated as a little plane, otherwise, how lighting works?
oliii's method can work. I'm now doing it so with some more pixels (9) involved. But sometimes it works with some errors.
As to getting normals from shaded surface mentioned by V-man, I am afraid it need lighting yet.
SirKnight, I'm interesting in what you'v talked. Would you please give me more direction? I'm going to find ATI examples on the net.
Thank you all, ljz.