From 7c50eae176c2f0077e49923b59876934a5d84620 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:40:04 -0500 Subject: [PATCH] chore: cleanup examples --- README.md | 14 +++++--------- examples/webgl-compute.ts | 8 +++----- examples/webgl-fullscreen.ts | 6 ++---- examples/webgpu-compute.ts | 6 ++---- examples/webgpu-fullscreen.ts | 6 ++---- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2a69fc3..fd7e6b4 100644 --- a/README.md +++ b/README.md @@ -589,14 +589,12 @@ const geometry = new Geometry({ }) const computeMaterial = new Material({ compute: /* glsl */ `#version 300 es - out vec2 position; out vec2 uv; - - const vec2 vertex[3] = vec2[](vec2(-1), vec2(3, -1), vec2(-1, 3)); + out vec2 position; void main() { - position = vertex[gl_VertexID]; - uv = abs(position) - 1.0; + uv = vec2(gl_VertexID << 1 & 2, gl_VertexID & 2); + position = uv * 2.0 - 1.0; } `, }) @@ -623,12 +621,10 @@ const computeMaterial = new Material({ @group(0) @binding(1) var uv: array>; - const vertex = array, 3>(vec2(-1), vec2(3, -1), vec2(-1, 3)); - @compute @workgroup_size(64) fn main(@builtin(local_invocation_index) i: u32) { - position[i] = vertex[i]; - uv[i] = abs(vertex[i]) - 1.0; + uv[i] = vec2(vec2((i << 1) & 2, i & 2)); + position[i] = uv[i] * 2 - 1; } `, }) diff --git a/examples/webgl-compute.ts b/examples/webgl-compute.ts index c7dcc95..2dec5ab 100644 --- a/examples/webgl-compute.ts +++ b/examples/webgl-compute.ts @@ -11,14 +11,12 @@ const geometry = new Geometry({ const computeMaterial = new Material({ compute: /* glsl */ `#version 300 es - out vec2 position; out vec2 uv; - - const vec2 vertex[3] = vec2[](vec2(-1), vec2(3, -1), vec2(-1, 3)); + out vec2 position; void main() { - position = vertex[gl_VertexID]; - uv = abs(position) - 1.0; + uv = vec2(gl_VertexID << 1 & 2, gl_VertexID & 2); + position = uv * 2.0 - 1.0; } `, }) diff --git a/examples/webgl-fullscreen.ts b/examples/webgl-fullscreen.ts index cd977fa..2a79fb9 100644 --- a/examples/webgl-fullscreen.ts +++ b/examples/webgl-fullscreen.ts @@ -11,12 +11,10 @@ const material = new Material({ }, vertex: /* glsl */ `#version 300 es out vec2 vUv; - - const vec2 triangle[3] = vec2[](vec2(-1), vec2(3, -1), vec2(-1, 3)); void main() { - gl_Position = vec4(triangle[gl_VertexID], 0, 1); - vUv = abs(gl_Position.xy) - 1.0; + vUv = vec2(gl_VertexID << 1 & 2, gl_VertexID & 2); + gl_Position = vec4(vUv * 2.0 - 1.0, 0, 1); } `, fragment: /* glsl */ `#version 300 es diff --git a/examples/webgpu-compute.ts b/examples/webgpu-compute.ts index f47b35b..671aa6a 100644 --- a/examples/webgpu-compute.ts +++ b/examples/webgpu-compute.ts @@ -17,12 +17,10 @@ const computeMaterial = new Material({ @group(0) @binding(1) var uv: array>; - const vertex = array, 3>(vec2(-1), vec2(3, -1), vec2(-1, 3)); - @compute @workgroup_size(64) fn main(@builtin(local_invocation_index) i: u32) { - position[i] = vertex[i]; - uv[i] = abs(vertex[i]) - 1.0; + uv[i] = vec2(vec2((i << 1) & 2, i & 2)); + position[i] = uv[i] * 2 - 1; } `, }) diff --git a/examples/webgpu-fullscreen.ts b/examples/webgpu-fullscreen.ts index 3f6e242..44dcda0 100644 --- a/examples/webgpu-fullscreen.ts +++ b/examples/webgpu-fullscreen.ts @@ -21,13 +21,11 @@ const material = new Material({ @location(1) uv: vec2, }; - const triangle = array, 3>(vec2(-1), vec2(3, -1), vec2(-1, 3)); - @vertex fn main(@builtin(vertex_index) i: u32) -> VertexOut { var out: VertexOut; - out.position = vec4(triangle[i], 0, 1); - out.uv = abs(out.position.xy) - 1.0; + out.uv = vec2(vec2((i << 1) & 2, i & 2)); + out.position = vec4(out.uv * 2 - 1, 0, 1); out.color = vec4(0.5 + 0.3 * cos(vec3(out.uv, 0.0) + uniforms.time), 0.0); return out; }