Skip to content

Commit

Permalink
chore: cleanup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Sep 29, 2023
1 parent 115f36e commit 7c50eae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`,
})
Expand All @@ -623,12 +621,10 @@ const computeMaterial = new Material({
@group(0) @binding(1)
var<storage, read_write> uv: array<vec2<f32>>;
const vertex = array<vec2<f32>, 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<f32>(vec2((i << 1) & 2, i & 2));
position[i] = uv[i] * 2 - 1;
}
`,
})
Expand Down
8 changes: 3 additions & 5 deletions examples/webgl-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`,
})
Expand Down
6 changes: 2 additions & 4 deletions examples/webgl-fullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions examples/webgpu-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ const computeMaterial = new Material({
@group(0) @binding(1)
var<storage, read_write> uv: array<vec2<f32>>;
const vertex = array<vec2<f32>, 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<f32>(vec2((i << 1) & 2, i & 2));
position[i] = uv[i] * 2 - 1;
}
`,
})
Expand Down
6 changes: 2 additions & 4 deletions examples/webgpu-fullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ const material = new Material({
@location(1) uv: vec2<f32>,
};
const triangle = array<vec2<f32>, 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<f32>(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;
}
Expand Down

0 comments on commit 7c50eae

Please sign in to comment.