PDA

View Full Version : Lighting



gvm
02-02-2003, 12:32 AM
Is anyone can help me with lighting?
Everyone knows that opengl allow 8 light sources... but how to make more?
Must I write my own lighting?
Then the other question - How to do this? (where to put vertexes coloring?)
Yeah, I saw per-pixel lighting, but it is to hard for me. (i think) I just need simple, fast real-time lighting...
Is anyone can give an opengl example with own lighting??? (per-vertex lighting) plz.
tnx.

nexusone
02-02-2003, 04:47 AM
A simple way is to use light maps, which is texture that is applied using the blend function to create lighted area's on the texture or object under it.

Just do a google search on light map's.

or visit nehe.gamedev.net, I think he has a tutor on it, with light maps you have have unlimited simulated lighting.
I think most games use lighting maps, which takes less overhead then real lighting does.


Per pixel lighting is a more advance way to produce a real work lighting effects.


Originally posted by gvm:
Is anyone can help me with lighting?
Everyone knows that opengl allow 8 light sources... but how to make more?
Must I write my own lighting?
Then the other question - How to do this? (where to put vertexes coloring?)
Yeah, I saw per-pixel lighting, but it is to hard for me. (i think) I just need simple, fast real-time lighting...
Is anyone can give an opengl example with own lighting??? (per-vertex lighting) plz.
tnx.

gvm
02-02-2003, 05:03 AM
Yes, most games use light maps but for static lighting. I know about nehe(his tutorials are great!) but there is no tutorial about lightmaps and other lighting (only standart ogl). My main problem in using lightmaps is how to project them on quads/triangles and how must i generate them? (i know only how to create the radial glow(like sphere) texture)...
plz. need in help.
maybe someone has example app?

roffe
02-02-2003, 11:28 PM
Originally posted by gvm:
Everyone knows that opengl allow 8 light sources... but how to make more?


Even if a certain implementation of OpenGL only supported 1 light you can "use" as many lights as you want. The only limitation is that you can only use 8 simultaneous lights. Which is quite many(and slow).

You just have to call glLightf(...) over and over again. Example:

glLightf(GL_LIGHT0,GL_POSITION,mylight1);
draw_some_objects();

glLightf(GL_LIGHT0,GL_POSITION,mylight2);
draw_some_more_objects();

glLightf(GL_LIGHT0,GL_POSITION,mylight3);
draw_a_lot_more_objects();

But maybe you knew this already. In that case I suggest you do your own lighting. Vertex lighting works fine as long as your models are somewhat highly tesselated.

JustHanging
02-03-2003, 12:33 AM
If you really have to, you can always use multiple passes to render all the lights you want. Render the first 8 lights on the first pass, then use additive blending to render the next 8 on top of them and so.

If you use textures, you have to render the lighting without them, and modulate with the texture in an additional pass. All this is a bit slow, so you might be better off with lightmaps for static lights.

And so that nobody forgets, real world lighting is far from simple dot product lighting. Don't fall for that.

-Ilkka

gvm
02-03-2003, 02:17 AM
2roffe: I didn't know that. thanks.

2JustHanging: But how to make lighting without multi-passing?

and again:
If i whould use own vertex-lighting so i need to insert it somehow into rendering pipe-line. (?right? sorry for my english) But how?

and about lightmaps: may i use simple sphere-like texture? then, how to project it on quads/triangles?

is someone make own lighting(not ogl)? need example of that thing. http://www.opengl.org/discussion_boards/ubb/confused.gif
I need something like in OnPaint():
clear,
set perspective.
set 125 http://www.opengl.org/discussion_boards/ubb/eek.gif lights(pos,rgba). set objects. (doing transformations)
flip.
and objects is lighted...
maybe I lost somthing? (i'm stupid and trying to make my own game-engine)
---------
with best regards...

JustHanging
02-03-2003, 02:47 AM
For your own vertex lighting:

-Set all vertex colors to zero/ambient
-For each light, add light's contribution (from the lighting equation) to each vertex color.
-[optional, but cool] If your lights have a high dynamic range (vertex colors ranging way beyond one), apply exposure.
-Draw your stuff with these vertex colors

For lightmaps, I don't think these guys mean quite that, it's more like having a unique texture for all the faces, and those textures contain precomputed lighting from all the lights.

In practice you should group some faces together and use the same texture for all of them. Planar surfaces are a good choice. For each group, select the one from xy, xz and yz planes that in closest to the surface plane. Determine the group's vertice's maximum and minimum values on this plane and map the texture according to them. Then calculate lighting for each texel.

You should use relatively low-resolution lightmaps, and try to group all the lightmaps into one big texture. Lightmaps are a bit complicated to get working, but the results are nice.

-Ilkka

vincoof
02-03-2003, 01:58 PM
As a side note, I doubt you ever need 8 lights simultaneously. And even if you did, you would get bad performance.
The OpenGL FAQ (http://www.opengl.org/developers/faqs/technical/lights.htm#ligh0070) explains that pretty well.

[This message has been edited by vincoof (edited 02-03-2003).]

gvm
02-04-2003, 02:51 AM
Thanks for that everyone!
And how about static lighting? (lightmaps? or something else?)
And about the lighting used in q2(dynamic lighting) - they are used triangles to draw simple lightmap?

vincoof
02-04-2003, 11:06 AM
lightmaps is not necessarily "static lighting. For instance, when the light follows the rocket it's not static.

Lightmaps are somewhat hard to implement for various reasons, especially dynamic lighting (moreover dynamic lighting looks very fake with lightmaps). Though, it gives a feeling of per-pixel which is useful on low-polygonal meshes (for instance walls rendered as a big quad).