Page 1 of 1

Rogue-like shadow casting

Posted: Sun Jan 09, 2011 11:02 pm
by Chief
Could someone explain to me how one would go about doing shadow casting in a rogue-like grid-based game?

example:
Image

I've managed to recreate the effect with a trace function, where it traces from the light source and goes around 360 and scans for tiles to light up. Which is very inefficient. :cry:

Any ideas? (code examples would be nice :crazy:)

PS. couldn't find any older threads about this.

Re: Rogue-like shadow casting

Posted: Sun Jan 09, 2011 11:28 pm
by subrime
A fast way to do this is to make an array indexed by the relative position between the light source and the wall cell.

Each array entry contains a shadow mask that shows which cells are in the shadow of the wall celll.

This array only needs to be made once at game startup.

A light map is made by scanning the lit area for wall cells and combining the shadow masks with the current light map.

The number of array entries can be reduced by a factor of 8 by using symmetry considerations.

My only code for this is in c, but would be even easier to implement in lua.

Re: Rogue-like shadow casting

Posted: Mon Jan 10, 2011 5:02 am
by ghostwriter
Mmm well I implemented the method described in this paper a couple years ago with nice results, but until LÖVE gets shader support it probably wouldn't be appropriate to implement it this way.

Re: Rogue-like shadow casting

Posted: Mon Jan 10, 2011 6:59 am
by TechnoCat