dilate test
This commit is contained in:
parent
26e86edebf
commit
7ebba10385
5 changed files with 160 additions and 37 deletions
|
@ -1 +1,2 @@
|
||||||
ofxAzureKinect
|
ofxAzureKinect
|
||||||
|
ofxShader
|
||||||
|
|
94
zoneb/bin/data/shaders/bound.frag
Normal file
94
zoneb/bin/data/shaders/bound.frag
Normal file
|
@ -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
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,22 @@
|
||||||
|
#include "ofMain.h"
|
||||||
#include "ofApp.h"
|
#include "ofApp.h"
|
||||||
|
|
||||||
int main()
|
//========================================================================
|
||||||
{
|
int main( ){
|
||||||
ofGLFWWindowSettings settings;
|
// ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
|
||||||
settings.setGLVersion(3, 2);
|
|
||||||
settings.setSize(1280, 720);
|
|
||||||
ofCreateWindow(settings);
|
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,19 +3,20 @@
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::setup()
|
void ofApp::setup()
|
||||||
{
|
{
|
||||||
|
ofDisableArbTex();
|
||||||
//ofSetLogLevel(OF_LOG_VERBOSE);
|
//ofSetLogLevel(OF_LOG_VERBOSE);
|
||||||
|
|
||||||
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
|
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
|
||||||
|
|
||||||
// Open Kinect.
|
// Open Kinect.
|
||||||
if (this->kinectDevice.open())
|
if (kinectDevice.open())
|
||||||
{
|
{
|
||||||
auto kinectSettings = ofxAzureKinect::DeviceSettings();
|
auto kinectSettings = ofxAzureKinect::DeviceSettings();
|
||||||
kinectSettings.updateIr = false;
|
kinectSettings.updateIr = false;
|
||||||
kinectSettings.updateColor = true;
|
kinectSettings.updateColor = true;
|
||||||
kinectSettings.colorResolution = K4A_COLOR_RESOLUTION_1080P;
|
kinectSettings.colorResolution = K4A_COLOR_RESOLUTION_1080P;
|
||||||
kinectSettings.updateVbo = false;
|
kinectSettings.updateVbo = false;
|
||||||
this->kinectDevice.startCameras(kinectSettings);
|
kinectDevice.startCameras(kinectSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load shader.
|
// Load shader.
|
||||||
|
@ -24,23 +25,26 @@ void ofApp::setup()
|
||||||
shaderSettings.shaderFiles[GL_GEOMETRY_SHADER] = "shaders/render.geom";
|
shaderSettings.shaderFiles[GL_GEOMETRY_SHADER] = "shaders/render.geom";
|
||||||
shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag";
|
shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag";
|
||||||
shaderSettings.bindDefaults = true;
|
shaderSettings.bindDefaults = true;
|
||||||
if (this->shader.setup(shaderSettings))
|
if (shader.setup(shaderSettings))
|
||||||
{
|
{
|
||||||
ofLogNotice(__FUNCTION__) << "Success loading shader!";
|
ofLogNotice(__FUNCTION__) << "Success loading shader!";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup vbo.
|
// Setup vbo.
|
||||||
std::vector<glm::vec3> verts(1);
|
std::vector<glm::vec3> 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;
|
pointSize = 1.0f;
|
||||||
this->useColorSpace = false;
|
useColorSpace = false;
|
||||||
|
|
||||||
|
boundShader.allocate(ofGetWidth(), ofGetHeight());
|
||||||
|
boundShader.load("shaders/bound.frag");
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::exit()
|
void ofApp::exit()
|
||||||
{
|
{
|
||||||
this->kinectDevice.close();
|
kinectDevice.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
@ -53,9 +57,20 @@ void ofApp::draw()
|
||||||
{
|
{
|
||||||
ofBackground(0);
|
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();
|
ofEnableDepthTest();
|
||||||
|
|
||||||
ofDrawAxis(100.0f);
|
ofDrawAxis(100.0f);
|
||||||
|
@ -63,34 +78,34 @@ void ofApp::draw()
|
||||||
ofPushMatrix();
|
ofPushMatrix();
|
||||||
ofRotateXDeg(180);
|
ofRotateXDeg(180);
|
||||||
|
|
||||||
this->shader.begin();
|
shader.begin();
|
||||||
this->shader.setUniform1f("uSpriteSize", this->pointSize);
|
shader.setUniform1f("uSpriteSize", pointSize);
|
||||||
|
|
||||||
int numPoints;
|
int numPoints;
|
||||||
|
|
||||||
if (this->useColorSpace)
|
if (useColorSpace)
|
||||||
{
|
{
|
||||||
this->shader.setUniformTexture("uDepthTex", this->kinectDevice.getDepthInColorTex(), 1);
|
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthInColorTex(), 1);
|
||||||
this->shader.setUniformTexture("uWorldTex", this->kinectDevice.getColorToWorldTex(), 2);
|
shader.setUniformTexture("uWorldTex", kinectDevice.getColorToWorldTex(), 2);
|
||||||
this->shader.setUniformTexture("uColorTex", this->kinectDevice.getColorTex(), 3);
|
shader.setUniformTexture("uColorTex", kinectDevice.getColorTex(), 3);
|
||||||
this->shader.setUniform2i("uFrameSize", this->kinectDevice.getColorTex().getWidth(), this->kinectDevice.getColorTex().getHeight());
|
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
|
else
|
||||||
{
|
{
|
||||||
this->shader.setUniformTexture("uDepthTex", this->kinectDevice.getDepthTex(), 1);
|
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthTex(), 1);
|
||||||
this->shader.setUniformTexture("uWorldTex", this->kinectDevice.getDepthToWorldTex(), 2);
|
shader.setUniformTexture("uWorldTex", kinectDevice.getDepthToWorldTex(), 2);
|
||||||
this->shader.setUniformTexture("uColorTex", this->kinectDevice.getColorInDepthTex(), 3);
|
shader.setUniformTexture("uColorTex", kinectDevice.getColorInDepthTex(), 3);
|
||||||
this->shader.setUniform2i("uFrameSize", this->kinectDevice.getDepthTex().getWidth(), this->kinectDevice.getDepthTex().getHeight());
|
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);
|
vbo.drawInstanced(GL_POINTS, 0, 1, numPoints);
|
||||||
this->shader.end();
|
shader.end();
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
this->cam.end();
|
cam.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
|
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
|
||||||
|
@ -101,15 +116,15 @@ void ofApp::keyPressed(int key)
|
||||||
{
|
{
|
||||||
if (key == OF_KEY_UP)
|
if (key == OF_KEY_UP)
|
||||||
{
|
{
|
||||||
this->pointSize *= 2;
|
pointSize *= 2;
|
||||||
}
|
}
|
||||||
else if (key == OF_KEY_DOWN)
|
else if (key == OF_KEY_DOWN)
|
||||||
{
|
{
|
||||||
this->pointSize /= 2;
|
pointSize /= 2;
|
||||||
}
|
}
|
||||||
else if (key == ' ')
|
else if (key == ' ')
|
||||||
{
|
{
|
||||||
this->useColorSpace ^= 1;
|
useColorSpace ^= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
|
|
||||||
#include "ofxAzureKinect.h"
|
#include "ofxAzureKinect.h"
|
||||||
|
#include "ofxShaderFilter.h"
|
||||||
|
|
||||||
class ofApp
|
class ofApp
|
||||||
: public ofBaseApp
|
: public ofBaseApp
|
||||||
|
@ -30,7 +31,8 @@ private:
|
||||||
ofxAzureKinect::Device kinectDevice;
|
ofxAzureKinect::Device kinectDevice;
|
||||||
ofEasyCam cam;
|
ofEasyCam cam;
|
||||||
ofVbo vbo;
|
ofVbo vbo;
|
||||||
ofShader shader;
|
ofxShader shader;
|
||||||
|
ofxShaderFilter boundShader;
|
||||||
|
|
||||||
float pointSize;
|
float pointSize;
|
||||||
bool useColorSpace;
|
bool useColorSpace;
|
||||||
|
|
Loading…
Reference in a new issue