Skip to content

Instantly share code, notes, and snippets.

@peterkcodes
peterkcodes / FastVoxelTraversal.cs
Last active May 7, 2025 13:59
Fast Voxel Traversal C# Implementation (made for Unity but works anywhere)
/// <summary>
/// From 'A Fast Voxel Traversal Algorithm for Ray Tracing'
/// by Amanatides and Woo
/// http://www.cse.yorku.ca/~amana/research/grid.pdf
/// </summary>
private static void Trace(Vector3 origin, Vector3 direction, float maxDistance)
{
//Initialization
int x = Mathf.FloorToInt(origin.x);
int y = Mathf.FloorToInt(origin.y);