Jump to content
  • Advertisement


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


Smooth shading with "your own" normals ?

This topic is 6506 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

Hey. I've been messing with an .ASC reader just for lerning. It's based on an .ASE reader by Philippe Kunzle wich I found in his files for his OOGL project. I got it all working great, it can read ASC files and get all nessesary data to draw the object in openGL, but, since ASC files doesn't contain any normal data like ASE files I started messing with calculating the normals for each face in order to get the object affected by light. The rutine I wrote for that is:
AVector glASC::GetNormal(AVector v1, AVector v2, AVector v3) {
	AVector b1, b2;
	AVector	Normal;	

		b1.x = v1.x - v2.x;
		b1.y = v1.y - v2.y;
		b1.z = v1.z - v2.z;

		b2.x = v3.x - v2.x;
		b2.y = v3.y - v2.y;
		b2.z = v3.z - v2.z;

		Normal.x = ((b1.y * b2.z) - (b1.z * b2.y));
		Normal.y = ((b1.z * b2.x) - (b1.x * b2.z));
		Normal.z = ((b1.x * b2.y) - (b1.y * b2.x));
return Normal;
Probably very basic, and it works fine, except for the fact that all faces are flat shaded. I'm very new to openGL, but shouldn't glShadeModel(GL_SMOOTH); take care of that ? Or is there something wrong with the calculations. the full source can be found here: http://home.junkshop.nu/panic/glASC/ Again, I'm just trying to lern, so you don't have to point me to any existing ASC readers newbie2001 Edited by - panic on February 16, 2001 11:11:35 PM

Share this post

Link to post
Share on other sites

Don''t you need to normalize your vectors ??

I think you calculate one vector for a plane, that''s why you have flat shading. You need to calculate the average on each vertex of all the plane normals that this vertex belongs to.
Then you will get a smooth shading.




Share this post

Link to post
Share on other sites
GL_SMOOTH will work fine if you interpolate your normals...

to get the approximated normal for a vertex add the normals of all faces that share that vertex together and divide it by the number added normals..

another thing: normalize the normal vectors... (get them to unit length) otherwise you might get unexact results....
do not use GL_NORMALIZE cause it will renormalize them each frame, and normalizing involves an square root call, sooo...

hope that helped,

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Share this post

Link to post
Share on other sites

hmmm, now I feel stupid.

I spent hours of writing a routine that would calculate the vector normal for each vertex of the imported model.
When I compiled and tested it all worked great, smooth shading was perfect! Then I saw that I didn't even use the calculations I had made, but I simply gave the vertices vector that I was about to draw as normal.

like this:

glNormal3f(Vertices[Faces[\i].A].x /aScale, Vertices[Faces.A].y /aScale, Vertices[Faces[i].A].z /aScale);
glVertex3f(Vertices[Faces[i].A].x / aScale,Vertices[Faces[i].A].y / aScale,Vertices[Faces[i].A].z / aScale);
glNormal3f(Vertices[Faces[i].B].x /aScale, Vertices[Faces[i].B].y /aScale, Vertices[Faces[i].B].z /aScale);
glVertex3f(Vertices[Faces[i].B].x / aScale,Vertices[Faces[i].B].y / aScale,Vertices[Faces[i].B].z / aScale);
glNormal3f(Vertices[Faces[i].C].x /aScale, Vertices[Faces[i].C].y /aScale, Vertices[Faces[i].C].z /aScale);
glVertex3f(Vertices[Faces[i].C].x / aScale,Vertices[Faces[i].C].y / aScale,Vertices[Faces[i].C].z / aScale);

When I tested with using my calculated normals it got all messed up

I guess some things have an easier solution then you think of..

aww, seems like it only worked for a sphere , hmm, think I'll have to lern some more math before messing with this..

Edited by - panic on February 17, 2001 4:04:39 PM

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!