Compiler2 min read

Debug Module

Debug colors, heatmaps, luminance, UV visualization, and bad-value highlighting.

Reading Time
2 min
Word Count
327
Sections
6
Try It Live

Turn the guide into code

Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.

Open Playground

Debug colors, heatmaps, luminance, UV visualization, and bad-value highlighting.

Import

bwsl
import Debug

This module imports: Math.

Constants

None.

Structs

No structs found.

Enums

No enums found.

Functions

debug_red

Returns the standard debug red color.

bwsl
debug_red :: () -> float3 { return float3(1.0, 0.0, 0.0); }

debug_green

Returns the standard debug green color.

bwsl
debug_green :: () -> float3 { return float3(0.0, 1.0, 0.0); }

debug_blue

Returns the standard debug blue color.

bwsl
debug_blue :: () -> float3 { return float3(0.0, 0.2, 1.0); }

debug_cyan

Returns the standard debug cyan color.

bwsl
debug_cyan :: () -> float3 { return float3(0.0, 1.0, 1.0); }

debug_yellow

Returns the standard debug yellow color.

bwsl
debug_yellow :: () -> float3 { return float3(1.0, 1.0, 0.0); }

debug_magenta

Returns the standard debug magenta color, commonly used here to mark NaN values.

bwsl
debug_magenta :: () -> float3 { return float3(1.0, 0.0, 1.0); }

debug_black

Returns black for checkerboards, masks, and low-end debug ramps.

bwsl
debug_black :: () -> float3 { return float3(0.0); }

debug_white

Returns white for checkerboards, masks, and high-end debug ramps.

bwsl
debug_white :: () -> float3 { return float3(1.0); }

luminance

Reference: https://en.wikipedia.org/wiki/Rec._709

bwsl
luminance :: (float3 color) -> float

normal_color

Maps a normal from signed [-1, 1] space into displayable [0, 1] RGB.

bwsl
normal_color :: (float3 n) -> float3

signed_color

Maps a signed vector from [-1, 1] into [0, 1] without normalizing it.

bwsl
signed_color :: (float3 value) -> float3

mask_color

Returns green for true and red for false, useful for visualizing predicates.

bwsl
mask_color :: (bool value) -> float3

is_bad

Reference: https://en.wikipedia.org/wiki/NaN

bwsl
is_bad :: (float value) -> bool

has_bad

Returns true when any component is NaN or infinite.

bwsl
has_bad :: (float2 value) -> bool

has_bad

Returns true when any component is NaN or infinite.

bwsl
has_bad :: (float3 value) -> bool

has_bad

Returns true when any component is NaN or infinite.

bwsl
has_bad :: (float4 value) -> bool

bad_value_color

Replaces a scalar's normal debug color with magenta for NaN or yellow for infinity.

bwsl
bad_value_color :: (float value, float3 okColor) -> float3

bad_value_color

Replaces a vector's normal debug color with magenta for NaN or yellow for infinity.

bwsl
bad_value_color :: (float3 value, float3 okColor) -> float3

heatmap

Useful for visualizing depth, roughness, overdraw, lighting cost, and scalar fields.

bwsl
heatmap :: (float value) -> float3

heatmap_range

Remaps a scalar range to [0, 1] and displays it with heatmap().

bwsl
heatmap_range :: (float value, float minValue, float maxValue) -> float3

depth_gray

Displays linear depth as grayscale between nearPlane and farPlane.

bwsl
depth_gray :: (float depth, float nearPlane, float farPlane) -> float3

depth_bands

Displays repeating colored depth bands for spotting precision and ordering issues.

bwsl
depth_bands :: (float depth, float bandCount) -> float3

checker

Creates a procedural black/white checkerboard in UV space.

bwsl
checker :: (float2 uv, float scale) -> float3

uv_color

Displays UV coordinates directly as red/green color channels.

bwsl
uv_color :: (float2 uv) -> float3

axis_color

Colors a direction by its dominant axis: X red, Y green, Z blue.

bwsl
axis_color :: (float3 direction) -> float3

overdraw_tint

Returns a heatmapped color with alpha proportional to count / maxCount.

bwsl
overdraw_tint :: (float count, float maxCount) -> float4

Source

Generated from compiler-reference/modules/Debug.bwsl.