diff options
| author | Tengu712 <genreihoutengu@gmail.com> | 2026-10-07 00:57:01 +0900 |
|---|---|---|
| committer | Tengu712 <genreihoutengu@gmail.com> | 2026-10-07 00:57:01 +0900 |
| commit | 3bbe5ebcdb2a5aa6810dd05576c6ec031efdc1c7 (patch) | |
| tree | 844e4ba5efc755dabf091a51178937a93e1d47ed /src/shader.wgsl | |
| parent | 503486e2ce889858aac619985516374bddeb7a8f (diff) | |
Diffstat (limited to 'src/shader.wgsl')
| -rw-r--r-- | src/shader.wgsl | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/shader.wgsl b/src/shader.wgsl index e0b34f4..80df5b0 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -1,18 +1,25 @@ +enable wgpu_binding_array; + struct Instance { - position: vec2<f32>, - scale: vec2<f32>, - uv: vec4<f32>, + transform: mat2x2<f32>, + translation: vec2<f32>, + uv_offset: vec2<f32>, + uv_size: vec2<f32>, + tex_id: u32, + _pad: u32, } struct VertexOutput { - @builtin(position) position: vec4<f32>, - @location(0) uv: vec2<f32>, + @builtin(position) position: vec4<f32>, + @location(0) uv: vec2<f32>, + @location(1) @interpolate(flat) tex_id: u32, } @group(0) @binding(0) var<storage, read> instances: array<Instance>; @group(1) @binding(0) var tex_sampler: sampler; @group(1) @binding(1) var font_tex: texture_2d<f32>; +@group(1) @binding(2) var image_texs: binding_array<texture_2d<f32>, 5>; @vertex fn vs_main( @@ -23,13 +30,17 @@ fn vs_main( let instance = instances[in_instance_index]; var out: VertexOutput; - out.position = vec4<f32>(instance.position + (uv - 0.5) * instance.scale * 2.0, 0.0, 1.0); - out.uv = instance.uv.xy + vec2<f32>(uv.x, 1.0 - uv.y) * instance.uv.zw; + out.position = vec4<f32>(instance.transform * (uv - 0.5) + instance.translation, 0.0, 1.0); + out.uv = instance.uv_offset + uv * instance.uv_size; + out.tex_id = instance.tex_id; return out; } @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { - return vec4<f32>(1.0, 1.0, 1.0, textureSample(font_tex, tex_sampler, in.uv).r); + if in.tex_id >= 5u { + return vec4<f32>(1.0, 1.0, 1.0, textureSampleLevel(font_tex, tex_sampler, in.uv, 0.0).r); + } + return textureSampleLevel(image_texs[in.tex_id], tex_sampler, in.uv, 0.0); } |
