#### Archived

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

# Lighting the insie of a cube

## Recommended Posts

Im trying to make a lit room. The camera is inside ans there should be comming a light from the ceiling. im doing the following: enable lighting enable light0 position the light set diffuse light to 1, 1, 1 set light model to local point light draw the cube with normals pointing to the inside and draw the verteces clockwise so that the front faces will be inside Ok, the cube is lit from the inside now, but the onlything i see is a white screen now, all 6 polygons have the same color! I want the floor to look darker than the ceiling, becuz the light comes from the ceiling. oim very sure the light posision is correct.. i hope you can help me (btw with a sphere this works fine!) thx -xill

##### Share on other sites
I believe you're looking for light attenuation, which makes the light fade with distance. Place the light source closer to the ceiling.

Maybe it "works" with a sphere because the many polygons show off how the light hits at varying angles? Just a guess.

[edited by - Waverider on April 30, 2002 11:59:27 AM]

##### Share on other sites
isnt that normal in a light??

i mean, if light doesnt fade in distance what does the position matter??? then it can be everywhere in the room...

how can i turn attenuation on?

like..

glLightfv(GL_LIGHT0, GL_*_ATTENUATION, x); ???

and what should be best for * and x??

-xill

##### Share on other sites
nothing is normal for a light in computergrafics, cause simulating correct lighting is _FAR_ from beeing in realtime..

what gl does is:
ambient + diffuse + specular
where you can set colors for those..
diffuse is what you''re using and is calculated with the cosine of the angle to the light and the surfacenormal, as well as the distance-attentuation. the distance-attentuation-function is att = 1/(a+bx+cx^2) where you have to set the parameters..

and, most important: remember its only calculated per vertex.. in your geometrical case you will get the worst artefacts if you don''t tesselate your cube to some higher res.

guess you should read some docs about how lighting is done in gl, and play around for a while, it should clarify a lot..

don''t ask too much from the gl-lights, they are old and crap, but they work on every implementations, wich is the "power" of them.. (they look damn cool for highres-meshes like on sgi-workstations btw.. have seen it one time.. wow...)

"take a look around" - limp bizkit

##### Share on other sites
so youre saying that all pixels must have the same color in 1 polygon? i dont believe that..
btw.. i didnt see any difference when i made my cube of 6*16 polygons :/

##### Share on other sites
So what do i have to do to make the light realistic in that cube? thats the most simple light i can think of, shouldnt be too hard right?

In the game engines of today it looks pretty cool and i still have alot FPS

##### Share on other sites
THIS is what i had in mind
http://developer.nvidia.com/view.asp?IO=pp_attenuation_ogl
only then, a stationary ligth source

\o/

##### Share on other sites
for gl, nothing is stationary as gl does not know any scene..

but this is perpixellighting you look at (more precious, pertexel lighting) and like that independend of vertice-count
if you simply enable GL_LIGHTING you get the standart lighting of opengl, wich is pervertexlighting, wich only calculates one lighting-value per vertex (means 3 per triangle and then linear interpolated like colors)

"take a look around" - limp bizkit

##### Share on other sites
yeah i know all that, i read te theory 100x now....

but i DONT see any difference between ANY vertex in my quads..
EVERY pixel in my quad has the same color.

I dont really want per pixel lightning but i want it to look like when you assign 3 different colors to the verices but then with different light values...

what ever i do with GL_*_ATTENUATION, i dont see anything happening...

i saw what i want just done with the standard opengl light

hel me

##### Share on other sites
Okay, a stupid question first: Did you enable GL_POLYGON_SMOOTH?
probabely since it all goes well with a sphere.

I think the problem is that the light position is in such a way that values from the normals calculated by the light are somehow all the same. Try placing the light in one of the corners instead of the center of the roof (is it in the center now)? Are all your normals correct? (eg normalized and all?) Is your diffuse light set too high (this can cause every polygon to be full bright)? Do you use one normal per poly or one normal per veretx? (try one normal per vertex if possible).

If you have some spare time, look through the OpelGL docs and find out exactly how OGL calculates light based on the normals. Calculate them by hand to find a light position that *must* result in different colors on each vertex. Insert it and try to experiment with all the other settings.

My two (euro) cents

- An eye for an eye will make the world go blind -

##### Share on other sites
ok thx for the help, ill try that, but the polygons are all quads, and each vertex of the quad has the same normal right? so per polyogn normals should be enough here i guess :/

cya

##### Share on other sites
Nope! This is where you head the wrong way. In the cube, all of the vertex normals on a quad are actually different! To calculate a vertex normal, first calculate all the polygon normals.

Go to a specific vertex and add all adjecent polygon vectors together. For your cude. One corner belongs to 3 quads. Add the normals of these 3 quads together. Normalize the result. This is your vertex normal. Use this vector on all 3 vertexes that make up this corner of your cube.

Here you go, per vertex lighting I hope this will improve the lighting of your cube.

- An eye for an eye will make the world go blind -

• ### Forum Statistics

• Total Topics
628327
• Total Posts
2982091

• 22
• 9
• 9
• 13
• 11