PDA

View Full Version : How to get the normal vector of a pixel which is used for lighting in OnenGL?



li.j.z
12-12-2013, 08:08 PM
We know that the normal vector of a pixel is used for lighting in openGL and the normal vector of each pixel of the displayed model is known to openGL before lighting rendering, so is there any way we could get the normal vector after the model is rendered?

tonyo_au
12-13-2013, 01:07 AM
You can write it out to an extra bound texture buffer but you need to use shaders to do this

li.j.z
12-13-2013, 07:02 PM
You can write it out to an extra bound texture buffer but you need to use shaders to do this

Thanks. You mean we can get the normal vector of each pixel before the model is rendered and could you please tell me more info on how to do this. Thanks again.

tonyo_au
12-13-2013, 10:41 PM
Are you familiar with shaders and glsl?

li.j.z
12-14-2013, 12:49 AM
Sorry, I am not. But I googled glsl, it seems a higher level APIs than opengl.
What I am doing at the moment is using opengl rendering to do some simulation. I first draw and render a model with basic opengl functions, and then try to get the pixel information including z-buffer and normal vector for further simulation. Now z-buffer is easy to get with glReadPixel(), but as to the normal vector, hope you could kindly help. I think basic opengl APIs instead of glsl are profered. Do you agree with me that opengl knows the normal vector of each pixel for light indensity computing? If so, where does opengl store the data and how to extract?

tonyo_au
12-14-2013, 04:07 AM
The gpu can calculate the normal for each fragment ( pixel ) but you cannot get access to it without using shaders. The gpu does not need to store this information as it uses it immediately that it calculates it and has no need for it again so it does not store it. If you want to keep it you have to write it out yourself - hence the need to replace the default shader with your own. The shader language glsl is quite a large topic so you will need to do familiar with it before you can do what you want to do.

li.j.z
12-14-2013, 08:44 PM
Now I'm clear. Thanks any way.
BTW, is glsl a replacement of opengl?

tonyo_au
12-14-2013, 10:33 PM
BTW, is glsl a replacement of opengl?
No, you might call it an extension. OpenGL was designed when the graphics card was only silicon and you could set switches to control the path though the hardwired logic but you could not change the basic hardware. Now it is a computer in is own right (or actually many computers) so you can write programs for it. The programming language for the graphics card that has been developed to work with OpenGL is glsl. Directx has a similar programming language call hlsl. Many mobile phones and tablets support a subset of this programming language and OpenGL called OpenGL ES

li.j.z
12-15-2013, 07:58 AM
Thanks for the explanation.