Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting question

Started by Mr Lane May 5, 2004 at 12:30 PM 6 replies 450+ views
Original Post
Mr Lane
Mr Lane
I am using lighting in my terrain app for the first time, the problem is it (the lighting) is per poly...not per vertex. I realized it is because i was specifying a plane normal for all 3 vertexes on the triangle, rather than a normal for each vertex which i didnt realize i had to do. Now the question comes, how does one calculate the normals for vertexes? I would not have a clue how do do this... Thanks in advance.
Trip99
Trip99
To create the gouraud normal for each vertex you sum all the normals of triangles that share that vertex and divide by how many there were. This is the standard way but if you have an irregular mesh you can improve the normals somewhat by taking the area of each triangle into account and sum based on relatiove sizes so smaller triangle normals have less effect than the normal from a larger triangle.
------------------------See my games programming site at: www.toymaker.info
Mr Lane
Mr Lane
Thanks for the help. Its actually an assignment i am doing and I dont think i am going to implement it before the due date which is soon. Its not a requirment anyway.

The problem is, with the way i store my terrain data it going to be tricky working out how to do these calculations.

Never mind!
Trip99
Trip99
Anonymous Poster: yes of course you could just normalise but that would involve more calculations than dividing by the number
------------------------See my games programming site at: www.toymaker.info
VolkerG
VolkerG
To Trip99: But you do a division only when you need a normalized vector anyway. And dividing by the number of vectors does not mean that the resulting vector is normalized.

[edit] wrong person

[edited by - VolkerG on May 7, 2004 11:33:04 AM]
Trip99
Trip99
I assume the face normals will be normalised (hence the name) so dividing by the number you have summed up is gauranteed to give you a normal. But I do see your point and at the end of the day it just depends how you are doing your calculations and one method may be quicker than another depending on the circumstances.
------------------------See my games programming site at: www.toymaker.info
FReY
FReY
Actually Trip, that''s not the case. Although, it is something that I once believed too...

As an example: take the 2 vectors (1,0,0) and (0,1,0). These vectors are clearly normalized. Adding them and dividing by 2 yields the vector (0.5, 0.5, 0) and the length of this vector is sqrt((0.5)^2 + (0.5)^2) = sqrt(0.5) which is 0.707 which is quite clearly not equal to 1.

But, the closer your original vectors are to each other the closer the sum and division method will be to 1. But for most lighting this isn''t accurate enough.


do unto others... and then run like hell.

Topic Locked

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

Sign in to reply to this topic.