# Lighting like glut materials and normals...

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

## Recommended Posts

Hello you all, since last week I'm having some trouble while managing lights.

Imagine a 3D scene with lots of cubes disposed in the middle of the world(0, 0, 0), and a point light source comming from (0, 0, -10). Without taking into account the shadows and so, the (0,0,-1) face of all the cubes should be lit, while the (0, 0, 1) face should not.
When the light reaches the center, just some faces of the cubes should be lit (the ones that are in the direction of the light).
Ok, this works perfect when working with glutSolidCube(x), because there is something (not just the normals) in this function that makes what I want to know.
But, if I create my own polygons and specifies their normals, this effect doesn't work.
E.g, I can draw a single square in the center of the scene with the normal (0, 0, -1). When the light is located in a z less than 0, that face of the square are lit. But when it's in a z higher than 0, the other face should be lit, but it's not.

So, it's not just the normals that should be calculated. There is something more in the glutSolidSHAPE that deals good with lights.
I hope you understand my doubt, since this is my first topic and my english is not that good.

Thank you!

##### Share on other sites

Hello you all, since last week I'm having some trouble while managing lights.

Imagine a 3D scene with lots of cubes disposed in the middle of the world(0, 0, 0), and a point light source comming from (0, 0, -10). Without taking into account the shadows and so, the (0,0,-1) face of all the cubes should be lit, while the (0, 0, 1) face should not.
When the light reaches the center, just some faces of the cubes should be lit (the ones that are in the direction of the light).
Ok, this works perfect when working with glutSolidCube(x), because there is something (not just the normals) in this function that makes what I want to know.
But, if I create my own polygons and specifies their normals, this effect doesn't work.
E.g, I can draw a single square in the center of the scene with the normal (0, 0, -1). When the light is located in a z less than 0, that face of the square are lit. But when it's in a z higher than 0, the other face should be lit, but it's not.

So, it's not just the normals that should be calculated. There is something more in the glutSolidSHAPE that deals good with lights.
I hope you understand my doubt, since this is my first topic and my english is not that good.

Thank you!

If you draw a single quad with a normal (0,0,-1) it should only be lit if the light is at a z below 0.

If you want a solid shape you have to render one face per side (if its infinitly flat then 2 quads are enough).

You should probably also enable backface culling when you render solid shapes as the backside of each triangle will always be hidden anyway and thus its pointless to render those.

##### Share on other sites

If you want a solid shape you have to render one face per side (if its infinitly flat then 2 quads are enough).

I achieved my purpose by using shaders, with a solution that can be found in this very site. Though, your way seems interesting, and I'll study it when I do not want to use shaders...
However, there is something new and ugly in my project.

In the following scene, the polygons are drawn in x, y and z bettwen -1 and 1. The light source is at (0, 0, -5). And everthing seems ok.

[attachment=7885:img1.JPG]

But when I rotate my camera...

[attachment=7886:img2.JPG]

... these black squares appears. They are the ambient light of my scene (0.0, 0.0, 0.0, 1.0). The wierd is that if my light goes to the center (0, 0, 0), these squares (just the ugly ones) remains exactly the same, when they should move along with the light. It seems that the iluminated fractions of the objects rotates as I rotate my camera...
This can better be seen if I decrease my GL_SPOT_CUTOFF to 30.0f, e.f. That small radius of light moves when I rotate along the x or y axis.

So, I want them to disapear or to be smooth, at least. Any ideas?

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013603
×