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 5 of 5

Thread: How to get shading with out supplying normals using glDrawElements.

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    3

    How to get shading with out supplying normals using glDrawElements.

    I am drawing a mesh using glDrawElements.
    Recently I heard that, using GL Shading language(GLSL) ,
    shading is possible with out supplying normals.
    Is it possible. !!!????
    Please help me on this.
    If possible, please provide some examplary code.
    Thanks in advance.

  2. #2
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    51
    Normals are always needed in fragment shader, but you can compute them directly in GLSL (additional work done by shaders, for every vertex).
    Search on Google how to compute them in the best way in which fits your case.

  3. #3
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    This strongly depends on the data you are planning to use.

    If you have a heightmap, the computation is easy: The shader must simply take additional heights next to the point the normal will be calculated for. Then, a cross-product gives a good approximation of how the actual normal should look like. The more points are taken into account for this calculation, the more accurate the normal is.

    However, for arbitrary geometry this may not be possible. As far as I know, the fragment shader cannot know all points of the drawn polygon; only one point can be known (by using the "flat" keyword which leaves the coordinate un-interpolated).

    But why not calculate the normals out of the shader once for all faces, and then simply pass them on to the shader to read and draw?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,183
    One way is to use a geometry shader; input triangles with adjacency, output a single triangle, and calculate the normal from the vertex data. Adjacency on input is only necessary if you want to average normals for adjacent faces.

    Of course that's going to be slower than just calculating normals in your asset creation pipeline and including them in the models you load and draw. But it can certainly be done.

  5. #5
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    3
    Thanks tdname, I will use GLSL.

    Thanks all of you to help me on this.

Posting Permissions

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