2D lighting/shadowing demo

Sage
Posts: 1,482
Joined: 2002.09
Post: #1
Just coded up a simple 2D lighting/shadowing demo. Pretty cool for the first bit of real openGL code I've done. Much like the lighting in Gish, if you've played that. I can put up the code if anyone wants it.

lighting demo
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #2
Code, please. Grin
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
trouble in lighty town, otherwise, nice little demo
[Image: troubleinlightytown.jpg]
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
skyhawk Wrote:trouble in lighty town, otherwise, nice little demo

It uses homogenous coordinates to project the shadows. So if you put the light directly on the line then all of the vertices of the shadow polygon are in the same line, and two them are at infinity. OpenGL craps out then when it tries to draw the poly. (for obvious reasons) Needless to say, that's not exactly something that you should have to worry about in normal use.

Essentially it just takes the line segments that outline the area and project them off to infinity. Each light is stenciled separately and a texture is used to create the falloff.

Xcode project
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
Hmm... looks like you read this article.

btw, what exactly are you doing that makes it possible to create an app without a Quit menu?
Quote this message in a reply
Moderator
Posts: 700
Joined: 2002.04
Post: #6
Quote:btw, what exactly are you doing that makes it possible to create an app without a Quit menu?
From a quick look inside Skorche's app bundle - that's a bug in SDL.

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
arekkusu Wrote:Hmm... looks like you read this article.

btw, what exactly are you doing that makes it possible to create an app without a Quit menu?

Actually no, I just came up with it myself. But I'll have to check out how they do the soft shadows.

Yeah, it's just a simple SDL app that doesn't really deal with events. For anyone who hasn't figured it out, just click to exit. (or force quit Rolleyes )
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
Interesting read, a couple of differences I noticed though:

1) They use the alpha in the framebuffer instead of the stencil buffer. Is this faster? I certainly seems easier.

2) Also, in the article, they just say to extend the shadow to a certain multiple of the distance from the light to a vertex. I just put 0 in for the w coordinate.

3) Obvious optimization to use triangle strips instead of individual quads. Didn't even occur to me.

I'll have to try fiddling around with the soft shadows once I get my BSP stuff going. That's pretty slick. (significantly more difficult though) I was actually hoping that they had some sort of trick to make it simpler without having to muck about with each vertex.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenCL deferred lighting demo Holmes 9 12,353 Feb 22, 2011 07:53 PM
Last Post: Holmes
  iPhone 3GS Shadowing Bug Bersaelor 6 10,600 Dec 28, 2010 04:08 PM
Last Post: jarodl
  Shadowing bug TomorrowPlusX 6 4,971 Feb 1, 2010 12:00 PM
Last Post: DoG
  Shadow Mapping - Self-Shadowing Z-Fighting Artifacts Bachus 16 22,063 Feb 11, 2009 12:24 PM
Last Post: arekkusu
  Static Shadowing with shadow maps NYGhost 1 3,773 Jun 28, 2003 06:21 PM
Last Post: Feanor