2
$\begingroup$

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 and range

I have written a fragment shader that renders my scene based on a texture I compose of the informations above.

basic line of sight calculation

Left side: my level rendered, right side: the actual texture that is fed to the shader

  • 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

$\endgroup$
0
$\begingroup$

In this SIGGRAPH paper is described a similar operation for the visibility calculation from every pixel in the domain (you only need calculate it from actors position), which has been implemented in GPU.

Although it is oriented to fluid dynamics, it may be a starting point to look.

You can see other related shader examples like this one with implicit geometry.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.