1
0
This commit is contained in:
Niklas Birk
2020-03-13 17:11:07 +01:00
parent 92a3dc0813
commit 1b5b6d0f45
3 changed files with 96 additions and 73 deletions

View File

@@ -16,23 +16,49 @@ layout(std430, binding = 0) buffer particles
};
uniform float dt;
uniform vec3 resetPos;
uniform uint seed;
layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
float rand()
{
uint seedR;
seedR = (seed * 1103515245u + 12345u);
return float(seed) / 4294967296.0;
}
vec3 rand3() {
vec3 result;
uint seedR;
seedR = (seed * 1103515245u + 12345u);
result.x = float(seed);
seedR = (seed * 1103515245u + 12345u);
result.y = float(seed);
seedR = (seed * 1103515245u + 12345u);
result.z = float(seed);
return (result / 2147483648.0) - vec3(1,1,1);
}
void main()
{
uint gid = gl_GlobalInvocationID.x;
particle part = p[gid];
if (part.age > 0 || part.pos.x > 1 || part.pos.y > 1 || part.pos.z > 1)
if (part.age < 0 || part.pos.x > 1 || part.pos.y > 1 || part.pos.z > 1
|| part.pos.x < -1 || part.pos.y < -1 || part.pos.z < -1 )
{
part.pos = resetPos;
part.vel = rand3();
part.col = vec3(rand(), rand(), rand());
part.age = rand() * 0x7fff * 0.01f;
}
else
{
part.pos += part.vel * dt;
part.age -= 0.01f;
}
else
{
part.pos = vec3(0, 0, 0);
}
p[gid] = part;
}

View File

@@ -8,5 +8,5 @@ out vec3 colV;
void main(void)
{
colV = colIn;
gl_Position = vec4(pos, 0);
gl_Position = vec4(pos, 1);
}