From 7ebba10385e79add797e395ecdb971a31d2f5c4b Mon Sep 17 00:00:00 2001 From: micuat Date: Sun, 18 Oct 2020 15:25:49 +0200 Subject: [PATCH] dilate test --- zoneb/addons.make | 1 + zoneb/bin/data/shaders/bound.frag | 94 +++++++++++++++++++++++++++++++ zoneb/src/main.cpp | 27 ++++++--- zoneb/src/ofApp.cpp | 71 ++++++++++++++--------- zoneb/src/ofApp.h | 4 +- 5 files changed, 160 insertions(+), 37 deletions(-) create mode 100644 zoneb/bin/data/shaders/bound.frag diff --git a/zoneb/addons.make b/zoneb/addons.make index b155bef..0b31261 100644 --- a/zoneb/addons.make +++ b/zoneb/addons.make @@ -1 +1,2 @@ ofxAzureKinect +ofxShader diff --git a/zoneb/bin/data/shaders/bound.frag b/zoneb/bin/data/shaders/bound.frag new file mode 100644 index 0000000..d8dec0b --- /dev/null +++ b/zoneb/bin/data/shaders/bound.frag @@ -0,0 +1,94 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D u_depth; +uniform sampler2D u_buffer0; +uniform sampler2D u_buffer1; + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +uniform bool u_init; + +varying vec2 v_texcoord; + +void main() { + vec2 st = v_texcoord; + // st.y = 1.0 - st.y; + + +#ifdef BUFFER_0 + // PING BUFFER + // + // Note: Here is where most of the action happens. But need's to read + // te content of the previous pass, for that we are making another buffer + // BUFFER_1 (u_buffer1) + vec4 color = vec4(0,0,0,1); + if(u_init) { + float tmp = texture2D(u_depth, st).r; + if(tmp > 0.005) { + color.rgb = vec3(1); + } + } + else { + vec2 pixel = 1./u_resolution; + + float kernel[9]; + kernel[0] = 0.125; + kernel[1] = 0.25; + kernel[2] = 0.125; + kernel[3] = 0.25; + kernel[4] = 1.0; + kernel[5] = 0.25; + kernel[6] = 0.125; + kernel[7] = 0.25; + kernel[8] = 0.125; + + vec2 offset[9]; + offset[0] = pixel * vec2(-1.0,-1.0); + offset[1] = pixel * vec2( 0.0,-1.0); + offset[2] = pixel * vec2( 1.0,-1.0); + + offset[3] = pixel * vec2(-1.0,0.0); + offset[4] = pixel * vec2( 0.0,0.0); + offset[5] = pixel * vec2( 1.0,0.0); + + offset[6] = pixel * vec2(-1.0,1.0); + offset[7] = pixel * vec2( 0.0,1.0); + offset[8] = pixel * vec2( 1.0,1.0); + + float lap = 0; + + for (int i=0; i < 9; i++){ + float tmp = texture2D(u_buffer1, st + offset[i]).r; + // lap += tmp * kernel[i] / 2.5; + if(tmp > 0.005) { + color.rgb = vec3(1); + } + } + } + + gl_FragColor = color; + +#elif defined( BUFFER_1 ) + // PONG BUFFER + // + // Note: Just copy the content of the BUFFER0 so it can be + // read by it in the next frame + // + gl_FragColor = texture2D(u_buffer0, st); +#else + // Main Buffer + vec3 dispColor = vec3(0, 0, 1); + dispColor.r = texture2D(u_depth, st).r > 0.005 ? 1 : 0; + dispColor.g = texture2D(u_buffer1, st).r; + // color.r = 1.; + gl_FragColor = vec4(dispColor, 1.0); + + + // gl_FragColor = color; +#endif + +} \ No newline at end of file diff --git a/zoneb/src/main.cpp b/zoneb/src/main.cpp index f74d4cf..6c48ca5 100644 --- a/zoneb/src/main.cpp +++ b/zoneb/src/main.cpp @@ -1,11 +1,22 @@ +#include "ofMain.h" #include "ofApp.h" -int main() -{ - ofGLFWWindowSettings settings; - settings.setGLVersion(3, 2); - settings.setSize(1280, 720); - ofCreateWindow(settings); +//======================================================================== +int main( ){ + // ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + +#ifdef TARGET_OPENGLES + ofGLESWindowSettings settings; + settings.setGLESVersion(2); +#else + ofGLWindowSettings settings; + settings.setGLVersion(3, 2); // Programmable pipeline +#endif + ofCreateWindow(settings); + ofRunApp(new ofApp()); - ofRunApp(new ofApp()); -} +} \ No newline at end of file diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index 27235c4..cfdfc7b 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -3,19 +3,20 @@ //-------------------------------------------------------------- void ofApp::setup() { + ofDisableArbTex(); //ofSetLogLevel(OF_LOG_VERBOSE); ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices."; // Open Kinect. - if (this->kinectDevice.open()) + if (kinectDevice.open()) { auto kinectSettings = ofxAzureKinect::DeviceSettings(); kinectSettings.updateIr = false; kinectSettings.updateColor = true; kinectSettings.colorResolution = K4A_COLOR_RESOLUTION_1080P; kinectSettings.updateVbo = false; - this->kinectDevice.startCameras(kinectSettings); + kinectDevice.startCameras(kinectSettings); } // Load shader. @@ -24,23 +25,26 @@ void ofApp::setup() shaderSettings.shaderFiles[GL_GEOMETRY_SHADER] = "shaders/render.geom"; shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag"; shaderSettings.bindDefaults = true; - if (this->shader.setup(shaderSettings)) + if (shader.setup(shaderSettings)) { ofLogNotice(__FUNCTION__) << "Success loading shader!"; } // Setup vbo. std::vector verts(1); - this->vbo.setVertexData(verts.data(), verts.size(), GL_STATIC_DRAW); + vbo.setVertexData(verts.data(), verts.size(), GL_STATIC_DRAW); - this->pointSize = 1.0f; - this->useColorSpace = false; + pointSize = 1.0f; + useColorSpace = false; + + boundShader.allocate(ofGetWidth(), ofGetHeight()); + boundShader.load("shaders/bound.frag"); } //-------------------------------------------------------------- void ofApp::exit() { - this->kinectDevice.close(); + kinectDevice.close(); } //-------------------------------------------------------------- @@ -53,9 +57,20 @@ void ofApp::draw() { ofBackground(0); - if (this->kinectDevice.isStreaming()) + if (kinectDevice.isStreaming()) { - this->cam.begin(); + 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); + return; + + cam.begin(); ofEnableDepthTest(); ofDrawAxis(100.0f); @@ -63,34 +78,34 @@ void ofApp::draw() ofPushMatrix(); ofRotateXDeg(180); - this->shader.begin(); - this->shader.setUniform1f("uSpriteSize", this->pointSize); + shader.begin(); + shader.setUniform1f("uSpriteSize", pointSize); int numPoints; - if (this->useColorSpace) + if (useColorSpace) { - this->shader.setUniformTexture("uDepthTex", this->kinectDevice.getDepthInColorTex(), 1); - this->shader.setUniformTexture("uWorldTex", this->kinectDevice.getColorToWorldTex(), 2); - this->shader.setUniformTexture("uColorTex", this->kinectDevice.getColorTex(), 3); - this->shader.setUniform2i("uFrameSize", this->kinectDevice.getColorTex().getWidth(), this->kinectDevice.getColorTex().getHeight()); + shader.setUniformTexture("uDepthTex", kinectDevice.getDepthInColorTex(), 1); + shader.setUniformTexture("uWorldTex", kinectDevice.getColorToWorldTex(), 2); + shader.setUniformTexture("uColorTex", kinectDevice.getColorTex(), 3); + shader.setUniform2i("uFrameSize", kinectDevice.getColorTex().getWidth(), kinectDevice.getColorTex().getHeight()); - numPoints = this->kinectDevice.getColorTex().getWidth() * this->kinectDevice.getColorTex().getHeight(); + numPoints = kinectDevice.getColorTex().getWidth() * kinectDevice.getColorTex().getHeight(); } else { - this->shader.setUniformTexture("uDepthTex", this->kinectDevice.getDepthTex(), 1); - this->shader.setUniformTexture("uWorldTex", this->kinectDevice.getDepthToWorldTex(), 2); - this->shader.setUniformTexture("uColorTex", this->kinectDevice.getColorInDepthTex(), 3); - this->shader.setUniform2i("uFrameSize", this->kinectDevice.getDepthTex().getWidth(), this->kinectDevice.getDepthTex().getHeight()); + shader.setUniformTexture("uDepthTex", kinectDevice.getDepthTex(), 1); + shader.setUniformTexture("uWorldTex", kinectDevice.getDepthToWorldTex(), 2); + shader.setUniformTexture("uColorTex", kinectDevice.getColorInDepthTex(), 3); + shader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight()); - numPoints = this->kinectDevice.getDepthTex().getWidth() * this->kinectDevice.getDepthTex().getHeight(); + numPoints = kinectDevice.getDepthTex().getWidth() * kinectDevice.getDepthTex().getHeight(); } - this->vbo.drawInstanced(GL_POINTS, 0, 1, numPoints); - this->shader.end(); + vbo.drawInstanced(GL_POINTS, 0, 1, numPoints); + shader.end(); ofPopMatrix(); - this->cam.end(); + cam.end(); } ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20); @@ -101,15 +116,15 @@ void ofApp::keyPressed(int key) { if (key == OF_KEY_UP) { - this->pointSize *= 2; + pointSize *= 2; } else if (key == OF_KEY_DOWN) { - this->pointSize /= 2; + pointSize /= 2; } else if (key == ' ') { - this->useColorSpace ^= 1; + useColorSpace ^= 1; } } diff --git a/zoneb/src/ofApp.h b/zoneb/src/ofApp.h index ddcc4e1..600416b 100644 --- a/zoneb/src/ofApp.h +++ b/zoneb/src/ofApp.h @@ -3,6 +3,7 @@ #include "ofMain.h" #include "ofxAzureKinect.h" +#include "ofxShaderFilter.h" class ofApp : public ofBaseApp @@ -30,7 +31,8 @@ private: ofxAzureKinect::Device kinectDevice; ofEasyCam cam; ofVbo vbo; - ofShader shader; + ofxShader shader; + ofxShaderFilter boundShader; float pointSize; bool useColorSpace;