Tilebased Light - kinda like Minecraft

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Immerse your quiz games with our 6 unique music loops, ranging from acoustic chill guitar to cute and upbeat style.
  • <font size="3">Tilebased Light - kinda like Minecraft</font>

    Hi everyone! Im new to the forum but not so new to Construct.

    Thanks for such a wonderful application! Free of Charge! <img src="smileys/smiley2.gif" border="0" align="middle">

    Im having a brain meltdown here, and this is my last resort.

    I have searched the web for this but I can only find C++ examples and Im no good at interpret that. I have also searched the forums here but I can't find any example which explains this.

    As the title say: Tilebased Light, how would you go about doing that?

    I have tried to add a light variable to every tile and depending on the distance to the light source it gets a certain light value. Then I used that value to set the color filter using the RGB expression. And that worked well. But with multiple lightsources when the lighted area is overlapping and should get a addative effect, I just can't work it out.

    I have also looked at the Bresenham Line algorithm, which some people suggested on the net, like this:

    Youtube Video

    But I can't figure it out... <img src="smileys/smiley9.gif" border="0" align="middle">

    So Im asking for help/directions/examples... <img src="smileys/smiley19.gif" border="0" align="middle">

    That would really get me going again. <img src="smileys/smiley4.gif" border="0" align="middle">

    /MJOne

  • How about less line, more radius?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Please explain :)

  • Light goes out in all directions, so its reasonable to assume that the distance between a tile, and a light source would be just like a radius of a circle.

    Given you know the xy of the light you can figure the adjacent tiles using cos, and sin. The formula would be lightx+cos(loop angle)*loop radius, and lighty+sin(loop angle)*loop radius, with two loops, loop angle, and loop radius.

    Since this is tiles you don't need all 360 degrees, 45 degree increments should suffice. Like wise your radius would increase by the length of your tiles.

    That will give you a circle around the light, to change that to an oval change your y offset radius to twice that of your x.

    Keep in mind the longer the radius the more degrees you will need.

  • aah I will try that newt. Thanks!

    But how would you do the blending with multiple lights that illuminates the same tile?

    If you also have a gradient drop in light strength in the color filter RGB channels. 255 to 0. White to black.

  • Nice example there, but that part I have figured out, what I can't figure out is how to blend the tiles when there are many light sources.

  • Not sure I would think you would add that particular tiles distance from the light to rgb.

  • I made an example based on Tokinson cap:

    http://dl.dropbox.com/u/7871870/construct/tile-light-01.cap

  • Nice example there, but that part I have figured out, what I can't figure out is how to blend the tiles when there are many light sources.

    Here ya go

    dl.dropbox.com/u/17634050/TileBasedLight1.cap

    Just needed to add one more condition!

    Also I recommend NOT using nuovofill or any pixel shaders for something like this; it can really slow your game down. You said something about color filters earlier, best just stick with that!

    edit: actually animmaniac's example might be what you're looking for..the lights 'combine' becoming a lot stronger, where as mine just 'blends' the lights.

  • Thanks a million! :)

    Thank you Animmaniac and Tokinsom, that's perfect! ;)

    But how would you stop it from render through 1x1 tile(32x32) walls?

    Like lights in a labyrinth...

    If you have alot of small solid objects scattered about...

    Thanks anyways! I will study this deeply! :)

    /MJOne

  • I took the challenge of adding occlusion to my example and came up with two different approaches: one uses raytrace and the other is similar to minecraft's method through propagation.

    http://dl.dropbox.com/u/7871870/construct/tile-light-raytrace-01.cap

    http://dl.dropbox.com/u/7871870/construct/tile-light-minecraft-01.cap

    They are not very fast, specially the raytrace that could be a little more optimized.

    The second method propagates the light every frame like if "calculating on the fly", so it doesn't look very good for moving lights. I tried to make it update instantaneously but it became to slow. I recommend using it for static illumination mainly.

    Actually both can work better for static lights. They can be executed just once at the start of a layout (during a loading screen for example) just to set the illumination resulting in a better performance.

  • I recently made something very similar to this for my game, except I only made it calculate the light when you change tile. Which helps keep the framerate higher.

  • Woah! You guys are amazing! :)

    Im really moved by how fast I got help on this forum.

    Thanks a thousand times!

    Is it okey with you Animmaniac if I use this method in my game/s?

    I will study these two examples as well, see what I can learn!

    Thanks!

    /MJOne

  • Woah! Is it okey with you Animmaniac if I use this method in my game/s?Yes it's ok, you can use it freely. If you came up with an optimized solution I would be happy if you share it here on the forums.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)