iDevGames Forums
2d opengl lighting question - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: 2d opengl lighting question (/thread-3167.html)



2d opengl lighting question - Leroy - Jul 21, 2007 12:29 AM

I'm working on a 2d isometric tile engine in opengl (textured quads, ortho projection) and I'm trying to figure out the how do get decent lighting to work. Currently I just made my own light object with position and color values, and when I draw each textured quad i cycle through lights, check if the quad is within the lights radius, and apply needed color values.

My only real problem with this is that I don't get soft edges, and haven't yet thought of a feasible way to get them with this lighting method, have a look at what I mean http://web.mac.com/aleister55/iWeb/Site/Blank.html

Anyone have any ideas?


2d opengl lighting question - OneSadCookie - Jul 21, 2007 12:39 AM

Use a textured quad with a radial fall-off?


2d opengl lighting question - Leroy - Jul 21, 2007 12:46 AM

But how could that be practically implemented given my engine?


2d opengl lighting question - OneSadCookie - Jul 21, 2007 01:08 AM

Draw it centered on the light source. Use the stencil buffer for shadows if you need 'em.


2d opengl lighting question - Leroy - Jul 21, 2007 09:47 AM

I don't really understand what your saying exactly, could you please be a little more specific. Also, I'm not using opengl lighting, should I be(or is this what you've been reffering to)? So I think my question is more, how would I implement a per-pixel lighting model instead of per-tile light lighting model(which of course makes the lighting appear coarse across the staggered diamond tiles).


2d opengl lighting question - OneSadCookie - Jul 21, 2007 02:14 PM

No, you should not be using OpenGL lighting.

Without knowing what you don't understand, and what your constraints are, it's very difficult to be more specific. Please be more specific.


2d opengl lighting question - Leroy - Jul 21, 2007 03:28 PM

OneSadCookie Wrote:Without knowing what you don't understand, and what your constraints are, it's very difficult to be more specific. Please be more specific.

Sorry, I will try to be more specific.

Currently I am applying lighting(a single rgb color value per tile) to each tile (or textured quad) within the radius of that light. The problem with this is that I'm lighting the entire tile, and thus the "staggered" shapes of the tiles become apparent.

http://web.mac.com/aleister55/iWeb/Site/Blank.html

(even though it's not seen in the above pic, interpolating the light value with the distance from the center of the light to produce darker tiles farther from the center of the light radius still, produces the same "staggered" effect (it just makes it slightly more tolerable)and is not acceptable for my engine.

What I need is something like this(doesn't have to be as good, just the basic idea):
http://www.blizzard.co.kr/images/diablo2/sor-ss03.jpg

Hope I was clear enough, thanks.


2d opengl lighting question - OneSadCookie - Jul 21, 2007 03:43 PM

Your blizzard link is 403'ing...

Anyway, I think the textured quad thing is the way to go. Make a texture which is bright white in the center, and falls off radially to black on the outside. Enable additive blending (glBlendFunc(GL_ONE, GL_ONE)), and draw a textured quad with this texture, centered on the light's position, with a radius equal to the light's radius. Do this after drawing all the rest of the level normally.


2d opengl lighting question - Leroy - Jul 21, 2007 09:57 PM

OneSadCookie Wrote:. Make a texture which is bright white in the center, and falls off radially to black on the outside. Enable additive blending (glBlendFunc(GL_ONE, GL_ONE)), and draw a textured quad with this texture, centered on the light's position, with a radius equal to the light's radius. Do this after drawing all the rest of the level normally.

Currently I use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) because I need it to make the alpha mask on my sprites transparent. And when I call glBlendFunc(GL_ONE, GL_ONE) and then switch it back to the previous blend setting, it doesn't seem to do anything. Is it possible to do what you mentioned using alpha values and the blend setting that I'm already using?


2d opengl lighting question - OneSadCookie - Jul 21, 2007 11:41 PM

switch to additive blending, draw your lighting quad, switch back again.