2d opengl lighting question

Member
Posts: 105
Joined: 2007.03
Post: #1
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Use a textured quad with a radial fall-off?
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #3
But how could that be practically implemented given my engine?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Draw it centered on the light source. Use the stencil buffer for shadows if you need 'em.
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #5
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).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
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.
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #7
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
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.
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #9
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
switch to additive blending, draw your lighting quad, switch back again.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Lighting and changing texture colors in OpenGL agreendev 2 7,787 Aug 13, 2010 03:47 PM
Last Post: agreendev
  2D Dynamic Lighting in OpenGL! Sort of... metacollin 22 18,246 Aug 19, 2009 01:48 AM
Last Post: Madrayken
  Lighting a sphere with OpenGL lights (normals wrong?) cecilkorik 3 8,196 Dec 27, 2007 02:40 PM
Last Post: _ibd_
  openGL polygon lighting honkFactory 2 3,761 Jan 3, 2003 02:33 PM
Last Post: henryj
  An OpenGL Question Justin Brimm 1 2,391 Dec 13, 2002 03:38 AM
Last Post: OneSadCookie