69 lines
1.7 KiB
GLSL
69 lines
1.7 KiB
GLSL
|
#extension GL_ARB_explicit_attrib_location : enable
|
||
|
|
||
|
// ping pong inputs
|
||
|
uniform sampler2DRect particles0;
|
||
|
uniform sampler2DRect particles1;
|
||
|
uniform sampler2DRect particles2;
|
||
|
|
||
|
uniform sampler2DRect u_depth;
|
||
|
uniform sampler2DRect u_world;
|
||
|
uniform sampler2DRect u_v4l2cam;
|
||
|
|
||
|
uniform ivec2 uFrameSize;
|
||
|
uniform ivec2 uDepthFrameSize;
|
||
|
|
||
|
uniform vec3 mouse;
|
||
|
uniform float radiusSquared;
|
||
|
uniform float elapsed;
|
||
|
|
||
|
in vec2 texCoordVarying;
|
||
|
|
||
|
layout(location = 0) out vec4 posOut;
|
||
|
layout(location = 1) out vec4 velOut;
|
||
|
layout(location = 2) out vec4 misOut;
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
|
||
|
float depth = texture(u_depth, texCoordVarying.st).x;
|
||
|
vec4 ray = texture(u_world, texCoordVarying.st);
|
||
|
|
||
|
float vValid = (depth != 0 && ray.x != 0 && ray.y != 0) ? 1 : 0;
|
||
|
|
||
|
if(depth < 0.012) vValid = 0;
|
||
|
if(depth > 0.04) vValid = 0;
|
||
|
|
||
|
vec4 posWorld = vec4(1);
|
||
|
posWorld.z = -depth * 65535.0; // Remap to float range.
|
||
|
posWorld.x = ray.x * posWorld.z;
|
||
|
posWorld.y = ray.y * posWorld.z;
|
||
|
|
||
|
vec3 pos = texture(particles0, texCoordVarying.st).xyz;
|
||
|
pos = posWorld.xyz;
|
||
|
vec3 vel = texture(particles1, texCoordVarying.st).xyz;
|
||
|
|
||
|
// mouse attraction
|
||
|
vec3 direction = mouse - pos.xyz;
|
||
|
float distSquared = dot(direction, direction);
|
||
|
float magnitude = 500.0 * (1.0 - distSquared / radiusSquared);
|
||
|
vec3 force = step(distSquared, radiusSquared) * magnitude * normalize(direction);
|
||
|
|
||
|
// gravity
|
||
|
force += vec3(0.0, -0.5, 0.0);
|
||
|
|
||
|
// accelerate
|
||
|
vel += elapsed * force;
|
||
|
|
||
|
// bounce off the sides
|
||
|
vel.x *= step(abs(pos.x), 512.0) * 2.0 - 1.0;
|
||
|
vel.y *= step(abs(pos.y), 384.0) * 2.0 - 1.0;
|
||
|
|
||
|
// damping
|
||
|
vel *= 0.995;
|
||
|
|
||
|
// move
|
||
|
pos += elapsed * vel;
|
||
|
|
||
|
posOut = vec4(pos, 1.0);
|
||
|
velOut = vec4(vel, 0.0);
|
||
|
}
|