Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Visibility Polygon

An asset by kratocz
The page banner background of a mountain and forest
Visibility Polygon hero image

Quick Information

0 ratings
Visibility Polygon icon image
kratocz
Visibility Polygon

A dependency-free 2D visibility polygon (isovist) for Godot 4: computes the region an observer can see over a set of line segments, using a correct O(N log N) active-edge sweep that does not leak sight around corners. Useful for fog of war, 2D lighting/shadows, stealth line-of-sight, and visibility analysis. Includes an interactive demo scene. Algorithm ported from byronknoll/visibility-polygon-js (public domain).

Supported Engine Version
4.0
Version String
1.0.0
License Version
CC0
Support Level
community
Modified Date
7 hours ago
Git URL
Issue URL

Godot Visibility Polygon

A small, dependency-free Godot 4 addon that computes a 2D visibility polygon (isovist) from an observer over a set of line segments — the region visible from a point, given walls that block sight. Useful for fog of war, 2D lighting/shadows, stealth line-of-sight, and visibility analysis.

README Visibility polygon demo: the lit area is what the red observer can see; the walls cast crisp shadows behind them.

The lit (yellow) area is everything the red observer can see; each wall casts a crisp shadow behind it. In the demo scene the observer follows your mouse.

It uses a correct O(N log N) active-edge rotational sweep (a binary heap of segments ordered by distance from the observer, emitting a polygon vertex only when the nearest segment changes). Unlike a naive "cast a ray at every endpoint and connect the nearest hits by angle" sweep, it never lets a polygon edge cut across a wall — so it does not leak sight around corners into the next room.

The algorithm is a hand-port of byronknoll/visibility-polygon-js (public domain). Released under CC0 1.0 — do whatever you like with it, no attribution required (a star is appreciated).

Try it

Open this project in Godot 4.6+ and press Play — the demo scene draws the visibility polygon from your mouse over a few walls.

Install into your project

Copy the addons/visibility_polygon/ directory into your own project. The library is a plain script — use it immediately via preload:

const VisibilityPolygon = preload("res://addons/visibility_polygon/visibility_polygon.gd")

var walls := [
    [Vector2(0, 0), Vector2(100, 0)],
    [Vector2(100, 0), Vector2(100, 100)],
    [Vector2(100, 100), Vector2(0, 100)],
    [Vector2(0, 100), Vector2(0, 0)],
]
var poly: PackedVector2Array = VisibilityPolygon.compute(Vector2(50, 50), walls)

Full API & docs

See addons/visibility_polygon/README.md for the complete API (compute, compute_viewport, point_in_polygon, fan_indices, convert_to_segments, break_intersections), usage notes, and the segment-input convention.

License

CC0 1.0 Universal (public domain dedication) — see addons/visibility_polygon/LICENSE. Algorithm ported from byronknoll/visibility-polygon-js (public domain).

A dependency-free 2D visibility polygon (isovist) for Godot 4: computes the region an observer can see over a set of line segments, using a correct O(N log N) active-edge sweep that does not leak sight around corners. Useful for fog of war, 2D lighting/shadows, stealth line-of-sight, and visibility analysis. Includes an interactive demo scene. Algorithm ported from byronknoll/visibility-polygon-js (public domain).

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Visibility Polygon icon image
kratocz
Visibility Polygon

A dependency-free 2D visibility polygon (isovist) for Godot 4: computes the region an observer can see over a set of line segments, using a correct O(N log N) active-edge sweep that does not leak sight around corners. Useful for fog of war, 2D lighting/shadows, stealth line-of-sight, and visibility analysis. Includes an interactive demo scene. Algorithm ported from byronknoll/visibility-polygon-js (public domain).

Supported Engine Version
4.0
Version String
1.0.0
License Version
CC0
Support Level
community
Modified Date
7 hours ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers