Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lighting Normals

This topic is 5928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im a newbie.. I have a relatively flat rolling terrain working and its textured and lit with point lights.. I read some Tuts for calculating the normal, though Im not confident with the results Im getting.. A Plane Normal from what I understand is: Normal = (p1 - p2) * (p3 - p2) Does that have to be then Normalized before being used, for example with D3DXVec3Normalize? Can someone just clear this up for me..

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
welllllll that doesn''t give a vector... what you''ll want to search for is the cross product (I don''t have have the formula here now, it''s in the dx8 documentation and you seem to be using dx8or7, make it search for "cross" and the use two coplanar vectores (which you are already calculating, those two subtraction you''ve got).

as your using dx8 you''ll have always normalize the normal, unless you want to try some weird new effects...

one notice, as your using dx8, the above mentioned normal is the plane normal and this is only useful if you''ve got three separate vertices for every plane (or use some of that striding(?) thingmajig that allows you to point to the data instead of neatly assigning all the vertices separately) and you desire sharp edges all the way around. In DX 8 you need to calculate the vert normals, don''t worry with these dx8 will give you smooth gourand transitions, so it actually saves on work. To get the vert normals: pick up the plane normals, add up all the plane normals of planes that share that vertice and normalize your end result. It might sound extremely expensive but you should remember that this isn''t done every frame and when you do do it it''s because your loading non visualizable data (and you can separate these calculations by various frames doing x now and x the next frame or the next second and so on... oh, and this data is much faster to load preprossesed...) or morphing the terrain and you''ll probably have some method which will help (eitherways, if you don''t you can always recalculate the normals of a given medium patch, without grinding 5fps).

extra notice, playing around with the methodology used to calculate vert normals and with features like some kind of flag or some weight system or just dot producting the angles and using some top limit to define sharp angles, you can create some mthod that actively set''s sharp and soft sides (noting that sharp sides imply having mor then 1 vert for said segment in that same space).

Share this post


Link to post
Share on other sites
  
// p = b - a

p.x = pV[1].x - pV[0].x;
p.y = pV[1].y - pV[0].y;
p.z = pV[1].z - pV[0].z;

// q = c - a

q.x = pV[2].x - pV[0].x;
q.y = pV[2].y - pV[0].y;
q.z = pV[2].z - pV[0].z;

o.x = (p.y * q.z) - (q.y * p.z);
o.y = (p.z * q.x) - (q.z * p.x);
o.z = (p.x * q.y) - (q.x * p.y);



Where pV is an array of 3 vertices.
o is your normalised vertex that you''d put into each vertex of the triangle

Oli



All the best problems start with C

.:: K o s m o s E n g i n e ::.

Share this post


Link to post
Share on other sites

What downgraded told you is correct, but this will give you the SURFACE normal for the tri. If you feed this into every vert, you will get flat shading which wont look good.

What you need is the vert normals, which as AP pointed out is calculated like so by summing and then normalising all of the plane coords for tris that also share that vertex.



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!