You can support the development on the Github Sponsors page.


Tools > LIGHTIC


A cart for lights and shadows
made by TeamBean
uploaded by TeamBean
added:
updated:
download cartridge
- CLICK TO PLAY -

2


A cart that implements a few functions for a raytraced light rendering system all within a remap function that can be easily implemented and used. Supports directional lights and all parameters of a light can be changed at runtime.

Lil' Tutorial :

Step 1 - Setup
Find the variable named "SOLID_FLAG" and set it to the flag you use to identify solid tiles
Find the variable named "FLAG_SET" and set it to true if solid tiles have the flag set otherwise set it to false
Find tha variable named "BLANK_TILE" and set it to a blank tile that you have, alternatively if you want your darkness to have a texture you can set this var to the tile ID you want

Step 2 - Using LighTic
Find your map() call and then set the last input, the ninth input, to the function "light"

Done, that's it, you can now simply use map() and all tiles will be shown/hidden based on the various lights.

Now if you want to enable smooth ligthing there are a few more steps to do :
DISCLAIMER : Using smooth ligting currently comes at a very steep performance cost, I'm currently working on some optimizations

Find the variable named "SMOOTH_LIGHT" and set it to true
To use the smooth lighting youmust allocate some unsudet sprites to the function, to do that find the table called "FREE" and add as many sprite IDs as you want, it is recommended to use about 3 per different tile
And finally before calling the map function write "firstTile=true" one line before

Done! Now you have smooth ligthing.

How to add a light to the scene :
Just call NewLight().

The inputs are strength, angle, cone, x position, y position
Explanations :

strength : the max range of the light, anithing further won't be illuminated
angle : used for directional lights, it indicates the direction of the light
cone : The spred of the light, set it to 180° to make a circular light light
x position : the x position of the light
y position : the y position of the light

The function return a reference to a light wich gives you full access of all it's propreties, they are :

x : the x position
y : the y position
str : the strength of the light
isActive : if the light is on or not
ang : the angle of the light
cone : the spread of the light

A feature that can be useful are the new "light masks", basically a light for lghts.
They basically let tiles light up only if they're in their range and line of sight.

To instatiate a mask you call "NewMask", the inputs are the same as the ones for "NewLight".
Masks come at a little performance cost but in my tests it's only about 1-2ms for 1 mask

This cart also includes 5 helper functions :

rad2deg : helper function to convert radians to degrees
deg2rad : helper function to cenvert degrees to radians
raycast : given two positions casts a ray from the forst twards the second, returns false if the ray hits something on the way there, otherwise returns true
readSpr : given a sprite ID it return a table containing the pixels
saveSpr : given a table of pixels and an ID saves the pixels in the ID


Post comment