Skip to main content
gamedev.net
🔒 Locked

Generating Normals

Started by Matthew123 Aug 2, 2002 at 1:44 AM 15 replies 2.4k views
Original Post
Matthew123
Matthew123
Could someone give me a link to a tutorial on generating normals, so the lighting on my terrain is smooth. Thanks
walkingcarcass
walkingcarcass
is your terrain tesselated patches, or have you got a soup of polygons from a model editor, or what?


********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back
spraff.net: don't laugh, I'm still just starting...
Matthew123
Matthew123
I got my terrain from a height map and a brute force method but i don''t know how to calculate my normals so the lighting will be smooth.
Matthew123
Matthew123
Could someone please help me.
Hippokrates
Hippokrates
I have a question too (it is fairly stupid I admit ).
If I have a vertex (-1|-1|0) is its normal then (-1|-1|-1) ?
(I know I could also have it point into the opposite direction, but is this correct?)

Im Anfang war die Tat...
Faust
Im Anfang war die Tat...Faust
thedo
thedo
D3DXComputeNormals()

or look at Mr Snows web site (cant remeber the direct link)

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
Drath
Drath
Couldn''t you simply point all the point normals upwards? That should give smooth results. Else find the normals of each polygon that shares the point, add the normals together then divide by the number of polygons.
Ekas78
Ekas78
quote:
Original post by Hippokrates
I have a question too (it is fairly stupid I admit ).
If I have a vertex (-1|-1|0) is its normal then (-1|-1|-1) ?
(I know I could also have it point into the opposite direction, but is this correct?)

Im Anfang war die Tat...
Faust


A normalized vector can't be [-1,-1,-1]. (unless we define a unit as something else)
Try Sqrt( (-1)^2 + (-1)^2 + (-1)^2 ) I'd bet you get a result > 1

____________________________________________
I AM THE GOD OF SHADERS. LET ME ENLIGHT YOU

[edited by - ekas78 on August 3, 2002 5:04:37 PM]
______Only dead fish go with the main-stream.
Hippokrates
Hippokrates
Well, I did not mean a normalized vector but a normal vector to a vertex.
I have got a vertex [-1|-1|0], what is its normal then ?

Im Anfang war die Tat...
Faust
Im Anfang war die Tat...Faust
RapidStunna
RapidStunna
A vertice''s normal cannot be just determined by it''s position. It needs it''s neiboring triangle vertices. From there, you take the cross product of the two vectors of the triangle that share a same point to get a vector perpendicular to the two which is the normal vector. you should normalize it(no relation to it''s normal. it just means to have a magnitude of 1) so calculations are quicker and accurate.

Setting the normals up won''t produce correct lighting. If you arn''t using triangles for rendering but you have all the points, then just get the neiboring vertices and take the cross product of them. If you get backwards lighting, switch the order of the cross product. Backwards order produces backwards normals.

---
My Site
Come join us on IRC in #directxdev @ irc.afternet.org
Hippokrates
Hippokrates
Well, I am using these vertices for my quads.
I have those Vertices:

**-----*
| |
| |
*-----**


Where there are two stars I have 2 vertices because I am using a triangle list.
Every frame I manually transform vertices and normals (both the same way).
But how do I calculate the normals in this scenario ?
(Just for a single Quad, 6 vertices, 2 primitives)

Im Anfang war die Tat...
Faust

[edited by - Hippokrates on August 4, 2002 1:02:52 PM]
Im Anfang war die Tat...Faust
darookie
darookie
A--B
|\ |
| \|
D--C

N' = (B-A)x(C-B)
N = N'/|N'|

where 'x' is the cross product and |N| the length of the vector.
N is the normal vector of the quad (given that A,B,C, and D are
on the same plane)

[edit]
Typo.
Maybe you need to flip the direction of N, by either swapping
A and B or C and B in the formula or just multiply N by -1...

If A,B,C and D are not on the same plane, then just calculate
N1 = normal(A,B,C)
N2 = normal(A,C,D)
N = (N1+N2)*0.5
[/edit]


[edited by - darookie on August 4, 2002 1:16:39 PM]
Matthew123
Matthew123
I have read the various ways to set up normals, but i was looking for a turotial that showed how to do it in actual code.

Topic Locked

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

Sign in to reply to this topic.