Advanced search tips: use spaces to require multiple terms (AND), | for alternatives (OR), wrap phrases in quotes (="a b"), =term for exact match, 'term to include, !term to exclude, ^term to match prefix, !^term to exclude prefix, .ext$ to match suffix, and !.ext$ to exclude suffix.

common.wgsl

Import path

Constants

CASCADE_COUNT

#
const CASCADE_COUNT: u32 = 6u

VERTEX_SNAP_MULTIPLIER

#
const VERTEX_SNAP_MULTIPLIER: f32 = 2.0

COARSE_GRID_MULTIPLIER

#
const COARSE_GRID_MULTIPLIER: f32 = 4.0

LOD_TRANSITION_START

#
const LOD_TRANSITION_START: f32 = 1.0

MORPH_BLACK_POINT

#
const MORPH_BLACK_POINT: f32 = 0.05

MORPH_FADE_SIDES

#
const MORPH_FADE_SIDES: f32 = 2.0

MORPH_INNER_RADIUS

#
const MORPH_INNER_RADIUS: f32 = 0.375

GRID_CELL_CENTER

#
const GRID_CELL_CENTER: f32 = 0.5

UV_CENTER

#
const UV_CENTER: f32 = 0.5

MIN_SAMPLE_WEIGHT

#
const MIN_SAMPLE_WEIGHT: f32 = 0.001

MIN_NORMAL_Y

#
const MIN_NORMAL_Y: f32 = 0.0001

SAFE_LENGTH_SQUARED

#
const SAFE_LENGTH_SQUARED: f32 = 1e-8

LUMINANCE_EPSILON

#
const LUMINANCE_EPSILON: f32 = 0.0001

DEBUG_MODE_WATER_PATH

#
const DEBUG_MODE_WATER_PATH: u32 = 1u

DEBUG_MODE_REFRACTION_VALIDITY

#
const DEBUG_MODE_REFRACTION_VALIDITY: u32 = 2u

DEBUG_MODE_TRANSMISSION

#
const DEBUG_MODE_TRANSMISSION: u32 = 3u

DEBUG_MODE_UNREFRACTED

#
const DEBUG_MODE_UNREFRACTED: u32 = 4u

DEBUG_MODE_BEER_LAMBERT

#
const DEBUG_MODE_BEER_LAMBERT: u32 = 5u

DEBUG_MODE_SEA_FLOOR

#
const DEBUG_MODE_SEA_FLOOR: u32 = 6u

DEBUG_MODE_BEAUTY

#
const DEBUG_MODE_BEAUTY: u32 = 7u

DEBUG_MODE_REFLECTION

#
const DEBUG_MODE_REFLECTION: u32 = 8u

DEBUG_MODE_FOAM

#
const DEBUG_MODE_FOAM: u32 = 9u

DEBUG_MODE_WAVE_HEIGHT

#
const DEBUG_MODE_WAVE_HEIGHT: u32 = 10u

DEBUG_MODE_LIGHT_RADIANCE

#
const DEBUG_MODE_LIGHT_RADIANCE: u32 = 11u

DEBUG_MODE_REFLECTION_FRACTION

#
const DEBUG_MODE_REFLECTION_FRACTION: u32 = 12u

DEBUG_MODE_FAR_TIER

#
const DEBUG_MODE_FAR_TIER: u32 = 13u

CREST_SSS_MAXIMUM

#
const CREST_SSS_MAXIMUM: f32 = 0.6

CREST_SSS_RANGE

#
const CREST_SSS_RANGE: f32 = 0.12

CREST_SSS_UNCOMPRESSED

#
const CREST_SSS_UNCOMPRESSED: f32 = CREST_SSS_MAXIMUM - CREST_SSS_RANGE

PLANAR_PROJECTION_GUARD

#
const PLANAR_PROJECTION_GUARD: f32 = 0.03

MAX_BODIES

#
const MAX_BODIES: u32 = 16u

Bindings

lod_data

#
@group(#{MATERIAL_BIND_GROUP})
@binding(0)
var lod_data: texture_2d_array<f32>

lod_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(1)
var lod_sampler: sampler

cascade_layout

#
@group(#{MATERIAL_BIND_GROUP})
@binding(2)
var<uniform> cascade_layout: CascadeLayout

surface

#
@group(#{MATERIAL_BIND_GROUP})
@binding(3)
var<uniform> surface: SurfaceParams

bed_height

#
@group(#{MATERIAL_BIND_GROUP})
@binding(4)
var bed_height: texture_2d<f32>

detail_normal

#
@group(#{MATERIAL_BIND_GROUP})
@binding(5)
var detail_normal: texture_2d<f32>

detail_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(6)
var detail_sampler: sampler

foam_data

#
@group(#{MATERIAL_BIND_GROUP})
@binding(7)
var foam_data: texture_2d_array<f32>

foam_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(8)
var foam_sampler: sampler

foam_pattern

#
@group(#{MATERIAL_BIND_GROUP})
@binding(9)
var foam_pattern: texture_2d<f32>

foam_pattern_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(10)
var foam_pattern_sampler: sampler

fft_surface

#
@group(#{MATERIAL_BIND_GROUP})
@binding(11)
var fft_surface: texture_2d_array<f32>

field_params

#
@group(#{MATERIAL_BIND_GROUP})
@binding(15)
var<uniform> field_params: FieldParams

field_maps

#
@group(#{MATERIAL_BIND_GROUP})
@binding(16)
var field_maps: texture_2d_array<f32>

field_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(17)
var field_sampler: sampler

reflection_a

#
@group(#{MATERIAL_BIND_GROUP})
@binding(19)
var reflection_a: texture_2d<f32>

reflection_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(20)
var reflection_sampler: sampler

reflection_b

#
@group(#{MATERIAL_BIND_GROUP})
@binding(21)
var reflection_b: texture_2d<f32>

planar_reflections

#
@group(#{MATERIAL_BIND_GROUP})
@binding(22)
var<uniform> planar_reflections: PlanarReflectionParams

caustics_texture

#
@group(#{MATERIAL_BIND_GROUP})
@binding(23)
var caustics_texture: texture_2d<f32>

caustics_sampler

#
@group(#{MATERIAL_BIND_GROUP})
@binding(24)
var caustics_sampler: sampler

Structures

CascadeParams

#
struct CascadeParams {
center: vec2<f32> ,
scale: f32 ,
texture_res: f32 ,
inv_texture_res: f32 ,
texel_width: f32 ,
weight: f32 ,
max_wavelength: f32 ,
}

CascadeLayout

#
struct CascadeLayout {
center: vec4<f32> ,
bed_transform: vec4<f32> ,
bed_range: vec4<f32> ,
}

PlanarReflectionView

#
struct PlanarReflectionView {
view_projection: mat4x4<f32> ,
level: f32 ,
}

PlanarReflectionParams

#
struct PlanarReflectionParams {
view_count: u32 ,
distortion: f32 ,
}

PlanarReflectionSample

#
struct PlanarReflectionSample {
color: vec3<f32> ,
weight: f32 ,
}

SurfaceParams

#
struct SurfaceParams {
deep_color: vec4<f32> ,
grazing_color: vec4<f32> ,
shallow_color: vec4<f32> ,
fresnel: vec4<f32> ,
reflection: vec4<f32> ,
debug: vec4<f32> ,
fog_density: vec4<f32> ,
sea_floor: vec4<f32> ,
sss_tint: vec4<f32> ,
detail: vec4<f32> ,
capillary: vec4<f32> ,
foam: vec4<f32> ,
advection: vec4<f32> ,
far_tier: vec4<f32> ,
caustics: vec4<f32> ,
}

BodyParams

#

Localized-water extent controls; mirrors lod::BodyParams. flags.x is 1.0 for bounded bodies: the vertex stage skips camera snap/morph and the fragment stage culls against extent.xy (centre) and extent.w (radius).

struct BodyParams {
flags: vec4<f32> ,
extent: vec4<f32> ,
aabb_min: vec4<f32> ,
aabb_size: vec4<f32> ,
optics_a: vec4<f32> ,
optics_b: vec4<f32> ,
}

FieldParams

#
struct FieldParams { }

LocalLightSample

#
struct LocalLightSample {
direction: vec3<f32> ,
radiance: vec3<f32> ,
}

RiverState

#

One snapshot of this invocation’s river state, handed to imported modules that cannot read this file’s private globals directly.

struct RiverState {
enabled: bool ,
sample: vec4<f32> ,
flow: vec2<f32> ,
}

Functions

sample_planar_reflection

#
fn sample_planar_reflection (
world_position: vec3<f32>
surface_level: f32
surface_normal: vec3<f32>
) -> PlanarReflectionSample

set_xz_footprint

#
fn set_xz_footprint (
value: f32
)

screen_xz_footprint

#
fn screen_xz_footprint ()

screen_texture_lod

#

Analytic texture LOD: dUV/dpixel is the world-XZ footprint divided by metres per UV repeat, and mip LOD is log2(texels covered per pixel).

fn screen_texture_lod (
metres_per_repeat: f32
texture_width: u32
) -> f32

begin_invocation

#

Stage entry: records the owning body slot’s parameters.

fn begin_invocation (
bounded: bool
)

set_effective_flow

#

Stage entry: selects the advection current for wave-content sampling.

fn set_effective_flow ( )

set_effective_time

#
fn set_effective_time (
time: f32
)

set_fragment_river

#

Fragment entry: records the baked river-flow sample under the fragment.

fn set_fragment_river ( )

set_body_optics

#

Fragment entry: records the effective Beer-Lambert extinction and the scatter-endpoint scale after fresh-water optics override.

fn set_body_optics (
extinction: vec3<f32>
scatter_scale: f32
)

set_river_ripple

#

Fragment entry: records the river ripple-strength multiplier.

fn set_river_ripple (
scale: f32
)

invocation_extinction

#
fn invocation_extinction ()

invocation_scatter_scale

#
fn invocation_scatter_scale ()

invocation_river_state

#
fn invocation_river_state ()

invocation_ripple

#
fn invocation_ripple ()

advected_world

#
fn advected_world (
world_xz: vec2<f32>
) -> vec2<f32>

field_uv

#

Samples the baked river field; returns zero flow and a huge bank margin when this material has no flow texture.

fn field_uv (
world_xz: vec2<f32>
) -> vec2<f32>

sample_field_level

#

rg: surface level, one-based body slot (0 = unclaimed).

fn sample_field_level (
world_xz: vec2<f32>
) -> vec2<f32>

sample_field_flow

#

rgb: flow m/s; z: signed bank margin in metres; w: speed m/s.

fn sample_field_flow (
world_xz: vec2<f32>
) -> vec4<f32>

owning_body

#

Parameters of the body owning a point; slot 0 falls back to the inactive ocean defaults so unguarded reads stay harmless.

fn owning_body (
slot: u32
) -> BodyParams

lod_count

#
fn lod_count ()

smootherstep01

#
fn smootherstep01 (
value: f32
) -> f32

far_tier_weight

#
fn far_tier_weight (
base_world_position: vec3<f32>
) -> f32

lod_alpha

#
fn lod_alpha (
world_xz: vec2<f32>
) -> f32

snap_and_transition

#
fn snap_and_transition (
world_xz: vec2<f32>
object_xz: vec2<f32>
) -> vec3<f32>

world_to_uv

#
fn world_to_uv (
world_xz: vec2<f32>
) -> vec2<f32>

sample_displacement

#

Wave content advects at surface.advection.xy metres per second. A sampling-space shift is exact Doppler advection for both spectra: sampling at x - u * t turns every component’s phase into (k . x) - (omega + k . u) * t. Snap/transition, depth lookups, and foam gating stay world-anchored.

fn sample_displacement (
world_xz: vec2<f32>
lod: u32
alpha: f32
) -> vec3<f32>

flow_frame

#
fn flow_frame (
world_xz: vec2<f32>
) -> vec2<f32>

capillary_resolved_weight

#
fn capillary_resolved_weight (
world_xz: vec2<f32>
) -> f32

godot_fresnel

#

GodotOceanWaves water.gdshader: bounded GGX distribution and its Smith masking-shadowing approximation. Aqua applies Fresnel later in Crest’s reflection composition, so this returns the remaining direct-sun factor.

fn godot_fresnel (
view_alignment: f32
) -> f32