struct VertexInput {
    @location(0) position: vec2<f32>,
    @location(1) uv: vec2<f32>,
}

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

@vertex
fn vs_main(input: VertexInput) -> VertexOutput {
    var output: VertexOutput;
    output.clip_position = vec4<f32>(input.position, 0.0, 1.0);
    output.uv = input.uv;
    return output;
}

@group(0) @binding(0)
var t_shadow: texture_depth_2d_array;

@fragment
fn fs_shadow_map(input: VertexOutput) -> @location(0) vec4<f32> {
    let size = vec2<f32>(textureDimensions(t_shadow));
    let coord = vec2<i32>(input.uv * size);
    let depth = textureLoad(t_shadow, coord, 0, 0);
    let linearized = 1.0 - depth;
    return vec4<f32>(linearized, linearized, linearized, 1.0);
}

@group(0) @binding(1)
var t_snow_light: texture_2d<f32>;

@group(0) @binding(2)
var t_sampler: sampler;

@fragment
fn fs_snow_light(input: VertexOutput) -> @location(0) vec4<f32> {
    let value = textureSample(t_snow_light, t_sampler, input.uv).r;
    let remapped = clamp(value * 10.0, 0.0, 1.0);
    return vec4<f32>(remapped, remapped, remapped, 1.0);
}
