11
\$\begingroup\$

I am in the process of writing an isometric game from scratch, and I'd like to know how/if I can add lights and shadows.

The code I have so far can be found here, but it should be enough to know that right now, the maps are simple 3d arrays of true/false values. Here is a shot of the environment: Screenshot of the multi-layer tilemap

If it were a single layer tilemap it would be straight forward. I can understand the simple raycasting in 2d that is required.

However, given that my maps have multiple levels of height as well as cave-like areas, I don't really know how to go about doing convincing shadows for it. Perhaps a per-block solution is the only realistic way?

\$\endgroup\$
5
  • \$\begingroup\$ Are you looking for pre-baked or dynamically generated lighting? Are the “cave-like areas” shown cut-away if the player walks in, or does light need to consider the ceiling too? Do you expect each tile to be binary lit/dark, or to have some sort of fractional value? \$\endgroup\$
    – Anko
    Aug 23, 2015 at 11:38
  • 1
    \$\begingroup\$ @Anko I would prefer something fractional, like 0 - 1.1 (for over-bright areas like explosions, etc), but it could be simply block-based, with no real interpolation or anything like that. I really want it to be dynamic, and support multiple lights. And while the "cave-like"/roofed areas will be shown cut away the algo would need to consider the blocks not being shown when calculating light. For example, if you walk in a house, the roof blocks will disappear, but it should still be shady inside. \$\endgroup\$ Aug 29, 2015 at 21:56
  • \$\begingroup\$ If you look for a solution like that with caves and height, it seem you have nothing of 2D. You are probably looking for a full 3D solution, even if the camera is always looking to a North-45ºdown direction. You should look at technics like stencil-shadow or similar. \$\endgroup\$ Oct 2, 2015 at 13:51
  • \$\begingroup\$ I second @AdrianMaire you'll need to do proper 3d calculations but make some shortcuts if there's no interpolation across the faces of a "tile". If you are not doing interpolation you could probably use rays. \$\endgroup\$ Oct 9, 2015 at 6:30
  • \$\begingroup\$ I don't have the mindspace right now to digest it into an answer, but I just stumbled on this blog post about line-of-sight determination for heightmap terrain. It sounds just like what you're looking for. \$\endgroup\$
    – Anko
    Dec 21, 2015 at 23:59

1 Answer 1

1
\$\begingroup\$

Can I recommend getting 2d shadows working first, even if it's just for the level that your avatar is currently on. It will be easier to start looking at the code that way and get it working.

I have implemented shadows in 2d tile maps in a couple of ways. One shadowcasting method which I found described by Eric Lippert at Microsoft works quite well.

And the other way, which I did myself first time i looked at this kind of thing was to orthogonally sweep the visible tiles and tile-edges and generate edges (and maybe corners iirc) describing the scene in the lowest number of edges. You can then cull hidden edges and form any custom shadowing features such as recessed shadows if you want to show a little bit of wall. Then create your shadow geometry (projective shadow casting ?) and render it over the top.

But if I try to take that idea to 3d, it just becomes easier to do it in 3d. While the method described by Eric Lippert could presumably be converted to 3d. But I think you'll find that doing it in 3d is expensive. Perhaps take a look at the source code for Brogue as well. It may have a more efficient implementation for 2d visibility/shadow casting.

Good luck.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .