Results 1 to 6 of 6

Thread: Wrong Normal calculation!

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Wrong Normal calculation!

    I try to render a polygon with lighting enable. So as expected, the result will be a shaded polygon. But if I render a polygon with calling glScaled(-1.0,1.0,1.0);, at this time, no more shaded effect and even you change the normal direction.

    Can anyone show me how to solve this problem. Thanks.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2005
    Location
    Stockholm, Sweden
    Posts
    164

    Re: Wrong Normal calculation!

    I believe that if you flip the x-axis, you should be able to flip the x-coordinate of your normal and get the same result as with an "unflipped" x-axis. However, I have not tried this myself. So, you should flip all the normal coordinates, just the x-coordinate.

  3. #3
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Wrong Normal calculation!

    When you have that scale on the modelview everything will be transformed through it correctly including the normals, HOWEVER, the light is positioned when you specify the position parameters. This means that the position will be scaled, only if positioned after you call glScale.

    There are many lighting situations where a surface will appear unlit because of the result of the lighting calculation.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Re: Wrong Normal calculation!

    Originally posted by dorbie:
    When you have that scale on the modelview everything will be transformed through it correctly including the normals, HOWEVER, the light is positioned when you specify the position parameters. This means that the position will be scaled, only if positioned after you call glScale.

    There are many lighting situations where a surface will appear unlit because of the result of the lighting calculation.
    Exactly as what you say, if I call the Gl.glLightfv(Gl.GL_LIGHT0,Gl.GL_POSITION,position) after the glScale only one side of the polygon will appear lit and the other side will be unlit althought I
    select the light model of 'GL_LIGHT_MODEL_TWO_SIDE'. Do you know how to get rid of this problem? Thanks.

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    23

    Re: Wrong Normal calculation!

    Are you using glEnable(GL_NORMALIZE) to ensure that normals are recomputed? It will cause bit performance hit but ensures that normals will be recalculated.
    As normal needs to be multiplied with inverse transpose of the transform being applied to point (here scaling).

  6. #6
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Wrong Normal calculation!

    This is correct lighting, you need to add more light sources if you want both sides lit.

    Two sided lighting automatically flips the surface-normal for all back faces as per the OpenGL specification. Only a normal facing the light source can be lit by the directional direct illumination in OpenGL.

    You can do your own lighting by reversing face culling and keeping the same normals is you desire a different result. It will have less potential for hardware acceleration but two sided lighting with native acceleration that isn't some slower multipass is a high end feature these days, so you may not be any slower afterall.

Similar Threads

  1. Why my FPS calculation is wrong?
    By babaliaris in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-14-2018, 06:50 PM
  2. Triangle Normal Calculation
    By DerTherion in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-01-2009, 02:09 AM
  3. normal-calculation
    By kinslayer in forum OpenGL: General
    Replies: 6
    Last Post: 02-25-2004, 01:45 AM
  4. Normal Calculation
    By seamuslawless in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 02-28-2003, 11:32 PM
  5. Normal Calculation
    By seamuslawless in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-27-2003, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean