import { shader2d } from "https://deno.land/x/caviar@2.4.6/web/src/renderers/shader2d.ts";
type
`
struct Uniforms {
position: vec2<f32>;
usage: f32;
color: vec4<f32>;
};
struct Output {
@builtin(position) position: vec4<f32>;
@location(1) coords: vec2<f32>;
};
@group(0) @binding(0)
var uTexture: texture_2d<f32>;
@group(0) @binding(1)
var uSampler: sampler;
@group(1) @binding(0)
var<uniform> uniforms: Uniforms;
@stage(vertex)
fn vs_main(
@location(0) position: vec2<f32>,
@location(1) coords: vec2<f32>,
) -> Output {
var out: Output;
out.position = vec4(position + uniforms.position, 0.0, 1.0);
out.coords = coords;
return out;
}
@stage(fragment)
fn fs_main(out: Output) -> @location(0) vec4<f32> {
if (uniforms.usage == 0.0) {
return uniforms.color;
} else {
return textureSample(uTexture, uSampler, out.coords);
}
}
`