boundary on point cloud (weirdly chopped from last commit)

This commit is contained in:
micuat 2020-10-19 10:46:36 +02:00
parent 8adda60cab
commit 6de7bb89a2
3 changed files with 29 additions and 16 deletions

View file

@ -3,6 +3,7 @@ precision mediump float;
#endif #endif
uniform sampler2D u_depth; uniform sampler2D u_depth;
uniform sampler2D u_ofcam;
uniform sampler2D u_buffer0; uniform sampler2D u_buffer0;
uniform sampler2D u_buffer1; uniform sampler2D u_buffer1;
@ -16,7 +17,7 @@ varying vec2 v_texcoord;
float depthToSilhouette(float depth) { float depthToSilhouette(float depth) {
if(depth < 0.005) return 0; if(depth < 0.005) return 0;
if(depth > 0.1) return 0; // if(depth > 0.1) return 0;
else return 1; else return 1;
} }
@ -47,7 +48,8 @@ void main() {
// BUFFER_1 (u_buffer1) // BUFFER_1 (u_buffer1)
vec4 color = vec4(0,0,0,1); vec4 color = vec4(0,0,0,1);
if(u_init) { 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)); color.rgb = vec3(depthToSilhouette(tmp));
} }
else { else {
@ -84,8 +86,8 @@ void main() {
#else #else
// Main Buffer // Main Buffer
float buf1 = texture2D(u_buffer1, st).r; float buf1 = texture2D(u_buffer1, st).r;
vec3 dispColor = vec3(0, 0, 1); vec3 dispColor = vec3(0, 0, 0);
dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st).r)); vec4 pointCloudColor = texture2D(u_ofcam, st);
float maxVal = buf1; float maxVal = buf1;
float minVal = buf1; float minVal = buf1;
@ -101,6 +103,8 @@ void main() {
// dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st/u_resolution).r)); // dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st/u_resolution).r));
gl_FragColor = vec4(dispColor, 1.0); gl_FragColor = vec4(dispColor, 1.0);
gl_FragColor += pointCloudColor; // not good
#endif #endif
} }

View file

@ -40,6 +40,9 @@ void ofApp::setup()
boundShader.allocate(ofGetWidth(), ofGetHeight()); boundShader.allocate(ofGetWidth(), ofGetHeight());
boundShader.load("shaders/bound.frag"); 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()) if (kinectDevice.isStreaming())
{ {
ofDisableDepthTest(); fbos.at("ofcam").begin();
auto tex = kinectDevice.getDepthTex(); ofClear(0);
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);
cam.begin(); cam.begin();
ofEnableDepthTest(); ofEnableDepthTest();
@ -107,6 +101,19 @@ void ofApp::draw()
shader.end(); shader.end();
ofPopMatrix(); ofPopMatrix();
cam.end(); 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); ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);

View file

@ -34,6 +34,8 @@ private:
ofxShader shader; ofxShader shader;
ofxShaderFilter boundShader; ofxShaderFilter boundShader;
std::map<string, ofFbo> fbos;
float pointSize; float pointSize;
bool useColorSpace; bool useColorSpace;
}; };