67 lines
2.1 KiB
Text
67 lines
2.1 KiB
Text
#version 450
|
|
|
|
layout(local_size_x = 64) in;
|
|
|
|
// One texel per float: offset.x, offset.y, lifetime for the state and
|
|
// x, y for the velocity, as only single-channel images load everywhere.
|
|
layout(r32f, binding = 0) uniform image2D particleStateImage;
|
|
layout(r32f, binding = 2) uniform image2D particleVelocityImage;
|
|
|
|
layout(std140, binding = 1) uniform Params {
|
|
uint particleCountX;
|
|
uint particleCountY;
|
|
float phase;
|
|
float timeStep;
|
|
};
|
|
|
|
float easeInWindow(float fraction, float t) {
|
|
float windowSize = 0.8;
|
|
float windowStart = -windowSize;
|
|
float windowEnd = 1.0;
|
|
float windowPos = (1.0 - fraction) * windowStart + fraction * windowEnd;
|
|
float windowT = clamp(t - windowPos, 0.0, windowSize) / windowSize;
|
|
return 1.0 - windowT;
|
|
}
|
|
|
|
void main() {
|
|
uint gid = gl_GlobalInvocationID.x;
|
|
uint count = particleCountX * particleCountY;
|
|
if (gid >= count) {
|
|
return;
|
|
}
|
|
|
|
float easeInDuration = 0.8;
|
|
float effectFraction = clamp(phase, 0.0, easeInDuration) / easeInDuration;
|
|
|
|
uint particleX = gid % particleCountX;
|
|
float particleXFraction = float(particleX) / float(particleCountX);
|
|
float particleFraction = easeInWindow(effectFraction, particleXFraction);
|
|
|
|
int y = int(gid / particleCountX);
|
|
ivec2 stateCoord = ivec2(int(particleX) * 3, y);
|
|
ivec2 velocityCoord = ivec2(int(particleX) * 2, y);
|
|
|
|
vec2 offset = vec2(
|
|
imageLoad(particleStateImage, stateCoord).x,
|
|
imageLoad(particleStateImage, stateCoord + ivec2(1, 0)).x);
|
|
float lifetime = imageLoad(
|
|
particleStateImage,
|
|
stateCoord + ivec2(2, 0)).x;
|
|
|
|
vec2 velocity = vec2(
|
|
imageLoad(particleVelocityImage, velocityCoord).x,
|
|
imageLoad(particleVelocityImage, velocityCoord + ivec2(1, 0)).x);
|
|
|
|
offset += velocity * timeStep * particleFraction;
|
|
velocity.y += 80.0 * timeStep * particleFraction;
|
|
lifetime = max(0.0, lifetime - 0.6 * timeStep * particleFraction);
|
|
|
|
imageStore(particleStateImage, stateCoord, vec4(offset.x));
|
|
imageStore(particleStateImage, stateCoord + ivec2(1, 0), vec4(offset.y));
|
|
imageStore(particleStateImage, stateCoord + ivec2(2, 0), vec4(lifetime));
|
|
// velocity.x stays as the init pass wrote it.
|
|
imageStore(
|
|
particleVelocityImage,
|
|
velocityCoord + ivec2(1, 0),
|
|
vec4(velocity.y));
|
|
}
|