
Lighting: Am I on the right track?
Man, lighting is confusing as heck - I thought I had the hang of it, now I'm not so sure!
What I've done seems to be working, but what I was hoping for is if I could type what I *think* I understand, and if there are any big holes in it, let me know - thanks.
Anyway, I have this City demo that I've basically been working on since the outset of my OpenGL lifetime. It's just 12 rows of textured buildings with grass and a flowing river.
The lighting effect that I wanted was to emulate the sun - I wanted the sun to appear to rise in the east, thereby only illuminating the "eastern" sides of the buildings, and at noon basically illuminate completely the whole city, then as the sun sets you see only the western sides of the buildings illuminated with just a little bit of light on the other sides.
Here's what I did:
Set global ambient illumination to .2, .2, .2 (so that it's never just a 100% black screen)
called glEnable(GL_COLOR_MATERIAL) (for now I'm just assuming all of the buildings are made of the same material)
Created *one* OpenGL light
set its ambient *and* diffuse to sin(index * Pi) where index is a number that cycles from 0 to 1. I ended up using both because if I use only the diffuse, then any surfaces whose normals are perpendicular to the light never get lit. Besides, "early in the morning" I only want a little bit of the diffuse light reflected. Am I correct that "around midnight" the ambient light reflected is added to the diffuse light reflected? That sure seems to be the effect I'm getting.
Set the position of the light as:
(-cos(fLightIndex * 3.14159f), -sin(fLightIndex * 3.14159f), 0.0f, 0.0f); (which basically says, start out pointed along the negative X axis, then at "noon" (when fLightIndex = .5) you'll be pointed straight down, then finish pointed along the positive X axis.)
Set the SpotCutoff parameter to 180. (This is where I'm confused - I thought that if the fourth parameter to GL_POSITION was 0, it was a directional light not a spotlight - I played with my code and if I set SpotCutoff to anything but 180 very little if any of the city gets lit - what did I miss?)
It seems that SpotDirection and the 3 attenuation parameters get ignored - I get the same results no matter what I set them to.
Going forward, I plan to start playing around with material properties, in particular specular - some of the buildings are obviously glass, some are shinier brick and some are really dull brick, I should play around with giving each building different material properties and giving the light a high specular component to see what kind of effects I get.
My code is on the website in my sig (daltxcoltsfan.tripod.com) if anyone's interested in looking at it, but it's horrible code - proceed at your own risk
. The light code is toward the end of Render().
Any glaring holes in my understanding?
Thanks
Joe
Love means nothing to a tennis player
[edited by - DalTXColtsFan on May 22, 2003 6:29:57 PM]

Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
A quick glance and i notice you mention glEnable(GL_COLOR_MATERIAL) - yet you seem to be using glMaterial*(). Choose one or the other, at the moment probably a good idea to stick with glMaterial and leave COLOR_MATERIAL disabled.
Leave the GL_SPOT etc. values alone, you don''t need to change them for a directional light (like you have for the sun, you''re right with the w coord set to 0 to give a directional light).
If you''ve got COLOR_MATERIAL enabled when you shouldn''t, then thats probably leading to the unexpected results.
Leave the GL_SPOT etc. values alone, you don''t need to change them for a directional light (like you have for the sun, you''re right with the w coord set to 0 to give a directional light).
If you''ve got COLOR_MATERIAL enabled when you shouldn''t, then thats probably leading to the unexpected results.
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
please could someone explain me what glEnable(GL_COLOR_MATERIAL) and what glMaterial() do?
thanks!
There aren''''t problems that can''''t be solved with a gun...
thanks!
There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...
From the docs:
When you use lighting, by default GL is setup to use the properties you define via glMaterial*() for the surface colours. This lets you control the ambient, diffuse and specular individually - but you can only change material properties outside of begin/end, so one object (or batch of polys) can only have one material for all of the triangles.
If you use COLOR_MATERIAL you can make the material colours ''track'' the vertex colours (the ones you set with glColor*() calls). This way you can make (for example) the diffuse colour the same as the glColor*() and change the colour of an object on a per-vertex basis.
quote:
If enabled, have one or more material parameters track the current color
When you use lighting, by default GL is setup to use the properties you define via glMaterial*() for the surface colours. This lets you control the ambient, diffuse and specular individually - but you can only change material properties outside of begin/end, so one object (or batch of polys) can only have one material for all of the triangles.
If you use COLOR_MATERIAL you can make the material colours ''track'' the vertex colours (the ones you set with glColor*() calls). This way you can make (for example) the diffuse colour the same as the glColor*() and change the colour of an object on a per-vertex basis.
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
haven''t checked that myself, but in tut42 you should find something about GL_COLOR_MATERIAL...
thank you very much !
There aren''''t problems that can''''t be solved with a gun...

There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...
quote:
Original post by Bero_Avrion
haven''t checked that myself, but in tut42 you should find something about GL_COLOR_MATERIAL...
I''m afraid that the information you find about GL_COLOR_MATERIAL in lesson 42 is wrong... I already sent a mail to NeHe, with a correction... It is in fact the texture enviroment mode (glTexEnvf() function...) that lets you colour textures, not GL_COLOR_MATERIAL...
GL_COLOR_MATERIAL allows you to use "color tracking"... This is a technique that colours the polygons, when lighting, with glColor(), instead of using glMaterial(). I think it should be more or less equal to changing the diffuse parameter with glMaterial(), only much faster.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement