Sign in to follow this  
Tolito

Smooth Shading

Recommended Posts

Tolito    256

I have been working on getting proper shading on a model viewer I have made for a custom format. The first time I enabled lighting and set the lights and stuff, the model was completely white, unlike models in tutorials I saw, so I looked at the code for glutSolidCube to find that it uses normals.

 

In my PLY to my format converter, I made it multiply normals by 255 for X, Y, and Z normals (for the sake of saving space). In my renderer, I simply divided by 255.

 

glNormal3f(xn,yn,zn);

 

Where xn, yn, and zn are each normals between -1 and 1. Between 0 and 1 for this test, actually.

 

Surprisingly, the result had the same shading on every face (dark gray). I looked at the code for glutSolidCube again and noticed that X, Y, and Z normals do not each have a value. If X is 1, the others are 0. If Y is 1, the others are 0. If Z is 1, the others are 0. I modified my converter to write Normal*255 for whichever one was the greatest and 0 for the others. Then, there was a mixture of solid white and solid black faces. I have tried calling glNormal3f both per-vertex and per-face.

 

With that said, I am pretty mixed up on normals and shading in general. I would like to render shading on my 3D models and think it has to do with normals, but I'm not sure how to properly calculate them. If someone could help me figure out how, I would be grateful. Thank you for taking the time to read! :)

Share this post


Link to post
Share on other sites
Geometrian    1810

Put simply, the normal to a surface is the vector that is perpendicular to that surface. So, for example, if I have a triangle (0,0,0), (1,0,0), (0,0,1), then one normal could be (0,1,0). Yes, lighting calculations do use normals. The simplest model, for instance, calculates lighting intensity as the normal dotted with the light's direction.

 

But anyway, it sounds like you need to do some more research. Try to find something explaining OpenGL 2's lighting model.

Share this post


Link to post
Share on other sites
Helo7777    693

Yeah the Normal is perpendicular to its surface. It is needed in lighting calculations so it can be compared to a lights direction and determine that surfaces lit value. You could search for Blinn-Phong shading. This website also has a pretty good explanation under "OpenGL Directional Lights 1"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this