rustial-renderer-wgpu 1.0.0

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
// Heatmap colour-mapping shader.
//
// Pass 2: Reads the accumulated weight texture from Pass 1 and maps it
// through a colour ramp.

struct Uniforms {
    view_proj:  mat4x4<f32>,
    fog_color:  vec4<f32>,
    eye_pos:    vec4<f32>,
    fog_params: vec4<f32>,
};

struct FullscreenVertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) uv: vec2<f32>,
};

@group(0) @binding(0) var<uniform> u: Uniforms;
@group(1) @binding(0) var heat_texture: texture_2d<f32>;
@group(1) @binding(1) var ramp_texture: texture_2d<f32>;
@group(1) @binding(2) var ramp_sampler: sampler;

// Fullscreen triangle: vertex_index 0,1,2 produces a triangle covering
// the entire clip space.
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> FullscreenVertexOutput {
    var out: FullscreenVertexOutput;
    let x = f32(i32(vertex_index) / 2) * 4.0 - 1.0;
    let y = f32(i32(vertex_index) % 2) * 4.0 - 1.0;
    out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
    out.uv = vec2<f32>((x + 1.0) * 0.5, (1.0 - y) * 0.5);
    return out;
}

@fragment
fn fs_main(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
    let dims = textureDimensions(heat_texture);
    let texel = vec2<i32>(
        i32(in.uv.x * f32(dims.x)),
        i32(in.uv.y * f32(dims.y)),
    );
    let weight = textureLoad(heat_texture, texel, 0).r;

    // Clamp to [0, 1] and sample the colour ramp.
    let t = clamp(weight, 0.0, 1.0);
    if t < 0.001 {
        discard;
    }
    let ramp_color = textureSample(ramp_texture, ramp_sampler, vec2<f32>(t, 0.5));

    return vec4<f32>(ramp_color.rgb, ramp_color.a * t);
}