separate point cloud and energy draw buffers
This commit is contained in:
parent
c45f50c439
commit
a9b65025d3
6 changed files with 63 additions and 14 deletions
|
@ -4,6 +4,7 @@ precision mediump float;
|
||||||
|
|
||||||
uniform sampler2DRect u_depth;
|
uniform sampler2DRect u_depth;
|
||||||
uniform sampler2DRect u_ofcam;
|
uniform sampler2DRect u_ofcam;
|
||||||
|
uniform sampler2DRect u_energy;
|
||||||
uniform sampler2DRect u_v4l2cam;
|
uniform sampler2DRect u_v4l2cam;
|
||||||
uniform sampler2DRect u_buffer0;
|
uniform sampler2DRect u_buffer0;
|
||||||
uniform sampler2DRect u_buffer1;
|
uniform sampler2DRect u_buffer1;
|
||||||
|
@ -185,7 +186,10 @@ void main() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vec4 pointCloudColor = texture(u_ofcam, st);
|
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
|
#endif
|
||||||
|
|
|
@ -19,6 +19,7 @@ uniform vec3 uHottest1;
|
||||||
uniform vec3 uHottest3d0;
|
uniform vec3 uHottest3d0;
|
||||||
uniform vec3 uHottest3d1;
|
uniform vec3 uHottest3d1;
|
||||||
uniform vec3 uBetween;
|
uniform vec3 uBetween;
|
||||||
|
uniform int uEnergy;
|
||||||
|
|
||||||
in vec2 texCoordVarying;
|
in vec2 texCoordVarying;
|
||||||
in vec3 gPos;
|
in vec3 gPos;
|
||||||
|
@ -114,7 +115,14 @@ void main()
|
||||||
float rate = 1-smoothstep(D - d, D + d, length(gPos.x + uBetween.x) + n);
|
float rate = 1-smoothstep(D - d, D + d, length(gPos.x + uBetween.x) + n);
|
||||||
rate *= uAreThereTwoPeopleTween;
|
rate *= uAreThereTwoPeopleTween;
|
||||||
vec3 remapedColor = mix(remapedColorC, remapedColorW, rate);
|
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) {
|
// if(vTemperature < 0.5) {
|
||||||
// alpha *= vTemperature * 2;
|
// alpha *= vTemperature * 2;
|
||||||
|
|
|
@ -8,6 +8,8 @@ uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
|
||||||
|
uniform int uEnergy;
|
||||||
|
|
||||||
// App specific uniforms and attributes.
|
// App specific uniforms and attributes.
|
||||||
// uniform float uSpriteSize;
|
// uniform float uSpriteSize;
|
||||||
|
|
||||||
|
@ -42,8 +44,16 @@ void main()
|
||||||
if(gAge >= 1) return;
|
if(gAge >= 1) return;
|
||||||
for (int i = 0; i < gl_in.length(); ++i)
|
for (int i = 0; i < gl_in.length(); ++i)
|
||||||
{
|
{
|
||||||
vec3 vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz) * (gAge * 5);
|
vec3 vOffset;
|
||||||
vOffset += normalize(vOffset) * 5;
|
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) {
|
// if(length(vOffset) < 4) {
|
||||||
// vOffset = normalize(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);
|
gl_Position = projectionMatrix * (shiftPos + vec4(0.0, 0.0, 0.0, 0.0) * uSpriteSize);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
if(gAge > 0 && gTarget.w > 0) {
|
// if(gAge > 0 && gTarget.w > 0) {
|
||||||
for(int j = 0; j < 3; j++) {
|
// for(int j = 0; j < 2; j++) {
|
||||||
gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize);
|
// gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize);
|
||||||
EmitVertex();
|
// EmitVertex();
|
||||||
gl_Position = projectionMatrix * (shiftPos + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize);
|
// gl_Position = projectionMatrix * (shiftPos + vec4(0.0, float(j+1), 0.0, 0.0) * uSpriteSize);
|
||||||
EmitVertex();
|
// EmitVertex();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { // arrived
|
if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { // arrived
|
||||||
age += 1;
|
age += 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wandering
|
// wandering
|
||||||
|
@ -216,7 +216,7 @@ void main()
|
||||||
if(target.w > 0) { // go to target
|
if(target.w > 0) { // go to target
|
||||||
float th = atan(-pos.y + target.y, -pos.x + target.x);
|
float th = atan(-pos.y + target.y, -pos.x + target.x);
|
||||||
float phi = atan(-pos.z + target.z, length(target.xy-pos.xy));
|
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);
|
phi += 3.1415 / 1 * simplex3d_fractal(pos.xyz * 0.01);
|
||||||
force.x = cos(th) * cos(phi);
|
force.x = cos(th) * cos(phi);
|
||||||
force.y = sin(th) * cos(phi);
|
force.y = sin(th) * cos(phi);
|
||||||
|
|
|
@ -160,6 +160,8 @@ void ofApp::setup()
|
||||||
|
|
||||||
fbos.insert({"ofcam", ofFbo()});
|
fbos.insert({"ofcam", ofFbo()});
|
||||||
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB);
|
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)
|
for (auto s : gradientNames)
|
||||||
{
|
{
|
||||||
|
@ -327,6 +329,7 @@ void ofApp::onParticlesDraw(ofxShader &shader)
|
||||||
shader.setUniform3f("uHottest3d1", hotspot3d1);
|
shader.setUniform3f("uHottest3d1", hotspot3d1);
|
||||||
shader.setUniform3f("uBetween", uBetween);
|
shader.setUniform3f("uBetween", uBetween);
|
||||||
shader.setUniform1f("uAreThereTwoPeopleTween", areThereTwoPeopleTween);
|
shader.setUniform1f("uAreThereTwoPeopleTween", areThereTwoPeopleTween);
|
||||||
|
shader.setUniform1i("uEnergy", uEnergy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ofApp::drawMain()
|
void ofApp::drawMain()
|
||||||
|
@ -335,6 +338,7 @@ void ofApp::drawMain()
|
||||||
auto tex = kinectDevice.getDepthTex();
|
auto tex = kinectDevice.getDepthTex();
|
||||||
boundShader.setUniformTexture("u_depth", tex);
|
boundShader.setUniformTexture("u_depth", tex);
|
||||||
boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam"));
|
boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam"));
|
||||||
|
boundShader.setUniformTexture("u_energy", fbos.at("energy"));
|
||||||
boundShader.setUniformTexture("u_v4l2cam", v4l2Buffer.at(v4l2BufferCount));
|
boundShader.setUniformTexture("u_v4l2cam", v4l2Buffer.at(v4l2BufferCount));
|
||||||
boundShader.setUniform1i("u_calib", calibMode == true ? 1 : 0);
|
boundShader.setUniform1i("u_calib", calibMode == true ? 1 : 0);
|
||||||
boundShader.setUniform2f("u_calibXY", registrationXY);
|
boundShader.setUniform2f("u_calibXY", registrationXY);
|
||||||
|
@ -360,6 +364,27 @@ void ofApp::draw()
|
||||||
particles.whateverImages.at("u_world") = kinectDevice.getDepthToWorldTex();
|
particles.whateverImages.at("u_world") = kinectDevice.getDepthToWorldTex();
|
||||||
particles.whateverImages.at("u_v4l2cam") = v4l2Buffer.at(v4l2BufferCount);
|
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();
|
fbos.at("ofcam").begin();
|
||||||
ofClear(0);
|
ofClear(0);
|
||||||
cam.begin();
|
cam.begin();
|
||||||
|
@ -372,6 +397,7 @@ void ofApp::draw()
|
||||||
{
|
{
|
||||||
ofEnableDepthTest();
|
ofEnableDepthTest();
|
||||||
}
|
}
|
||||||
|
uEnergy = 0;
|
||||||
particles.draw();
|
particles.draw();
|
||||||
if (blendAdd)
|
if (blendAdd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,6 +60,7 @@ private:
|
||||||
ofPixels v4l2Pixels;
|
ofPixels v4l2Pixels;
|
||||||
|
|
||||||
ofxGpuParticles particles;
|
ofxGpuParticles particles;
|
||||||
|
int uEnergy;
|
||||||
|
|
||||||
std::vector<std::vector<ofVec3f>> hotspots;
|
std::vector<std::vector<ofVec3f>> hotspots;
|
||||||
ofVec3f hotspot0, hotspot1;
|
ofVec3f hotspot0, hotspot1;
|
||||||
|
|
Loading…
Reference in a new issue