Skip to content

Commit

Permalink
adapt examples
Browse files Browse the repository at this point in the history
  • Loading branch information
reczkok committed Jan 29, 2025
1 parent e9391ac commit 32af044
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const vertexFunction = tgpu['~unstable']
{ vertexIndex: d.builtin.vertexIndex },
{ outPos: d.builtin.position },
)
.does(/* wgsl */ `(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
.does(/* wgsl */ `(input: VertexInput) -> VertexOutput {
var pos = array<vec2f, 6>(
vec2<f32>( 1, 1),
vec2<f32>( 1, -1),
Expand All @@ -196,7 +196,7 @@ const vertexFunction = tgpu['~unstable']
);
var output: VertexOutput;
output.outPos = vec4f(pos[vertexIndex], 0, 1);
output.outPos = vec4f(pos[input.vertexIndex], 0, 1);
return output;
}`)
.$name('vertex_main');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const VertexOutput = {

const mainVert = tgpu['~unstable']
.vertexFn({ v: d.vec2f, center: d.vec2f, velocity: d.vec2f }, VertexOutput)
.does(/* wgsl */ `(@location(0) v: vec2f, @location(1) center: vec2f, @location(2) velocity: vec2f) -> VertexOutput {
let angle = getRotationFromVelocity(velocity);
let rotated = rotate(v, angle);
.does(/* wgsl */ `(input: VertexInput) -> VertexOutput {
let angle = getRotationFromVelocity(input.velocity);
let rotated = rotate(input.v, angle);
let pos = vec4(rotated + center, 0.0, 1.0);
let pos = vec4(rotated + input.center, 0.0, 1.0);
let color = vec4(
sin(angle + colorPalette.r) * 0.45 + 0.45,
Expand Down Expand Up @@ -223,7 +223,7 @@ const mainCompute = tgpu['~unstable']
var alignmentCount = 0u;
var cohesion = vec2(0.0, 0.0);
var cohesionCount = 0u;
for (var i = 0u; i < arrayLength(&currentTrianglePos); i = i + 1) {
if (i == index) {
continue;
Expand Down Expand Up @@ -253,7 +253,7 @@ const mainCompute = tgpu['~unstable']
+ (alignment * params.alignmentStrength)
+ (cohesion * params.cohesionStrength);
instanceInfo.velocity = normalize(instanceInfo.velocity) * clamp(length(instanceInfo.velocity), 0.0, 0.01);
if (instanceInfo.position[0] > 1.0 + triangleSize) {
instanceInfo.position[0] = -1.0 - triangleSize;
}
Expand Down Expand Up @@ -340,7 +340,7 @@ export const controls = {
onButtonClick: () => paramsBuffer.write(presets.blobs),
},

'⚛ Particles': {
'⚛ Particles': {
onButtonClick: () => paramsBuffer.write(presets.particles),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,24 @@ const mainVert = tgpu['~unstable']
VertexOutput,
)
.does(
/* wgsl */ `(
@location(0) tilt: f32,
@location(1) angle: f32,
@location(2) color: vec4f,
@location(3) center: vec2f,
@builtin(vertex_index) index: u32,
) -> VertexOutput {
let width = tilt;
let height = tilt / 2;
/* wgsl */ `(input: VertexInput) -> VertexOutput {
let width = input.tilt;
let height = input.tilt / 2;
var pos = rotate(array<vec2f, 4>(
vec2f(0, 0),
vec2f(width, 0),
vec2f(0, height),
vec2f(width, height),
)[index] / 350, angle) + center;
)[input.index] / 350, input.angle) + input.center;
if (canvasAspectRatio < 1) {
pos.x /= canvasAspectRatio;
} else {
pos.y *= canvasAspectRatio;
}
return VertexOutput(vec4f(pos, 0.0, 1.0), color);
return VertexOutput(vec4f(pos, 0.0, 1.0), input.color);
}`,
)
.$uses({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ const vertexMain = tgpu['~unstable']
{ idx: d.builtin.vertexIndex },
{ pos: d.builtin.position, uv: d.vec2f },
)
.does(/* wgsl */ `(@builtin(vertex_index) idx: u32) -> VertexOut {
.does(/* wgsl */ `(input: VertexInput) -> VertexOut {
var pos = array<vec2f, 4>(
vec2(1, 1), // top-right
vec2(-1, 1), // top-left
Expand All @@ -506,8 +506,8 @@ const vertexMain = tgpu['~unstable']
);
var output: VertexOut;
output.pos = vec4f(pos[idx].x, pos[idx].y, 0.0, 1.0);
output.uv = uv[idx];
output.pos = vec4f(pos[input.idx].x, pos[input.idx].y, 0.0, 1.0);
output.uv = uv[input.idx];
return output;
}`);

Expand Down

0 comments on commit 32af044

Please sign in to comment.