This commit is contained in:
micuat 2020-10-31 19:47:59 +01:00
parent c3c55ae4c7
commit 5726baafe0
5 changed files with 35 additions and 13 deletions

View file

@ -113,7 +113,7 @@ void main()
float rate = 1-smoothstep(D - d, D + d, length(gPos.x + uBetween.x) + n);
rate *= uAreThereTwoPeopleTween;
vec3 remapedColor = mix(remapedColorC, remapedColorW, rate);
float alpha = max(0, 1 - pow(gAge,4)) * .2;
float alpha = max(0, 1 - pow(gAge,4)) * .03;
// if(vTemperature < 0.5) {
// alpha *= vTemperature * 2;

View file

@ -6,10 +6,13 @@ layout (max_vertices = 4) out;
// OF handled uniforms and attributes.
uniform mat4 projectionMatrix;
uniform float u_time;
// App specific uniforms and attributes.
// uniform float uSpriteSize;
in vec4 vPosition[];
in vec4 vPrevPosition[];
in vec2 vTexCoord[];
flat in int vValid[];
@ -27,7 +30,7 @@ out float gAge;
void main()
{
float uSpriteSize = 1.5;
float uSpriteSize = 1;
// if (vValid[0] == 0) return;
texCoordVarying = vTexCoord[0];
@ -36,19 +39,30 @@ void main()
gTemperature = vTemperature[0];
gAge = vAge[0];
for (int i = 0; i < gl_in.length(); ++i)
{
gl_Position = projectionMatrix * (vPosition[i] + vec4(1.0, -1.0, 0.0, 0.0) * uSpriteSize);
vec3 vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz) * 4;
vOffset += normalize(vOffset) * 10;
// if(length(vOffset) < 4) {
// vOffset = normalize(vOffset) * 4;
// }
vec4 shiftPos = vec4(vOffset, 1) + vPosition[i];
gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, 1.0, 0.0, 0.0) * uSpriteSize);
EmitVertex();
gl_Position = projectionMatrix * (vPosition[i] + vec4(1.0, 1.0, 0.0, 0.0) * uSpriteSize);
if (u_time > 10) { // hack
gl_Position = projectionMatrix * (shiftPos + vec4(0.0, 1.0, 0.0, 0.0) * uSpriteSize);
EmitVertex();
gl_Position = projectionMatrix * (vPosition[i] + vec4(-1.0, -1.0, 0.0, 0.0) * uSpriteSize);
gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, -1.0, 0.0, 0.0) * uSpriteSize);
EmitVertex();
gl_Position = projectionMatrix * (vPosition[i] + vec4(-1.0, 1.0, 0.0, 0.0) * uSpriteSize);
gl_Position = projectionMatrix * (shiftPos + vec4(0.0, -1.0, 0.0, 0.0) * uSpriteSize);
EmitVertex();
}
EndPrimitive();
}

View file

@ -4,6 +4,7 @@ uniform sampler2DRect particles0;
uniform sampler2DRect particles1;
uniform sampler2DRect particles2;
uniform sampler2DRect particles3;
uniform sampler2DRect particles4;
in vec4 position;
in vec2 texcoord;
@ -14,6 +15,7 @@ out vec4 vTarget;
out float vTemperature;
out float vAge;
out vec4 vPosition;
out vec4 vPrevPosition;
void main()
{
@ -25,4 +27,5 @@ void main()
vAge = misc.y;
vPos = texture(particles0, vTexCoord).xyz;
vPosition = modelViewMatrix * vec4(vPos, 1.0);
vPrevPosition = modelViewMatrix * vec4(texture(particles4, vTexCoord).xyz, 1.0);
}

View file

@ -5,6 +5,7 @@ uniform sampler2DRect particles0;
uniform sampler2DRect particles1;
uniform sampler2DRect particles2;
uniform sampler2DRect particles3;
uniform sampler2DRect particles4;
uniform sampler2DRect u_depth;
uniform sampler2DRect u_world;
@ -28,6 +29,7 @@ layout(location = 0) out vec4 posOut;
layout(location = 1) out vec4 velOut;
layout(location = 2) out vec4 misOut;
layout(location = 3) out vec4 tarOut;
layout(location = 4) out vec4 prevPosOut;
vec3 random3(vec3 c) {
@ -111,6 +113,7 @@ void main()
vec3 vel = texture(particles1, texCoordVarying.st).xyz;
vec3 misc = texture(particles2, texCoordVarying.st).xyz;
vec4 target = texture(particles3, texCoordVarying.st).xyzw;
vec3 prevPos = pos;//texture(particles4, texCoordVarying.st).xyz;
float fraction = 8;
float thermo = texture2D(u_v4l2cam, texCoordVarying.st/fraction).r;
@ -152,8 +155,8 @@ void main()
if(vValid == 1 && target.w == 0) { // point valid && no target -> move to the point
pos = posWorld.xyz;
// prevPos = posWorld.xyz;// + vec3(1,0,0);//random3(posWorld.xyz) * 0.5;
age = 0;
target.xyz = pos;
}
else if (target.w > 0) { // targeted
age += 0.002;
@ -165,7 +168,7 @@ void main()
}
if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { // arrived
age += 0.1;
age += 1;
}
// wandering
@ -218,7 +221,6 @@ void main()
force.y = sin(th) * cos(phi);
force.z = sin(phi);
force *= 200 + 200 * simplex3d_fractal(vec3(texCoordVarying, 0.0));
// force += (target.xyz - pos) * 0.3;
}
// damping
@ -228,10 +230,12 @@ void main()
vel += elapsed * force;
// move
prevPos = pos;
pos += elapsed * vel;
posOut = vec4(pos, 1.0);
velOut = vec4(vel, 0.0);
misOut = vec4(thermo, age, 0, 0);
tarOut = vec4(target);
prevPosOut = vec4(prevPos, 1.0);
}

View file

@ -75,7 +75,7 @@ void ofApp::setupParticles()
unsigned w = 512 * 4 * 2;
unsigned h = 512 * 4 * 2;
particles.init(w, h, OF_PRIMITIVE_POINTS, false, 4);
particles.init(w, h, OF_PRIMITIVE_POINTS, false, 5);
particles.loadShaders("shaders/particles/update", "shaders/particles/draw");
@ -92,6 +92,7 @@ void ofApp::setupParticles()
}
}
particles.loadDataTexture(ofxGpuParticles::POSITION, particlePosns);
particles.loadDataTexture(4, particlePosns); // prev pos
// initial velocities
particles.zeroDataTexture(ofxGpuParticles::VELOCITY);