Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

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

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    10

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

    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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    You can write it out to an extra bound texture buffer but you need to use shaders to do this

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    10

    Red face

    Quote Originally Posted by tonyo_au View Post
    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    Are you familiar with shaders and glsl?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    10
    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?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    10
    Now I'm clear. Thanks any way.
    BTW, is glsl a replacement of opengl?
    Last edited by li.j.z; 12-14-2013 at 09:57 PM.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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

  9. #9
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    10
    Thanks for the explanation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •