How to collide light with an entity?

Blitz3D Forums/Blitz3D Beginners Area/How to collide light with an entity?

Liimbix(Posted 2015) [#1]
Hi all, if you watch this video, you'll see that I place a torch, and then surround it with blocks, but the light still comes through. Is there a way to create a collision with a light and an entity? Or at least dim/remove the light after it hits an entity? Thanks :)


RemiD(Posted 2015) [#2]
If the goal is to build a world of cubes (minecraft-like) and you want to light only some cubes, i would code a custom lighting system which only calculate the lighting/shadowing of some cubes when needed (when a light changes position). If you calculate the lightin/shadowing only on some cubes around each light, maybe it will be fast enough.

For this i would use a 3 dimension array to store the cubes.
If you know the xyzposition of the light, you know in which cell the light is, and consequently you know which cells to light/shadow depending on hte range of the light and depending on if there are obstacles between the light and the target cube.

;for a zone of 100x100x100 cubes
;each cell has a position between 0x,0y,0z and 99x,99y,99z
Dim CellMesh(99,99,99)
Dim CellState(99,99,99)

;if you know the light position, let's say the light position is 20.5,1.5,15.5,
;you can then browse and update only on the cells around the light (and maybe also keep a list of the previously lighted cells so that you can set them to shadowed without having to loop through all cells)
;so in this case, let's say that the light range is 10
;you want to only browse and update the cells which have a position between 20-10,1-10,15-10 and 20+10,1+10,15+10
;This means you will analyze and update only 20*20*20=8000cells instead of 100*100*100=1000000cells


That's the basic idea...