Mi2dRPGamEng/engine/render/shaders/textured_quad.wgsl

43 lines
1018 B
Plaintext

struct CameraUniform {
scale: vec2<f32>,
offset: vec2<f32>,
};
@group(0) @binding(0) var<uniform> camera: CameraUniform;
@group(1) @binding(0) var quad_texture: texture_2d<f32>;
@group(1) @binding(1) var quad_sampler: sampler;
struct VertexIn {
@location(0) position: vec2<f32>,
@location(1) uv: vec2<f32>,
};
struct InstanceIn {
@location(2) world_pos: vec2<f32>,
@location(3) size: vec2<f32>,
};
struct VertexOut {
@builtin(position) clip_position: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(vin: VertexIn, iin: InstanceIn) -> VertexOut {
var out: VertexOut;
let world = iin.world_pos + vin.position * iin.size;
let ndc = world * camera.scale + camera.offset;
out.clip_position = vec4<f32>(ndc, 0.0, 1.0);
out.uv = vin.uv;
return out;
}
@fragment
fn fs_main(in: VertexOut) -> @location(0) vec4<f32> {
let color = textureSample(quad_texture, quad_sampler, in.uv);
if (color.a < 0.01) {
discard;
}
return color;
}