diff --git a/zoneb/bin/data/shaders/bound.frag b/zoneb/bin/data/shaders/bound.frag index 7bee519..75fc38d 100644 --- a/zoneb/bin/data/shaders/bound.frag +++ b/zoneb/bin/data/shaders/bound.frag @@ -3,6 +3,7 @@ precision mediump float; #endif uniform sampler2D u_depth; +uniform sampler2D u_ofcam; uniform sampler2D u_buffer0; uniform sampler2D u_buffer1; @@ -16,7 +17,7 @@ varying vec2 v_texcoord; float depthToSilhouette(float depth) { if(depth < 0.005) return 0; - if(depth > 0.1) return 0; + // if(depth > 0.1) return 0; else return 1; } @@ -47,7 +48,8 @@ void main() { // BUFFER_1 (u_buffer1) vec4 color = vec4(0,0,0,1); if(u_init) { - float tmp = texture2D(u_depth, st).r; + vec3 tmpc = texture2D(u_ofcam, st).rgb; + float tmp = tmpc.r + tmpc.g + tmpc.b; color.rgb = vec3(depthToSilhouette(tmp)); } else { @@ -84,9 +86,9 @@ void main() { #else // Main Buffer float buf1 = texture2D(u_buffer1, st).r; - vec3 dispColor = vec3(0, 0, 1); - dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st).r)); - + vec3 dispColor = vec3(0, 0, 0); + vec4 pointCloudColor = texture2D(u_ofcam, st); + float maxVal = buf1; float minVal = buf1; for (int i=0; i < 9; i++){ @@ -101,6 +103,8 @@ void main() { // dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st/u_resolution).r)); gl_FragColor = vec4(dispColor, 1.0); + gl_FragColor += pointCloudColor; // not good + #endif } \ No newline at end of file diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index 80645d0..ba828fd 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -40,6 +40,9 @@ void ofApp::setup() boundShader.allocate(ofGetWidth(), ofGetHeight()); boundShader.load("shaders/bound.frag"); + + fbos.insert({"ofcam", ofFbo()}); + fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB); } //-------------------------------------------------------------- @@ -60,17 +63,8 @@ void ofApp::draw() if (kinectDevice.isStreaming()) { - ofDisableDepthTest(); - auto tex = kinectDevice.getDepthTex(); - boundShader.setUniformTexture("u_depth", tex); - boundShader.setUniform1i("u_init", 1); - boundShader.render(); - boundShader.setUniform1i("u_init", 0); - for (int i = 0; i < 60; i++) { - boundShader.render(); - } - boundShader.draw(0, 0); - + fbos.at("ofcam").begin(); + ofClear(0); cam.begin(); ofEnableDepthTest(); @@ -107,6 +101,19 @@ void ofApp::draw() shader.end(); ofPopMatrix(); cam.end(); + fbos.at("ofcam").end(); + + ofDisableDepthTest(); + auto tex = kinectDevice.getDepthTex(); + boundShader.setUniformTexture("u_depth", tex); + boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam")); + boundShader.setUniform1i("u_init", 1); + boundShader.render(); + boundShader.setUniform1i("u_init", 0); + for (int i = 0; i < 60; i++) { + boundShader.render(); + } + boundShader.draw(0, 0); } ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20); diff --git a/zoneb/src/ofApp.h b/zoneb/src/ofApp.h index 600416b..0fe061b 100644 --- a/zoneb/src/ofApp.h +++ b/zoneb/src/ofApp.h @@ -34,6 +34,8 @@ private: ofxShader shader; ofxShaderFilter boundShader; + std::map fbos; + float pointSize; bool useColorSpace; };