Live data from Hacker News

How to create 2D visibility/shadow effects for your game

ncase.github.io

11–20 of 47 posts

Re: How to create 2D visibility/shadow effects for your game

#11

Earlier quoted context omitted.

I'm downvoting your comment because on technical posts the top rated comment is damn near always of zero value and only serves to make the commenter try to sound smarter than the post author. The more in-depth and complicated the post the more those type of comments appear. This is a nice little post that reasonably describes a technique that has been used by a fair number of professional, commercial products. That a…

You didn't read very carefully if you missed that everything was interactive. "Today, I will show you how to make something like this: (move your mouse around in the box below)" "The demo below just draws a bunch of line segments and tracks your mouse position." "Here's what all that math looks like: (move your mouse over the box)"

You are correct. I did not read very carefully. Thank you for pointing that out. I focused on the pretty pictures before reading all of the text. I can say with extreme confidence that I am not the only person who made the mistake of not reading carefully so I thought it worthwhile to mention.

Re: How to create 2D visibility/shadow effects for your game

#12
post #5

He uses a nice trick to approximate the real thing, however this algorithm wouldn't be able to deal with curved objects.

I'm downvoting your comment because on technical posts the top rated comment is damn near always of zero value and only serves to make the commenter try to sound smarter than the post author. The more in-depth and complicated the post the more those type of comments appear. This is a nice little post that reasonably describes a technique that has been used by a fair number of professional, commercial products. That a…

> That anyone would try to downplay it to make themselves feel superior is silly.

Why would you think that was my goal? Did i say the author was stupid or didn't pay attention? I simply pointed out a limitation that might not be obvious to others at first sight and which wasn't discussed in the article itself, thus also providing for others an easy starting point to improve on the algorithm as presented.

Heck, in the circles* i run the first part of my comment is even praise. Figuring out ways to approximate "real" results so they can be done in realtime is not easy.

*Have an example of EXTREMELY competent faking from those circles: https://www.youtube.com/watch?v=MJfceF0syK8

Re: How to create 2D visibility/shadow effects for your game

#13

Earlier quoted context omitted.

I'm downvoting your comment because on technical posts the top rated comment is damn near always of zero value and only serves to make the commenter try to sound smarter than the post author. The more in-depth and complicated the post the more those type of comments appear. This is a nice little post that reasonably describes a technique that has been used by a fair number of professional, commercial products. That a…

You didn't read very carefully if you missed that everything was interactive. "Today, I will show you how to make something like this: (move your mouse around in the box below)" "The demo below just draws a bunch of line segments and tracks your mouse position." "Here's what all that math looks like: (move your mouse over the box)"

Some of us only skim articles.

It's not a sin.

Re: How to create 2D visibility/shadow effects for your game

#14
post #6
post #5

He uses a nice trick to approximate the real thing, however this algorithm wouldn't be able to deal with curved objects.

You can simply shoot some rays tangent to each curve in addition to the endpoints/vertices.

I'm not too strong with trig. Would this also work with curves that have more than one bump? (sine, etc.)

Re: How to create 2D visibility/shadow effects for your game

#15
I have an open source XNA/MonoGame implementation of a similar lighting technique available here:

https://github.com/sq/Illuminant

It's hardware-accelerated and has a few other useful features; we're using it in Escape Goat 2 and it works on Windows/Linux/Mac on pretty much any D3D9-spec hardware. You can see some of the levels using it here: https://www.youtube.com/watch?v=-9s1PyotS18#t=1m20s

For EG2 we have a pair of separate lighting environments; one for the foreground plane and one for the background plane. Most light sources exist on both planes but have different parameters in order to create a depth effect; some light sources are only on the background plane. We apply a customized ramp texture to the light sources in order to replace the smooth attenuation with quantized attenuation, and we don't use soft shadows (though we do render lighting at a lower resolution and upscale it, because that softens things a little.) We also do a simple HDR camera model by sampling lighting intensity across the scene's foreground/background planes and using that to adjust the range of the final lightmap so that we can automatically tune exposure/white point etc to highlight certain parts of a level.

I also have a similar pure-software-rendering lighting library from around ~8 years ago available here, in C++:

https://github.com/kg/Fury2/blob/master/libraries/SoftFX/mod...

That one's garbage, but may still be of some use.

I'll note that the author's approach (needing extra intersection points at +- 0.00001 radian) is a little perplexing. I'm not sure why that is needed; I've never needed it.

A better approach for 'fuzzy' shadows is to model the penumbra; you can render it as a single triangle that borders on the actual shadow umbra and then make it smooth by using a simple lookup texture. This technique is described here:

http://archive.gamedev.net/archive/reference/programming/fea...

Another great option for 2D lighting is to associate normal maps with your sprites and do per-pixel lighting against each light source using the normal map. This can produce some really great results. I think that SpriteLamp, http://snakehillgames.com/spritelamp/ does this; the Fury2 library I linked above also did per-pixel sprite lighting with normal maps. The upcoming game Full Bore (http://www.wholehog-games.com/fullbore/) is using per-pixel lighting on its sprites and environment art, and I believe Spelunky for PC/XBLA uses it on environment art.

Re: How to create 2D visibility/shadow effects for your game

#17
post #6

Earlier quoted context omitted.

You can simply shoot some rays tangent to each curve in addition to the endpoints/vertices.

I'm not too strong with trig. Would this also work with curves that have more than one bump? (sine, etc.)

Yes, with calculus you can find all the tangent lines from a point to any kind of curve. The exact equations vary based on what kind of curve it is (sine, parabola, cubic splines, Bezier curves, non-uniform rational B-splines, etc) and are kinda complicated.

Re: How to create 2D visibility/shadow effects for your game

#18
post #17

Earlier quoted context omitted.

I'm not too strong with trig. Would this also work with curves that have more than one bump? (sine, etc.)

Yes, with calculus you can find all the tangent lines from a point to any kind of curve. The exact equations vary based on what kind of curve it is (sine, parabola, cubic splines, Bezier curves, non-uniform rational B-splines, etc) and are kinda complicated.

Hm, then it becomes a question of whether that can be ran fast enough and remain realtime. :)

Re: How to create 2D visibility/shadow effects for your game

#19

Earlier quoted context omitted.

You didn't read very carefully if you missed that everything was interactive. "Today, I will show you how to make something like this: (move your mouse around in the box below)" "The demo below just draws a bunch of line segments and tracks your mouse position." "Here's what all that math looks like: (move your mouse over the box)"

Some of us only skim articles. It's not a sin.

Agreed. But given the rest of forrestthewoods's post I thought it was worth pointing out.

Re: How to create 2D visibility/shadow effects for your game

#20
post #10

You, sir, must be from the future, what with the uncopyrighted, bitcoin-based crowdfunding campaign. Backing this effort is a no-brainer. https://back.nothingtohide.cc/

A lovely game idea too. Wonderful commentary on surveillance states.
Post reply on HN