clintbellanger / flare

Free Libre Action Roleplaying Engine
http://clintbellanger.net/rpg/
GNU General Public License v3.0
166 stars 41 forks source link

"Atmo", "Lighting", or "foreground" layer #895

Closed makrohn closed 11 years ago

makrohn commented 11 years ago

This is another possibly useful layer, especially now that we have alpha rendering. This could be solid with just a single tile repeating itself, such as a dusk effect, which is just a semi-transparent tile laid out over the entire map. It could be a repeating "hazy" tile for a "heat " effect. If it were underground or nighttime, holes coule be poked in the layer for "light sources". Even animated tiles could be used for a "rain" effect. This could give us a very easy way of providing environmental effects.

I don't think it'd be too hard for me to figure out how to do, so I'd be happy to take it on if other people think it'd be useful. My major concern is that I don't know how much impact each additional map layer has on memory useage, or if it's even relevant to screen size, number of tiles used, etc.

igorko commented 11 years ago

Maybe this would be better to do using opengl, in future. Or wait for SDL 2.0. Some people say alpha blending is much faster in v2.0.

clintbellanger commented 11 years ago

Feel free to try this in a branch, but I'm skeptical that we'll get a good enough look and performance with our current system.

One challenge is that laying tiles over everything looks funny for tall tiles. We'd expect a vertical area of wall to have roughly the same lighting as the floor it's on.

There are low level techniques to do lighting (as we see in games like Diablo I/II, Nox, etc) but we're not really coding on that low level (using SDL for all our abstraction). I'm not sure adding low level stuff like that is beneficial.

Great lighting can be done with OpenGL and using normal maps for every tile, but at that point we might as well be making a 3D game.

Of course, tile sets could be cleverly built to have sort of "baked" lighting on them. That would mean no dynamic lights, but it can have some pretty effects.

makrohn commented 11 years ago

This would almost certainly not involve any sort of dynamic lighting - think of it more as just a mask. A vertical area of the wall would achieve the same lighting as the floor it's on simply by punching a wall-shaped hole in the atmosphere mask.

makrohn commented 11 years ago

Also, if we decide not to go this route, I could always just copy and mask the tileset.png itself for tilesetdusk.png, but it'd prevent the goal of having variation in those masks occasionally.

makrohn commented 11 years ago

Crude demo: I added the the Foreground layer in MapRenderer.*, then added a foreground tile layer in frontier_outpost.tmx, and just filled in the entire thing with a dark, partially alpha'd tile. Export! Boom! Night comes to the Frontier Outpost. Where I've erased the dark tile, there is a "light" spot - where one could put a torch or something else that makes sense. I also did some half-alpha'd tiles to show how one could make some (more or less) even contours instead of the jagged tile-based breaklines.

Code: https://github.com/makrohn/flare/commit/c3a72a72a962adfacfabf284a6a1cd89aa671112 Screenshot: https://raw.github.com/makrohn/flare/c3a72a72a962adfacfabf284a6a1cd89aa671112/Screenshot.png

Instead of a dark tile, it could be anything!

igorko commented 11 years ago

Interesting. We can draw or not draw foreground layer depending on daytime counter. But to change night to morning dynamically, (which would be awesome) it's not enough.

igorko commented 11 years ago

Ideas. To change night to morning we can use mapmod. To use rain in foreground layer we can use current environment sound effect as it's done with braziers.

clintbellanger commented 11 years ago

It's something that looks good in that example screenshot, but that's a very primitive case. Having it look great with various lit areas just using tiles would be quite challenging.

makrohn commented 11 years ago

I know you just posted on the FLARE blog about simplifying the engine, so I mean it when I ask, is it worth coding it in now, even if the artwork isn't developed yet? It should just be a matter of developing the tiles for it. I know in the simpler orthographic rendering, using LPC assets, I already have some artwork to take advantage of this feature.

If everyone would rather put it off, for technical or artistic reasons, I am more than willing to forego implementation in Polymorphable in order to retain shared code base with FLARE - or maybe even going halfsies and only coding in for othographic but not isometric (though it would seem weird to me not to give both projections the full functionality that the other would have).

clintbellanger commented 11 years ago

I'm not ruling it out.

I don't mind having a generic foreground layer that is always drawn above all objects. There are neat tricks that can be done with such a layer, similar to the flexibility that a fringe layer gives.

So, many games implement a kind of lighting by having a "dark" layer on top of everything and slicing out what should be lit up. Usually though, this is a pixel layer instead of using static tiles. Painting onto a shadow layer is a bit lower level than I care to get.

In the case of a night map, it could be done far better with a night version of a tile set. Night time isn't just darker, the actual colors should change (less yellow, more blue).

Anyway: if this can be done with a foreground layer, then a generic foreground layer is probably a decent addition.

[edit] side thought, we can probably have booleans for at least the fringe and foreground layers that say whether they were specified in this map. Then we can skip the render function/loop entirely for that layer.

igorko commented 11 years ago

This layer can be fine for "Atmo", but "Lighting" will not work (or will be terrible). Lighting requires dynamic: moving light from tile to tile, light for large distance with decreasing light power, connecting light to avatar.