Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boids Sprites: rotation and velocity behavior visualized with color #227

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/sample/computeBoids/sprite.wgsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
struct VertexOutput {
@builtin(position) position : vec4<f32>,
@location(4) color : vec4<f32>,
}

@vertex
fn vert_main(
@location(0) a_particlePos : vec2<f32>,
@location(1) a_particleVel : vec2<f32>,
@location(2) a_pos : vec2<f32>
) -> @builtin(position) vec4<f32> {
) -> VertexOutput {
let angle = -atan2(a_particleVel.x, a_particleVel.y);
let pos = vec2(
(a_pos.x * cos(angle)) - (a_pos.y * sin(angle)),
(a_pos.x * sin(angle)) + (a_pos.y * cos(angle))
);
return vec4(pos + a_particlePos, 0.0, 1.0);

var output : VertexOutput;
output.position = vec4(pos + a_particlePos, 0.0, 1.0);
output.color = vec4(
1.0 - sin(angle + 1.0) - a_particleVel.y,
pos.x * 100.0 - a_particleVel.y + 0.1,
a_particleVel.x + cos(angle + 0.5),
1.0);
return output;
}

@fragment
fn frag_main() -> @location(0) vec4<f32> {
return vec4(1.0, 1.0, 1.0, 1.0);
}
fn frag_main(@location(4) color : vec4<f32>) -> @location(0) vec4<f32> {
return color;
}