2d Topdown field of vision effect

Godot Version

4.6.stable

Question

Hear me fellow button pressers, hear me o’ wise ones, bestow upon me your knowledge before my head implodes.

I am trying to achieve a 2d vision field effect on a topdown shooter (see images below) so that the player can not see things around walls.

I began simply with a light source on the players position and light occluders on the wall tiles of the tileset as well as setting the tilesets canvas item material’s light mode to light only so only areas the light touch are visible and achieved this effect:

this functions correctly except now all wall tiles are hidden by the occluders. I have tried many things and cant seem to figure anything out so have just put another tileset with just the walls over the top to get this:

this works pretty good but the intended effect was to hide everything in the shadow including other walls. something like this edited image:

If anyone has any ideas or input it would be greatly appreciated. :slight_smile:


I did the same thing you did and also used a field of view raycast to determine which tiles to overlay. Something like Godot-FOV-algorithms-roguelike/scenes/Raycasting.gd at main · aikoncwd/Godot-FOV-algorithms-roguelike · GitHub

At the time I found a few lengthy issues and/or proposals that went into detail about the lighting issues and other workarounds, but I did not save the links :frowning:

1 Like

You might be able to achieve the intended effect by setting the OccluderPolygon2D.cull_mode to ClockWise or CounterClockWise (depending on the polygons edge direction) of the wall occluder polygon.

See Occluders cast shadows on their own parent canvas items · Issue #105110 · godotengine/godot · GitHub.

2 Likes

i would imagine this would result in a very grid like look as the tiles would only either be fully visible or invisible, no partial shading. which would be fine for some games but not the look im going for in this case.

I have played around with the cull mode and found the following:

If you are using seperate occluders for different parts of the wall (each tile for example) then changing the cull mode causes some undesirable effects like seen in this image from the link you provided:

If the occluder is just one big shape that covers all of the walls, the cull mode does essentially nothing except allow the occluder itself to be shaded or not. Achieving the same effect as layering a seperate wall tilemap layer as seen in my 3rd image.

However I have found a solution I think is about as good as Ill be able to get in a 2d topdown game with my limited experience. If I make 2 occluder polygons, one for the inside of the wall and one for the outside of the wall, like:

and for my case set the inner occluder’s cull mode to clockwise i get this:

The inner occluder is casting shadows like before but not shading itself whilst the outer occluder is casting shadows that can shade within the inner occluder.

or honestly i might be trying to over complicate it and having only the outer occluder will suffice:

Oh, I thought we were talking about the occlusion layer on the tiles themselves.