Advertisement

Light sourcing using Normals

Started by November 22, 2002 12:30 PM
1 comment, last by GuybrushNivek 22 years, 3 months ago
Hi, I posted ealier about Normals and using them to cull and light-source. The problem I am having is that 2 faces lying on the same plane light differently in some cases... I checked out the Normal generation and sure enough, 2 different sized triangles lying on the same plane are reporting different Normals...does anyone know a way around this ? Thanks in advance ! :-)
:-)
How do you generate these normals? Are they normalized?

We need more info.

Cédric
Advertisement
Sounds like cedricl has maybe stumbled onto your problem. When you calculate the normal to a triangle using the cross product, the length of that normal vector is equal to the area of the triangle. Bigger triangles have bigger areas and therefore longer normals. You must normalize, or unitize ---- make the normal a unit length vector ---- for your lighting calcs. Do do this, do the following:

length_of_normal = sqrt(normal.x*normal.x +                        normal.y*normal.y +                        normal.z*normal.z);normal.x /= length_of_normal;normal.y /= length_of_normal;normal.z /= length_of_normal; 


Do that for every triangle, and the normals will all have a length of 1 (unit length).

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement