rustial-renderer-wgpu 1.0.0

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
// ---------------------------------------------------------------------------
// Fill shader — dedicated fill-layer rendering with per-layer translate,
// opacity, outline colour, and fog support.
// ---------------------------------------------------------------------------

struct Uniforms {
    view_proj:   mat4x4<f32>,
    fog_color:   vec4<f32>,
    eye_pos:     vec4<f32>,
    fog_params:  vec4<f32>,   // (start, end, density, 0)
};

// Fill-specific parameters uploaded once per draw batch.
//   fill_translate: vec2  — pixel-space translate offset (applied in clip space)
//   fill_opacity:   f32   — layer opacity multiplier
//   fill_antialias: f32   — 1.0 if edge smoothing enabled, 0.0 otherwise
struct FillParams {
    fill_translate:    vec2<f32>,
    fill_opacity:      f32,
    fill_antialias:    f32,
    outline_color:     vec4<f32>,
};

struct FillVertexInput {
    @location(0) position: vec3<f32>,
    @location(1) color:    vec4<f32>,
};

struct FillVertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) color:     vec4<f32>,
    @location(1) world_pos: vec3<f32>,
};

@group(0) @binding(0)
var<uniform> u: Uniforms;

@group(0) @binding(1)
var<uniform> fp: FillParams;

@vertex
fn vs_main(in: FillVertexInput) -> FillVertexOutput {
    var out: FillVertexOutput;
    var clip = u.view_proj * vec4<f32>(in.position, 1.0);

    // Apply pixel-space translate.  Convert pixel offset to NDC offset
    // using the clip w component to approximate screen-space pixels.
    // This matches MapLibre's fill-translate behavior.
    clip.x = clip.x + fp.fill_translate.x * clip.w * 0.001;
    clip.y = clip.y + fp.fill_translate.y * clip.w * 0.001;

    out.clip_position = clip;
    out.color = in.color;
    out.world_pos = in.position;
    return out;
}

@fragment
fn fs_main(in: FillVertexOutput) -> @location(0) vec4<f32> {
    // Ground-plane horizon fog (same as vector.wgsl).
    let dx = in.world_pos.x - u.eye_pos.x;
    let dy = in.world_pos.y - u.eye_pos.y;
    let ground_dist = sqrt(dx * dx + dy * dy);
    let fog_start = u.fog_params.x;
    let fog_end   = u.fog_params.y;
    let density   = u.fog_params.z;
    let fog_t = clamp(
        (ground_dist - fog_start) / max(fog_end - fog_start, 0.001),
        0.0,
        1.0,
    ) * density;

    let fog_mix = fog_t * 0.7;
    let blended_rgb = mix(in.color.rgb, u.fog_color.rgb, fog_mix);

    // Apply fill-layer opacity on top of per-vertex alpha.
    let alpha = in.color.a * fp.fill_opacity;
    return vec4<f32>(blended_rgb, alpha);
}