From 33c3c0c0aa774bb7462e3c42aa04c591a66376a7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 14 Nov 2022 00:02:42 +0100 Subject: Group all solid triangles independently of color --- wgpu/src/shader/solid.wgsl | 29 +++++++++++++++++++++-------- wgpu/src/shader/triangle.wgsl | 30 ------------------------------ 2 files changed, 21 insertions(+), 38 deletions(-) delete mode 100644 wgpu/src/shader/triangle.wgsl (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/solid.wgsl b/wgpu/src/shader/solid.wgsl index 68a8fea3..b24402f8 100644 --- a/wgpu/src/shader/solid.wgsl +++ b/wgpu/src/shader/solid.wgsl @@ -1,17 +1,30 @@ -struct Uniforms { +struct Globals { transform: mat4x4, - color: vec4 } -@group(0) @binding(0) -var uniforms: Uniforms; +@group(0) @binding(0) var globals: Globals; + +struct VertexInput { + @location(0) position: vec2, + @location(1) color: vec4, +} + +struct VertexOutput { + @builtin(position) position: vec4, + @location(0) color: vec4, +} @vertex -fn vs_main(@location(0) input: vec2) -> @builtin(position) vec4 { - return uniforms.transform * vec4(input.xy, 0.0, 1.0); +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + + out.color = input.color; + out.position = globals.transform * vec4(input.position, 0.0, 1.0); + + return out; } @fragment -fn fs_main() -> @location(0) vec4 { - return uniforms.color; +fn fs_main(input: VertexOutput) -> @location(0) vec4 { + return input.color; } diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl deleted file mode 100644 index b24402f8..00000000 --- a/wgpu/src/shader/triangle.wgsl +++ /dev/null @@ -1,30 +0,0 @@ -struct Globals { - transform: mat4x4, -} - -@group(0) @binding(0) var globals: Globals; - -struct VertexInput { - @location(0) position: vec2, - @location(1) color: vec4, -} - -struct VertexOutput { - @builtin(position) position: vec4, - @location(0) color: vec4, -} - -@vertex -fn vs_main(input: VertexInput) -> VertexOutput { - var out: VertexOutput; - - out.color = input.color; - out.position = globals.transform * vec4(input.position, 0.0, 1.0); - - return out; -} - -@fragment -fn fs_main(input: VertexOutput) -> @location(0) vec4 { - return input.color; -} -- cgit