lighting and normals

Moderator
Posts: 916
Joined: 2002.10
Post: #1
GACK! I've just written my entire program and there is no lighting. Now I want to enable lighting in it.
How would I go about doing this without completely redefining my models (in which no normals are defined)? I was hoping for a simple solution.
I have an orthographic view.
I need everything a little ambient and I want the models to be lit from the top down.
Quote this message in a reply
henryj
Unregistered
 
Post: #2
Generally speaking no normals means no lighting, or at least broken lighting. I presume you're using openGL, which is a state machine so you could make one call to glNormal and from that day forth all of your vertices will share the same normal. Might look ok, most probably wont.

Another approach might be to calculate your normals at load time. This isn't too hard to do.

Or you could use a normal map and do your lighting in a fragment shader. Then you'll get really nice lighting.

Best to just bite the bullet and stick em in your model file.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #3
I would look for some load-time normal calculating stuff on the Net. It'd probably be easier than remaking models.
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #4
I agree. It is not too complicated to calculate normals, you should be able to find the code/formula somewhere on the net. Do this once for all your models vertices at load time and then just remember to transform the normals with the models.

Also remember that for smooth shading you want normals to be an average of all the faces that use the vertex.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #5
I have scoured the net, but I haven't found anything very valuable. SO my solution, unless handed a solution on a silver platter, is to ignore lighting in this game, and implment lighting in my next game. I believe that would be best.
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #6
Quote:Originally posted by skyhawk
I have scoured the net, but I haven't found anything very valuable.

scoured?

Quote:SO my solution, unless handed a solution on a silver platter, is to ignore lighting in this game, and implment lighting in my next game. I believe that would be best.

you are waiting for solutions to be handed to you on a silver platter?? Well - in this case...

So you have a triangle. Thats three points:

Point TriangleVertex0, TriangleVertex1, TriangleVertex2;

Then your normal would be the cross vector of two edges.

Vector TriangleEdge0 = TriangleVertex1 - TriangleVertex0;
Vector TriangleEdge1 = TriangleVertex2 - TriangleVertex0;
Vector TriangleNormal = TriangleEdge0.Cross(TriangleEdge1);
TriangleNormal.Normalize(); //make into a unit vector

hth,
Codemattic
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #7
problem
I also use many quads
all my models are made of triangles, fans, quads, and strips of the two.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Arbitrarily split your quads into two triangles.

If the quad actually is planar, the two normals for the two triangles will be the same. If it's not planar, it was fairly meaningless to try and calculate the normal for it anyway Rasp
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Lighting a sphere with OpenGL lights (normals wrong?) cecilkorik 3 8,085 Dec 27, 2007 02:40 PM
Last Post: _ibd_
  Normals Nick 20 8,287 Mar 25, 2005 09:31 AM
Last Post: tigakub
  Normals? Quicksilver 3 2,871 Jan 13, 2003 05:31 PM
Last Post: henryj