diff --git a/zoneb/bin/data/shaders/bound.frag b/zoneb/bin/data/shaders/bound.frag index 79c4db8..49132a2 100644 --- a/zoneb/bin/data/shaders/bound.frag +++ b/zoneb/bin/data/shaders/bound.frag @@ -4,6 +4,7 @@ precision mediump float; uniform sampler2DRect u_depth; uniform sampler2DRect u_ofcam; +uniform sampler2DRect u_energy; uniform sampler2DRect u_v4l2cam; uniform sampler2DRect u_buffer0; uniform sampler2DRect u_buffer1; @@ -185,7 +186,10 @@ void main() { } else { vec4 pointCloudColor = texture(u_ofcam, st); - gl_FragColor = vec4(mix(vec3(0), pointCloudColor.rgb, pointCloudColor.a), 1.0); + vec4 energyColor = texture(u_energy, st); + vec4 color = vec4(mix(vec3(0), pointCloudColor.rgb, pointCloudColor.a), 1.0); + gl_FragColor = vec4(mix(pointCloudColor.rgb, energyColor.rgb, energyColor.a), 1.0); + // gl_FragColor = vec4(mix(vec3(0), energyColor.rgb, energyColor.a), 1.0); } #endif diff --git a/zoneb/bin/data/shaders/particles/draw.frag b/zoneb/bin/data/shaders/particles/draw.frag index 07b347f..2b8ece1 100755 --- a/zoneb/bin/data/shaders/particles/draw.frag +++ b/zoneb/bin/data/shaders/particles/draw.frag @@ -19,6 +19,7 @@ uniform vec3 uHottest1; uniform vec3 uHottest3d0; uniform vec3 uHottest3d1; uniform vec3 uBetween; +uniform int uEnergy; in vec2 texCoordVarying; in vec3 gPos; @@ -114,7 +115,14 @@ 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)) * 0.1; + float alpha = max(0, 1 - pow(gAge,4)); + if(uEnergy > 0) { + // alpha = 1; + alpha *= 0.3; + } + else { + alpha *= 0.1; + } // if(vTemperature < 0.5) { // alpha *= vTemperature * 2; diff --git a/zoneb/bin/data/shaders/particles/draw.geom b/zoneb/bin/data/shaders/particles/draw.geom index e050498..4ab4898 100644 --- a/zoneb/bin/data/shaders/particles/draw.geom +++ b/zoneb/bin/data/shaders/particles/draw.geom @@ -8,6 +8,8 @@ uniform mat4 projectionMatrix; uniform float u_time; +uniform int uEnergy; + // App specific uniforms and attributes. // uniform float uSpriteSize; @@ -42,8 +44,16 @@ void main() if(gAge >= 1) return; for (int i = 0; i < gl_in.length(); ++i) { - vec3 vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz) * (gAge * 5); - vOffset += normalize(vOffset) * 5; + vec3 vOffset; + if(uEnergy > 0) { + vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz) * (gAge * 15); + // vOffset += normalize(vOffset) * 5; + } + else { + vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz); + vOffset += normalize(vOffset) * 2; + vOffset = vec3(1,0,0); + } // if(length(vOffset) < 4) { // vOffset = normalize(vOffset) * 4; // } @@ -56,14 +66,14 @@ void main() gl_Position = projectionMatrix * (shiftPos + vec4(0.0, 0.0, 0.0, 0.0) * uSpriteSize); EmitVertex(); - if(gAge > 0 && gTarget.w > 0) { - for(int j = 0; j < 3; j++) { - gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize); - EmitVertex(); - gl_Position = projectionMatrix * (shiftPos + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize); - EmitVertex(); - } - } + // if(gAge > 0 && gTarget.w > 0) { + // for(int j = 0; j < 2; j++) { + // gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize); + // EmitVertex(); + // gl_Position = projectionMatrix * (shiftPos + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize); + // EmitVertex(); + // } + // } } diff --git a/zoneb/bin/data/shaders/particles/update.frag b/zoneb/bin/data/shaders/particles/update.frag index 62df613..e8e68ae 100755 --- a/zoneb/bin/data/shaders/particles/update.frag +++ b/zoneb/bin/data/shaders/particles/update.frag @@ -169,7 +169,7 @@ void main() } if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { // arrived - age += 1; + age += 0.01; } // wandering @@ -216,7 +216,7 @@ void main() if(target.w > 0) { // go to target float th = atan(-pos.y + target.y, -pos.x + target.x); float phi = atan(-pos.z + target.z, length(target.xy-pos.xy)); - th += 3.1415 / 1 * simplex3d_fractal(vec3(pos.xyz * 0.01)); + th += 3.1415 / 1 * simplex3d_fractal(vec3(pos.xyz * 0.01) + vec3(u_time, 0, 0)); phi += 3.1415 / 1 * simplex3d_fractal(pos.xyz * 0.01); force.x = cos(th) * cos(phi); force.y = sin(th) * cos(phi); diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index 50293a9..ecfb825 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -160,6 +160,8 @@ void ofApp::setup() fbos.insert({"ofcam", ofFbo()}); fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB); + fbos.insert({"energy", ofFbo()}); + fbos.at("energy").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB); for (auto s : gradientNames) { @@ -327,6 +329,7 @@ void ofApp::onParticlesDraw(ofxShader &shader) shader.setUniform3f("uHottest3d1", hotspot3d1); shader.setUniform3f("uBetween", uBetween); shader.setUniform1f("uAreThereTwoPeopleTween", areThereTwoPeopleTween); + shader.setUniform1i("uEnergy", uEnergy); } void ofApp::drawMain() @@ -335,6 +338,7 @@ void ofApp::drawMain() auto tex = kinectDevice.getDepthTex(); boundShader.setUniformTexture("u_depth", tex); boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam")); + boundShader.setUniformTexture("u_energy", fbos.at("energy")); boundShader.setUniformTexture("u_v4l2cam", v4l2Buffer.at(v4l2BufferCount)); boundShader.setUniform1i("u_calib", calibMode == true ? 1 : 0); boundShader.setUniform2f("u_calibXY", registrationXY); @@ -360,6 +364,27 @@ void ofApp::draw() particles.whateverImages.at("u_world") = kinectDevice.getDepthToWorldTex(); particles.whateverImages.at("u_v4l2cam") = v4l2Buffer.at(v4l2BufferCount); + fbos.at("energy").begin(); + ofClear(0); + cam.begin(); + if (blendAdd) + { + ofEnableBlendMode(OF_BLENDMODE_ADD); + ofDisableDepthTest(); + } + else + { + ofEnableDepthTest(); + } + uEnergy = 1; + particles.draw(); + if (blendAdd) + { + ofDisableBlendMode(); + } + cam.end(); + fbos.at("energy").end(); + fbos.at("ofcam").begin(); ofClear(0); cam.begin(); @@ -372,6 +397,7 @@ void ofApp::draw() { ofEnableDepthTest(); } + uEnergy = 0; particles.draw(); if (blendAdd) { diff --git a/zoneb/src/ofApp.h b/zoneb/src/ofApp.h index 58c16c6..eb58b0e 100644 --- a/zoneb/src/ofApp.h +++ b/zoneb/src/ofApp.h @@ -60,6 +60,7 @@ private: ofPixels v4l2Pixels; ofxGpuParticles particles; + int uEnergy; std::vector> hotspots; ofVec3f hotspot0, hotspot1;