## Calculating Normals

leodeus
Unregistered

Post: #1
Sorry the basic question!!!!

How get the normal value in a x,y,z pixel of a polygon?

Leo
Sage
Posts: 1,403
Joined: 2005.07
Post: #2

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
leodeus
Unregistered

Post: #3
ok.. but they donÂ´t answer this:

Supose:
I have a cube with vertices, faces and normals.
Can i retrieve the normal value for any pixel(x,y,z)?... (supose: i want get the normal value for the pixel (not vertice or face) x=21,y=10,z=1, or other pixel)...

There is a command to get the normal value in certain pixel of a polygon?
Member
Posts: 153
Joined: 2004.12
Post: #4
Is this for a fragment shader?

There was a long silence...
'I claim them all,' said the Savage at last.
Moderator
Posts: 1,563
Joined: 2003.10
Post: #5
What on earth do you need that for?

It sounds to me like you'll want to unproject the pixel location from which you want to retrieve the normal, project that onto the face, and find the normal by interpolating appropriately between the normals of the face's vertices at that point. There's no way built into OpenGL to do it, unless I'm missing something.
leodeus
Unregistered

Post: #6
No...
it is for detecting a polygon face (in all pixels) (in a top and ortographic view) when the view frustum in less than a height of a polygon...

like this : http://labsim.estig.ipb.pt/test.jpg
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
Well for a face, the normal will be the same over the entire thing.
So you can use OpenGL picking to find out which face was clicked and then get the normal you have precalculated for that face.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
leodeus
Unregistered

Post: #8
ok... is that..
and now the initial basic question:

how can get the normal value in a some pixel of a face? using opengl... (i defined the normal by 3 points(x,y,z) (face)... and now i want retrieve this normal value pixel by pixel... (to know if some pixel belongs to a face or not)....

Thanks again.
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
I dont understand what you mean,
what is the input and expected output you want,
do you want to calculate the normal of the face that is at some pixel?

There is no OpenGL call that gives you a normal from a pixel, but there is one that can give you a face from a pixel.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
leodeus
Unregistered

Post: #10
If there is one that give me a face from a pixel better... How?

My input: pixel coordinates
The Output: norlmal value or face (if belongs a face)
Moderator
Posts: 1,563
Joined: 2003.10
Post: #11
There are a few different ways to do it. OpenGL provides a facility known as selection mode, which allows you to determine whether or not a particular primitive or set of primitives is drawn in a particular pixel location. You can read up on it in chapter 13 (if I'm remembering correctly) in the red book. You can do the math yourself as I suggested in my earlier post. They both have their pros and cons; learn about both and choose the one that works best for you.