PDA

View Full Version : wrong shading



07-14-2003, 04:23 AM
I have a modell which consists of around 400 triangles. I defined one light but all triangles have the same shading/color.

I want that triangles upside up are different (lighter) from triangles upside down(darker).

thanks for hints ToP

Robbo
07-14-2003, 05:07 AM
Check the winding of your polygons - that is, the winding will make a difference to normal generation. And if you aren't specifying normals, you need to enable opengl autonormal generation.

07-14-2003, 05:38 AM
I am quite sure that the normals are set correctly. Guess, I need to discribe my problem better: All triangles, even those with a totally different orientation in space, have the same color shading. That means, texture/relief cannot be seen. I want my objects having shaded colors so that you have the impression of a 3D space. To say, each triangle gets his own shading depending on its position to the light.

Mazy
07-14-2003, 05:43 AM
And you have enabled one light and lighting?

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

if you set that and still doenst get another shading i bet its the normals.

Deiussum
07-14-2003, 10:30 AM
You say you are "quite sure the normals are set correctly", but the problem you describe kind of sounds like all the normals are the same.

Just to be sure, you are doing something like this, right?




glBegin(GL_TRIANGLES);
foreach(triangle in triangleList)
{
glNormal3fv(triangle.normal);
glVertex3fv(triangle.vertex);
}
glEnd();

Ryo
07-14-2003, 11:22 PM
If light settings and normals are all correct, you may try this.

glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0f);

MichaelK
07-14-2003, 11:45 PM
Originally posted by Robbo:

Check the winding of your polygons - that is, the winding will make a difference to normal generation. And if you aren't specifying normals, you need to enable opengl autonormal generation.

Wow. Interesting OpenGL feature. Can You tell me the name of this fantastic extension, which generates normals for me?

Michalek

Mazy
07-15-2003, 12:58 AM
Since it doesnt exists for triangles, i bet you never get any name for it http://www.opengl.org/discussion_boards/ubb/smile.gif

the autonormals are only for high order surface generation.

07-15-2003, 04:18 AM
I donot create normals, they ar defines itself through 3 points?

glBegin(GL_TRIANGLES);
for (i = 1; i < triangles; i++)
{
glVertex3f(P1.x, P1.y,P1.z);
glVertex3f(P2.x, P2.y,P2.z);
glVertex3f(P3.x, P3.y,P3.z);
}
glEnd();

my lightsettings are this:

GLfloat ambient[] = {1.0, 1.0, 1.0, 1.0};
GLfloat position[] = {-500.0, 500.0, 900.0, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 0.5, 1.0};
GLfloat mat_shininess[] = {10.0};

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, position);

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

Maybe that this is a problem with material or lightposition?

Mazy
07-15-2003, 04:20 AM
You must define your own normals, opengl will not create them. You get the same lighting on all faces becourse of that.. Opengl only calculates the light with the normals, and since you dont give some new to it, the last sent normal ( or default (0,0,1) ) are set for all your vertices.

then its also good to set all material and light values, even if some are default..


[This message has been edited by Mazy (edited 07-15-2003).]