~starkingdoms/starkingdoms

ref: ea95cf279b1c21687826debb5db825fa057e6d3b starkingdoms/starkingdoms-client/src/shaders/sprite.wgsl -rw-r--r-- 940 bytes
ea95cf27 — core new rendering infrastructure beginnings 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
struct VertexShaderOut {
    @builtin(position) position: vec4<f32>,
    @location(0) texcoord: vec2<f32>
}

struct Uniforms {
    scale: vec2f,
    offset: vec2f
}
@group(0) @binding(2) var<uniform> uni: Uniforms;

@vertex fn vs(
    @builtin(vertex_index) vertexIndex : u32
) -> VertexShaderOut {
    let pos = array(
        vec2<f32>(0.0, 0.0),
        vec2<f32>(1.0, 0.0),
        vec2<f32>(0.0, 1.0),
        vec2<f32>(0.0, 1.0),
        vec2<f32>(1.0, 0.0),
        vec2<f32>(1.0, 1.0)
    );

    var vsOutput: VertexShaderOut;
    let xy = pos[vertexIndex];
    vsOutput.position = vec4f(xy * uni.scale + uni.offset, 0.0, 1.0);
    vsOutput.texcoord = vec2f(xy.x, 1.0 - xy.y);
    return vsOutput;
}

@group(0) @binding(0) var tex_sampler: sampler;
@group(0) @binding(1) var tex: texture_2d<f32>;

@fragment fn fs(fsInput: VertexShaderOut) -> @location(0) vec4<f32> {
    return textureSample(tex, tex_sampler, fsInput.texcoord);
}