struct VertexInput { // @location(0) pos: vec2, // @location(1) uv: vec2, // @location(2) col: vec4, [[location(0)]] pos: vec2; [[location(1)]] uv: vec2; [[location(2)]] col: vec4; }; struct FragmentInput { // @builtin(position) pos: vec4, // @location(0) col: vec4, // @location(1) uv: vec2, [[builtin(position)]] pos: vec4; [[location(0)]] col: vec4; [[location(1)]] uv: vec2; }; struct UniformInput { mvp: mat4x4; }; // @group(0) // @binding(0) [[group(0), binding(0)]] var ubo: UniformInput; // @group(0) // @binding(1) [[group(0), binding(1)]] var t_texture: texture_2d; // @group(0) // @binding(2) [[group(0), binding(2)]] var s_texture: sampler; // @vertex [[stage(vertex)]] fn vs_main(vin: VertexInput) -> FragmentInput { var fin: FragmentInput; fin.pos = ubo.mvp * vec4(vin.pos, 0.0, 1.0); fin.col = vin.col; fin.uv = vin.uv; return fin; } // smoothstep for old wgsl // https://en.wikipedia.org/wiki/Smoothstep fn smoothstep_2(edge0: f32, edge1: f32, x: f32) -> f32 { if (x < edge0) { return 0.0; } if (x >= edge1) { return 1.0; } // Scale/bias into [0..1] range let x = (x - edge0) / (edge1 - edge0); return x * x * (3.0 - 2.0 * x); } // @fragment [[stage(fragment)]] fn fs_main(fin: FragmentInput) -> [[location(0)]] vec4 { // @location(0) let aa = 0.01; let val = textureSample(t_texture, s_texture, fin.uv).x; // border let alpha = smoothstep_2(0.35 - aa, 0.35 + aa, val); // outline let col = vec3(smoothstep_2(0.5 - aa, 0.5 + aa, val)); return fin.col * vec4(col, alpha); }