gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > glnormal() - does the normalvector need to be normalized ?

#117898 - qw3rty - Thu Feb 08, 2007 2:58 pm

I don't get the expected lighting on faces, that are angular to the light.
The faces stay fully lit(?!), until an extreme angle.

P.S. : my normalvextor (not normalized) is in the range from (-1,1,0) .... (1,1,0)
the y-component is the one facing the light, and always stays 1 (maybe that's why it's fully lit until an extreme angel ?)

P.P.S. : in other words : does the normal (1,1,0) result in the same lighting as (1/sqrt(2), 1/sqrt(2),0) (the normalized vector).

#117905 - Dwedit - Thu Feb 08, 2007 5:16 pm

I know that normal vectors must be normalized on a PC, not sure about the DS.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#117908 - silent_code - Thu Feb 08, 2007 5:28 pm

make sure you don't "overflow" the normal fixed point format.
they should be normalized, because of the format (look it up).

i don't recommend normalizing stuff on the ds. write the normals to the file together with the mesh. i tried to calculate the normals at mesh load time, but exactly the same code i use inside my tools produced garbage on the nds. then, when you transform geometry, just make sure its normals get transformed aswell.

feel free to correct me, as i solved the problem some time ago and i can't remember any specific stuff. ;)

#117914 - Rajveer - Thu Feb 08, 2007 6:00 pm

My experience is that normals need to be normalised, but when using them for rendering a polygon (as opposed to using them for collisions or anything else) you have to check whether one of the components is the max value and if it is, minus 1.

#117955 - qw3rty - Thu Feb 08, 2007 10:41 pm

I made sure, that the v10's never exceed 511 (otherwise they point in the different direction :O)
Unfortunately the normals are calculated at runtime, and it would be hard to calculate them beforehand.
(I draw a sine-wave, and want to be able to change the amplitude, frequency, etc. so precalculating isn't possible ?!)
When I was at work, I thought about the lighting problem, and maybe it seems fully lit at small angels, because of the low color-depth on the NDS (the difference in lighting is swept away due to lost accuracy ) ?!

#118009 - dannyboy - Fri Feb 09, 2007 2:16 am

You have to normalise the normals. And btw you are using normals per vertex and not per polygon right?

#118039 - qw3rty - Fri Feb 09, 2007 10:09 am

Yes, I am using normals per vertex.
What happens if you don't normalise normals ?
On other platforms you DON'T have to normalize the normal :
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/normal.html

#118258 - silent_code - Sun Feb 11, 2007 5:25 pm

if you don't get it to work properly, try to calculate your normals with floats and then convert them for rendering.

#118400 - Rajveer - Tue Feb 13, 2007 1:33 am

You dont need normals per vertex, you can have normals per polygon, normals per vertex just gives a smooth shading (which perhaps you want) but using normals per polygon will still shade the polygons.

You say you make sure the v10's never exceed 511 right? I precompute my normals, but either way, I make sure in the code that 511 is the max value with a simple if statement. You always need to normalise normals, which can be consuming for the DS, but if you cant precompute normals then I guess its the only way to go :)

Sorry if I didnt help.

#118429 - qw3rty - Tue Feb 13, 2007 12:31 pm

I think I fixed the problem.
I projected 2*pi to 2.0 in 3d-space, but didn't take that into account when calculating the normals (they were the normals for the non-squished, flatter function)

#118598 - silent_code - Wed Feb 14, 2007 2:54 pm

hint: add "solved" to the topic ;)