OpenGL Lighting questions

Recommended Posts

I've done a bit of searching about the forums, looking for a few clues, but while some questions have been answered a few more have taken their places. So I'll define my problem first, and what little understanding I have, and hopefully someone out there will be able to point me in the right direction. Right, so I'm looking for a way to display more than 8 lights in OpenGL (why the limit after all these years?). I've found some tutorials on how to do many lights in one scene, but I'm told such a method will not work with deferred lighting. I'm also told that the only method it will work with is extremely slow for a higher poly scene (>100k) where deferred lighting can deal with lots of lights (but not more than 8?) very quickly depending on the resolution. The trouble is, I've read that deferred lighting has problems sorting transparencies, which my scenes will have a lot of. Am I basically stuck with... Forward rendering is it? Or can I do more than 8 lights with deferred lighting and deal with transparency issues? [Edited by - Feynt on March 3, 2008 7:54:11 PM]

Share on other sites
Quote:
 Original post by FeyntRight, so I'm looking for a way to display more than 8 lights in OpenGL (why the limit after all these years?).

That's 8 lights in a single draw call. Not 8 lights in the entire scene, or 8 lights visible at once. If I climb up a hill at night, I can see hundreds of streetlights. Does that mean that there are hundreds of streetlights shining on each car?

Share on other sites
Ah, I was told 8 in total. >P
So having lots of lights drawn would mean lots of drawing passes, which I guess is what forward rendering is?

Share on other sites
Quote:
 Original post by SneftelThat's 8 lights in a single draw call. Not 8 lights in the entire scene, or 8 lights visible at once. If I climb up a hill at night, I can see hundreds of streetlights. Does that mean that there are hundreds of streetlights shining on each car?

Yes, there will be hundreds of lights shining on your car if you can see hundreds of streetlights.

@Feynt
If you want to use the fix pipelines functions, of course it would be bounded by the implementation.

However, you must have using shader as you said you are doing deferred rendering, right? By using shader, you can write custom code to do whatever you want. In this case, you can do a lot more lighting calculation in a single pass as long as the shader can handle. If your shader code have too many instructions, you would like to use Cg from NVidia too. Cg will divide your Cg code into multi pass without bothering you. Also, shader program already support dynamic branching, therefore it can lower the number of instructions significantly if you are using it correctly.

Share on other sites
Quote:
 Original post by ma_htyYes, there will be hundreds of lights shining on your car if you can see hundreds of streetlights.

Wrong. Try again. (Note, it's not your car.)

Share on other sites
Quote:
 Original post by FeyntSo having lots of lights drawn would mean lots of drawing passes

Only if you actually wanted more than eight lights simultaneously shining on a single object. The thing is, situations where more than eight lights are actually having a noticeable effect on a given object are vanishingly rare. For those situations, you can use something like SPH, but the complexity and added computational burden there are unlikely to be worth it.

Share on other sites
Ah, well I don't want more than 8 lights shining on the same object. In all likelihood less than 8 will be in any given area. But like, if I were looking out over a village from up on a hill, I'd like to see my torch light, my camp fire nearby, the moonlight in the scene, and lighting from 10-20 lanterns around the village. Or in another case, a lit walkway at night with rows of lights shining down on the pathway. With a sufficiently long path that curves around a lake, you'd see more than 8 lights for sure.

So as long as I don't have more than 8 lights in one spot shining on the same object(s) (or don't want more than 8 lights to add up on the object(s)) I don't need to do multiple passes to get more lights going and I can skip deferred lighting?

Also, what's SPH? I can only find references to fluid dynamics on the net and I don't see how that applies to lighting unless I want to start doing refraction (which I don't).

Share on other sites
Quote:
Original post by Sneftel
Quote:
 Original post by ma_htyYes, there will be hundreds of lights shining on your car if you can see hundreds of streetlights.

Wrong. Try again. (Note, it's not your car.)

Funny Sneftel... I try again later in year 2030 when I have the time...

Share on other sites
Quote:
 Original post by FeyntAh, well I don't want more than 8 lights shining on the same object. In all likelihood less than 8 will be in any given area. But like, if I were looking out over a village from up on a hill, I'd like to see my torch light, my camp fire nearby, the moonlight in the scene, and lighting from 10-20 lanterns around the village. Or in another case, a lit walkway at night with rows of lights shining down on the pathway. With a sufficiently long path that curves around a lake, you'd see more than 8 lights for sure.So as long as I don't have more than 8 lights in one spot shining on the same object(s) (or don't want more than 8 lights to add up on the object(s)) I don't need to do multiple passes to get more lights going and I can skip deferred lighting?
Exactly. When you want to render an object, determine what lights are important for that object, and set them.

Quote:
 Addendum:Also, what's SPH? I can only find references to fluid dynamics on the net and I don't see how that applies to lighting unless I want to start doing refraction (which I don't).
Heh, I've got fluid simulation on the mind. I meant SH, Spherical Harmonic Lighting.

Share on other sites
If the light positions are static (street lamps, etc), why don't you just use lightmaps?

Share on other sites
SH sounds nice, but I plan on having moving objects in the world. For what I'm planning, not much will be guaranteed to be a static object, so I don't think it'll work (the Wikipedia entry suggests that translations and deforming meshes won't work with the technique). As for light mapping, I think that faces the same problem since neither the lights nor the environment are guaranteed to be stationary. Though having the option for setting certain things to "immovable" might work out in that respect. Hmm, gears in motion. >)

[Edited by - Feynt on March 7, 2008 2:19:44 PM]

Share on other sites
So after giving it some thought, I perhaps need to know a bit more about how SH works. Some places I've gone suggest that lights and/or objects CAN be moved within the scene. Others suggest that a gratuitous amount of memory and processing power would be required to store the values for lighting a scene. Considering I have a rather low minimum requirement to work with (4 year old hardware basically, maybe earlier), and the scenes will be dynamically generated, this method doesn't seem like it'd be feasible in this situation. It's dead sexy, what it can do, but... Someone tell me I'm wrong. >D
Light mapping looks like a more process friendly alternative, as I can generate results of whatever resolution I choose, and can start off quick and low res and work up.

Dynamic lights or objects (things I'm deeming to be physical, or possibly moving through other means, which I've decided is easier to flag in this case) will just use another rendering method. But this brings me back to the point of the topic, which I guess is now a good deal easier to answer now that a portion of the problem has been dealt with: Is deferred lighting a better idea for the dynamic side of the equation, considering I'll have transparencies moving about, or would just going forward with another lighting scheme work better?

Create an account

Register a new account

• Forum Statistics

• Total Topics
627701
• Total Posts
2978709
• Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12