Skip to main content
gamedev.net
🔒 Locked

Problems with lighting

Started by Snale 6 replies 1.3k views
Original Post
Snale
Snale
I have been writing a model class for handling and viewing 3D models. Everything is working great except for that it seems like the my normals or something is messed up... I am currently importing the models from 3D studios .ase format and maybe this is were the problem lies. I am not using the normal information in the .ase files, because I want to reduce file I/O as much as possible, and calculates them using the cross-product instead... I was thinking that not all the triangles vertices are not defined in the same order, and since the cross product isn''t commutative I would get strange results. Thanks in advance! Snale +--Java Game
Julio
Julio
what api might you be using? if it''s opengl, make sure you specified the materials. that''s a common mistake with opengl.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Sentinel
Sentinel
You shoud also know, that more triangles can share each vertex. So you must use avrage value of all triangle normals that share that vertex.
davior
davior
I too have written a program which reads the info from an ASE file to draw 3D models, and have had no trouble in using the normal data used in the file.. I was wondering how it was that you are calculating the normals if you are not using these values?

I know that in reading out the vertices, texture vertices and noramls, it is important to also read out the vertice order the texture verice order and the normal order. Perhaps when you are calcuating the normals, you have to take this order into consideration?
I can''t say that I really understand how it is that you are calculating the normals, would you please attempt to explan this to me cos I would be intested in hearing it.

thanx

davior

davior
davior
Also, are you calculating the normals for each vertice or just for each face (or both)?

davior
Snale
Snale
The reason for not reading the normals from the ase file is that since I use my own model file format (so I could embed textures and stuff like that) and I want to save som precious disk space, why save redundant data...
Anyway, to calculate a normal you could use the crossproduct, this article is explaining all this quite good. The trick is that if you use the crossproduct on two vectors ( you could treat the sides of an triangle ) it will return a vector that is orthagonal to both vectors.
I am using OGL, but by materials, do you mean plain textures, or is there some special parameters or something? If it is textures, they work just fine.
I haven't not been able to test anything yet but the average normal thing seems likely since I am only calculating the normal on ABxBC now.
When I calculate the average normal I suppose I should use the cross product on all vectors, like this:

There should be an triangle here, but since I couldn't get it right even using the code tag, you'll have to survive without it

on a triangle with corners ABC
(ABxBC + ACxAB + ACxBC) / 3
or am I completely lost now


Snale
+--Java Game


Edited by - Snale on September 12, 2000 6:44:13 PM

Edited by - Snale on September 12, 2000 6:47:28 PM
davior
davior
That''s some interesting stuff about the Normals. I''ll have to look into that. (Normals have always confused me. What are they for anyway?)
About the Materials, I suggest you look into the glMaterial() function. In the ASE file, there are a set of values which describe the Material properties of each object. They are inthe same chunk that describes the textures and U W offset. they are called something like MAT_SPECULAR MAT_AMBIENT etc. And the glMaterial function can alter these values.

And it sounds like the way you think you should be calcing your Normals is more accurate than the way you were before..

davior
Snale
Snale
Thanks, I''ll look into that function.
Normals are used to calculate how the light is reflected.
When light is reflected the angle between the normal(n) and the incoming(i) light ray is equal to the angle(u) of the reflected ray(r).

So you must know the normal to know in wich direction the reflected light will go. The normal is nothing else than a vector orthogonal to the point on the surface where the light ray will be reflected..


i n r
\ | /
\ | /
\v|u/
\|/
-----------


Snale
+--Java Game

Topic Locked

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

Sign in to reply to this topic.