Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A light problem.

23 views
Skip to first unread message

Jean-Christophe

unread,
Apr 7, 2013, 5:58:52 AM4/7/13
to
Hi all,

Using LIGHT on textured surfaces works well
on round shapes ( like sphere and cylinder )
but not on rectangles. Can you help here ?

// LIGHT
glLighti ( GL_LIGHT0, GL_SPOT_EXPONENT, 127 );
glLightfv( GL_LIGHT0, GL_POSITION, (GLfloat*)&lightPos );
glLightfv( GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat*)&z );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);

// RECTANGLE
const float b = 0.5f;
glBegin(GL_QUADS); // rect on XY plane
glNormal3i( 0,0,1 ); // normal towards +Z direction
glTexCoord2f( x , y ); glVertex3f( -b, -b, b );
glTexCoord2f( x+d, y ); glVertex3f( b, -b, b );
glTexCoord2f( x+d, y+e ); glVertex3f( b, b, b );
glTexCoord2f( x , y+e ); glVertex3f( -b, b, b );
glEnd();


Andy V

unread,
Apr 7, 2013, 9:02:44 PM4/7/13
to
On Sunday, April 7, 2013 5:58:52 AM UTC-4, Jean-Christophe wrote:
> Hi all,
>
>
>
> Using LIGHT on textured surfaces works well
>
> on round shapes ( like sphere and cylinder )
>
> but not on rectangles. Can you help here ?

What are you expecting that isn't happening?

Perhaps you are not aware that the old, fixed pipeline, OpenGL,
which you are using, only calculates lighting at the vertices
and interpolates?

Search for shaders (new OpenGL) that support phong lighting by
computing the lighting at each pixel.

Nobody

unread,
Apr 8, 2013, 2:16:04 PM4/8/13
to
On Sun, 07 Apr 2013 11:58:52 +0200, Jean-Christophe wrote:

> Using LIGHT on textured surfaces works well
> on round shapes ( like sphere and cylinder )
> but not on rectangles. Can you help here ?

Vertex lighting only works well if the polygons are small relative to the
distance to the light source.

For large polygons, you can subdivide them, use light maps, or use shaders
to implement Phong shading.

Jean-Christophe

unread,
Apr 8, 2013, 4:08:49 PM4/8/13
to
>> Jean-Christophe :
>> Using LIGHT on textured surfaces works well
>> on round shapes ( like sphere and cylinder )
>> but not on rectangles. Can you help here ?

> "Nobody" :
> Vertex lighting only works well if the polygons
> are small relative to the distance to the light source.
> For large polygons, you can subdivide them, use light
> maps, or use shaders to implement Phong shading.

Look, see this image:
http://cjoint.com/data/0Div4BUDMjl_0a.jpg

On the left image the light source is on the right:
the sphere reflects the light correctly
but the cube is dark(ish)

On the right image the light source is on the left:
the sphere still reflects the light correctly
but now the cube is bright.

Shouldn't it be the other way about the cube ?

The [ UR, UL, DR, DL ] face of the cube is
on the XY plane, I set its normal to (0,0,1)
I tried (0,0,-1) and any other
XYZ combination ... no luck !

Now I'm puzzled.

Andy V

unread,
Apr 8, 2013, 9:58:45 PM4/8/13
to
> On the left image the light source is on the right:
> the sphere reflects the light correctly
> but the cube is dark(ish)

It does look as though your cube normals are incorrect.

> The [ UR, UL, DR, DL ] face of the cube is
> on the XY plane, I set its normal to (0,0,1)
> I tried (0,0,-1) and any other
> XYZ combination ... no luck !

XY plane, meaning Z is 0.0 or Z is constant?

What sort of light do you have -- point or directional?
How is it set up?

Drawing the cube -- how many normals do you have?

Leclerc

unread,
Apr 9, 2013, 4:33:37 AM4/9/13
to
Hi,


you have at least one problem, your normal is not of unit length:
> glNormal3i( 0,0,1 ); // normal


take a close look at 2nd sentence of 1st paragraph of description:
http://www.talisman.org/opengl-1.1/Reference/glNormal.html

also it wouldn't hurt to become familiar with complete chapter about
lighting in "Red Book":
http://www.glprogramming.com/red/

cheers,
Gordan



Nobody

unread,
Apr 9, 2013, 8:01:52 AM4/9/13
to
On Mon, 08 Apr 2013 22:08:49 +0200, Jean-Christophe wrote:

> Look, see this image:
> http://cjoint.com/data/0Div4BUDMjl_0a.jpg
>
> On the left image the light source is on the right: the sphere reflects
> the light correctly but the cube is dark(ish)

It looks like the cube's normals are wrong.

> On the right image the light source is on the left: the sphere still
> reflects the light correctly but now the cube is bright.
>
> Shouldn't it be the other way about the cube ?
>
> The [ UR, UL, DR, DL ] face of the cube is on the XY plane, I set its
> normal to (0,0,1) I tried (0,0,-1) and any other
> XYZ combination ... no luck !

For a regular convex polyhedron (e.g. a cube), the normal for a face
should have the same direction as the result of the face's centroid minus
the object's centroid.

But there are a hundred other ways to mess up, apart from the normals.
Without seeing the code for a minimal example which demonstrates the
problem, it's pointless to guess.

Jean-Christophe

unread,
Apr 9, 2013, 1:24:35 PM4/9/13
to
Thank you "Andy V" and "Leclerc" and "Nobody".

I just realized that I used
glNormal3i( 0,0,1 );
instead of
glNormal3f( 0,0,1 );
so I changed them all and now it works.

Sorry, guys.
Stupid me.



"Nobody" :
0 new messages