CSH      “  #version 310 es
vec3 instMul(vec3 _vec, mat3 _mtx) { return ( (_vec) * (_mtx) ); }
vec3 instMul(mat3 _mtx, vec3 _vec) { return ( (_mtx) * (_vec) ); }
vec4 instMul(vec4 _vec, mat4 _mtx) { return ( (_vec) * (_mtx) ); }
vec4 instMul(mat4 _mtx, vec4 _vec) { return ( (_mtx) * (_vec) ); }
float rcp(float _a) { return 1.0/_a; }
vec2 rcp(vec2 _a) { return vec2(1.0)/_a; }
vec3 rcp(vec3 _a) { return vec3(1.0)/_a; }
vec4 rcp(vec4 _a) { return vec4(1.0)/_a; }
vec2 vec2_splat(float _x) { return vec2(_x, _x); }
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }
uniform vec4 u_viewRect;
uniform vec4 u_viewTexel;
uniform mat4 u_view;
uniform mat4 u_invView;
uniform mat4 u_proj;
uniform mat4 u_invProj;
uniform mat4 u_viewProj;
uniform mat4 u_invViewProj;
uniform mat4 u_model[32];
uniform mat4 u_modelView;
uniform mat4 u_modelViewProj;
uniform vec4 u_alphaRef4;
uniform vec4 u_params[3];
layout(std430, binding=0) writeonly buffer prevPositionBufferBuffer { vec4 prevPositionBuffer[]; };
layout(std430, binding=1) writeonly buffer currPositionBufferBuffer { vec4 currPositionBuffer[]; };
uint rotl(uint _x, uint _r)
{
return (_x << _r) | (_x >> (32u - _r) );
}
uint hash(uint _key, uint _seed)
{
uint c1 = 0xcc9e2d51u;
uint c2 = 0x1b873593u;
uint k1 = _key;
uint h1 = _seed;
k1 *= c1;
k1 = rotl(k1, 15u);
k1 *= c2;
h1 ^= k1;
h1 = rotl(h1, 13u);
h1 = h1 * 5u + 0xe6546b64u;
k1 *= c1;
k1 = rotl(k1, 15u);
k1 *= c2;
h1 ^= k1;
h1 ^= h1 >> uint(16u);
h1 *= 0x85ebca6bu;
h1 ^= h1 >> 13u;
h1 *= 0xc2b2ae35u;
h1 ^= h1 >> 16u;
return h1;
}
vec3 randomPointOnSphere(uint _id, uint _seed)
{
uvec2 u = uvec2(
hash(_id, _seed + 0u),
hash(_id, _seed + 1u)
);
vec2 v = uintBitsToFloat( (u >> 9u) | 0x3f800000u) - 1.0;
float lambda = v.x * 3.14159 * 2.0;
float phi = acos(2.0 * v.y - 1.0) - 3.14159 / 2.0;
vec3 p;
p.x = cos(lambda) * cos(phi);
p.y = sin(phi);
p.z = sin(lambda) * cos(phi);
return p;
}
layout (local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
void main()
{
uint key = gl_GlobalInvocationID.x;
vec3 position;
if (floatBitsToUint(u_params[2].y) == 0u)
{
position = vec3_splat(0.0);
}
else if (floatBitsToUint(u_params[2].y) == 1u)
{
position = 20.0 * randomPointOnSphere(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u);
}
else if (floatBitsToUint(u_params[2].y) == 2u)
{
uvec3 u = uvec3(
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 0u),
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 1u),
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 2u)
);
position = 20.0 * (uintBitsToFloat((u >> 9u) | uvec3(0x40000000, 0x40000000, 0x40000000) ) - 3.0);
}
else
{
uvec3 u = uvec3(
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 0u),
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 1u),
hash(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 2u)
);
vec3 v = 3.14159 * 2.0 * (uintBitsToFloat( (u >> 9u) | uvec3(0x3f800000u, 0x3f800000u, 0x3f800000u) ) - 1.0);
position.x = 20.0 * cos(v.x) + 3.0 * cos(v.y) * cos(v.x);
position.y = 3.0 * sin(v.y);
position.z = 20.0 * sin(v.x) + 3.0 * cos(v.y) * sin(v.x);
}
vec3 velocity = u_params[2].x * randomPointOnSphere(gl_GlobalInvocationID.x, floatBitsToUint(u_params[1].z) * 7u + 3u);
prevPositionBuffer[gl_GlobalInvocationID.x] = vec4(position - velocity * u_params[0].x, 0.0);
currPositionBuffer[gl_GlobalInvocationID.x] = vec4(position, 0.0);
}
 