Jump to content
  • Advertisement
Sign in to follow this  
leiavoia

OpenGL How to do this 2D pseudo-lighting technique?

This topic is 5465 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!