How to do this 2D pseudo-lighting technique?

Started by
4 comments, last by mikeman 19 years, 6 months ago
First of all, my game is 2D with textured quads using OpenGL. I want to implement lighting, but i won't be using "actual" lighting. To do that, i can sort of fake it by layering an alpha-blended textured quad of a "light sphere" and do additive blending. But now i want the reverse: imagine a light in a dark cave. If the cave is black and i slap my textured quad down, i just get grey. That does not work. Let's say this is my unlit game screen for example (just a mockup): I want to be able to have my "lamp" light up the dark like so: I can do that by having a black texture with a whole cut out of it to simulate a restricted field of vision but the real problem is what happens when i have several light sources for an effect like this: My question is: Do you know of any OpenGL extratrickery that will do this? Some kind of blending technique? Thanks for your help. I really do appreciate it.
Advertisement
perhaps i've misunderstood, but it seems you want a light map, which fakes lighting using textured quads ? in that case you would use multi-texturing to speed up the process. check this for more info.
- stormrunner
Well, i think that is on the right track, but if i understand what a lightmap is, it's something you apply to each and every quad you lay down, correct? What i'm looking for is more of an overlay for the whole scene. Here is a reduced version of my current collision physics testing facility:



If i "turned out the lights" so to speak, and lit a lamp, i want it to look like this (mockup):



I hope that was a little more clear
Well, really lightmapping isnt soemthing ive seen in 2d games... (think quake 3 arena) they used lightmapping, actually, most of the fps up till now used lightmaps. Anywho, your probably best off with some kind of circle texture with the kind of falloff you want, and scale it according to the brighntess of the light, and even color it if you want... and i believe if you do modulation... you should be fine... though the actual color math escapes me at the moment

hope that wasnt a waste of a post :-p
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Diablo 2 had it, if I'm not mistaken.

I don't know that simple blending will do the trick for you. Your best bet might be to generate the lightmap per-frame in a texture and use that with multiplicative blending.
If I understood you correctly, whis is what you need:

You first need to accumulate all the lighting in the buffer, and then do a final pass to multiply with the texture.

1)Render the background quad UNTEXTURED using an ambient color value, so even if an area is not lit by any local light, it doesn't look completely dark.
2)Enable additive blending(GL_ONE,GL_ONE);
3)Render all the fake lights.
4)Enable multiply blending(GL_DST_COLOR,GL_ZERO);
5)Render the textured background.

This topic is closed to new replies.

Advertisement