lighting and normals
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.
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.
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.
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.
I would look for some load-time normal calculating stuff on the Net. It'd probably be easier than remaking models.
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.
Also remember that for smooth shading you want normals to be an average of all the faces that use the vertex.
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: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
problem
I also use many quads
all my models are made of triangles, fans, quads, and strips of the two.
I also use many quads
all my models are made of triangles, fans, quads, and strips of the two.
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
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
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Lighting a sphere with OpenGL lights (normals wrong?) | cecilkorik | 3 | 7,082 |
Dec 27, 2007 02:40 PM Last Post: _ibd_ |
|
| Normals | Nick | 20 | 7,759 |
Mar 25, 2005 09:31 AM Last Post: tigakub |
|
| Normals? | Quicksilver | 3 | 2,577 |
Jan 13, 2003 05:31 PM Last Post: henryj |
|

