From 842f985c23ab19ba5622c32f3a0ff2f8505d6c6d Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Thu, 28 Sep 2023 17:46:22 -0400 Subject: [PATCH] Document `grid_lines` function --- hello-world/assets/shaders/procedural_grid.wgsl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hello-world/assets/shaders/procedural_grid.wgsl b/hello-world/assets/shaders/procedural_grid.wgsl index df776b3..ed4763d 100644 --- a/hello-world/assets/shaders/procedural_grid.wgsl +++ b/hello-world/assets/shaders/procedural_grid.wgsl @@ -12,6 +12,18 @@ fn inv_lerp(a: f32, b: f32, v: f32) -> f32 { return (v - a) / (b - a); } +/// Draw grid-lines at a given scale and camera depth. +/// +/// @param pos The reference coordinates for the grid lines. +/// @param depth Distance of the camera from the fragment being shaded. +/// @param scale +/// `pos` will be multiplied by this value before computing the color value. +/// E.g., a scale of 10 will draw 10 lines for each whole-number increment +/// on the X and Z axes of `pos`. +/// @param depth_min, depth_max +/// Controls the opacity of the grid lines relative to the camera depth. +/// These will be mapped to 0-1 and multiplied by the color value to produce +/// the final output. fn grid_lines(pos: vec4, depth: f32, scale: f32, depth_min: f32, depth_max: f32) -> f32 { let ref_coords = abs(pos) * scale;