Skip to main content
gamedev.net
🔒 Locked

Messed up lighting

Started by crshinjin Mar 1, 2007 at 9:41 AM 4 replies 700+ views
Original Post
crshinjin
crshinjin
Hi! I'm writing a sort of cloth simulation program, but I have run into some problems while trying to "turn the lights on". It's okay, as long as the surface is flat, as you can see below: Free Image Hosting at www.ImageShack.us But when the cloth starts to fall, sharp edges appear in the shading: Free Image Hosting at www.ImageShack.us The little grey lines are the vertex normals. I'm drawing the cloth using GL_TRIANGLES, but using the same normal for a single vertex every time, so I don't get it how is it possible to get different lit colour when a vertex used in different triangle, as it apparently happens. Any ideas would be appreciated. shinjin
jouley
jouley
Are you defining your normals on a per-vertex of per-triangle basis? The pertinent code would help, too.

Also, just to make sure I see it right, is the lower right corner the one falling in the second shot?

Egészségedre!
-jouley
crshinjin
crshinjin
You are right, the lower right corner is falling.

At each timestep I recalculate the face normals and accumulate them for each vertex in each face. Then I normalize the normals, and finally output the normals along with the vertices.

	glBegin(GL_TRIANGLES);		vector<face>::iterator it, endit = faces.end();		vector<vector3>::iterator nit, nendit = normals.end();		for (nit = normals.begin(); nit!=nendit; ++nit)			*nit = vector3::ZERO;		for (it = faces.begin(); it!=endit; ++it)		{			vector3 n = it->calcNUNormal(); // calculate non-unit normal of the triangle			normals[it->a_idx] += n;			normals[it->b_idx] += n;			normals[it->c_idx] += n;		}		for (nit = normals.begin(); nit!=nendit; ++nit)			nit->normalise();		for (it = faces.begin(); it!=endit; ++it)		{			glNormal3fv(normals[it->a_idx].val);			glVertex3fv(it->a->val);			glNormal3fv(normals[it->b_idx].val);			glVertex3fv(it->b->val);			glNormal3fv(normals[it->b_idx].val);			glVertex3fv(it->c->val);		}	glEnd();


Köszi, :D
shinjin
jouley
jouley
Sorry it's taken so long to get back to you, I got slammed with a bunch of work to get done. I haven't looked into it with much detail, but if you haven't solved this one yet, you may look into this region, particularly the normal you assign for the last vertex:
for (it = faces.begin(); it!=endit; ++it){	glNormal3fv(normals[it->a_idx].val);	glVertex3fv(it->a->val);	glNormal3fv(normals[it->b_idx].val);	glVertex3fv(it->b->val);	glNormal3fv(normals[it->b_idx].val);	glVertex3fv(it->c->val);}
I imagine it worked when the cloth was flat because all the normals were the same, then.

-jouley
knowyourrole
knowyourrole
Have you tried this:
glShadeModel(GL_SMOOTH);

It's a longshot, but if your normals are ok, which they appear to be, maybe you're using flat shading instead.
crshinjin
crshinjin
Aaah! Darned copy-paste!

Thanks Jouley! I've been stuck with this project for ages because of this.

shinjin

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.