This topic is 2086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites

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 on other sites

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 on other sites

Problem solved! Thank you for the links!

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009707
• ### Who's Online (See full list)

There are no registered users currently online

×