I am currently working on an algorithm to calculate visibility in a 2D top-down level.
The level contains
- actors, with
position
and "sight" information - walls, with
start
&end
positions - light sources, with
position
andrange
I have written a fragment shader that renders my scene based on a texture I compose of the informations above.
- Red channel = line of sight for actors (in the example just the selected token is an actor)
- Green channel = light sources with their range and their respective line of sight
- Blue channel (not present in example) = night-vision of actors (means areas are shaded despite no light present)
I am using Babylonjs and am naively rendering all those calculations one after the other into a DynamicTexture using the canvas 2d context.
Can I use the GPU for some of these calculations (or all?) I am no expert for shader programming and don't know where to start / look.
The code for my line-of-sight calculation can be found here: https://gitlab.com/aiacta/visibility