Search for normal OpenGL

I would like to know if we can get the normal on the surface of an object from window coordinates. The gluUnProject () function converts the coordinates of a window into the coordinates of an object in three-dimensional space. Similarly, I need a function that gives the normal surface on which the mouse pointer rests. I would be more than happy if we had an opengl functio that could give this. I would not want to do this with the intersection of the ray and objects (surface triangles).

+3
source share
4 answers

I do not think that's possible. Why does opengl keep all normals for all pixels? He does not need this, so it is unlikely that you can get it. I'm afraid it will not be so simple.

, , rgb, . , . , , .

+2

: gluUnProject OpenGL. , . gluUnProject ( glReadPixels). , (, 3x3) unproject , 9 , . ( 2x2), , .

, , :

1 8 7
2 0 6
3 4 5

, , , (0,1,2), (0,2,3),... (0,7,8), (0,8,1) (, ) . , . , ( , . OpenGL ... , , ).

+1

, . OpenGL Super Bible Macintosh Windows . math3d. * , m3dFindNormal.

, .

0

, , .

1

, (x, y). X (x + 1/width, y) y (x, y + 1/height), - . gluUnProject , {A, B, C}. , :

A = ObjectCoordinates(x+1/width, y)
B = ObjectCoordinates(x, y)
C = ObjectCoordinates(x, y+1/height)
BA = (A-B)/|A-B|
BC = (C-B)/|C-B|
N = BA cross BC

| X | - X N

, , A, B C ( , , ). .

2

, , . . . , . , .

. (r, g, b) , (x, y, z). . . , , (u, v) , , .

, , , , .

Here is a slightly outdated but free book on GLSL in the Shading Language OpenGL that describes how you are going to build some of these shaders.

Here is a tutorial on loading and compiling shaders.

Here is the pseudo-code for calculating normal.

Cheers, ned

0
source

Source: https://habr.com/ru/post/1783856/


All Articles