bump ofxFluid to newer glsl

This commit is contained in:
micuat 2020-11-01 12:05:04 +01:00
parent 0124f6c2be
commit af3d2f354a
10 changed files with 212 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

View file

@ -0,0 +1,161 @@
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2DRect uFluid;
uniform sampler2DRect uDepth;
uniform sampler2DRect uV4l2cam;
uniform sampler2DRect u_buffer0;
uniform sampler2DRect u_buffer1;
uniform bool uCalib;
uniform vec2 uCalibXY;
uniform float uCalibScale;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
uniform bool u_init;
varying vec2 v_texcoord;
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
j *= .125;
r.y = fract(512.0*j);
return r-0.5;
}
/* skew constants for 3d simplex functions */
const float F3 = 0.3333333;
const float G3 = 0.1666667;
/* 3d simplex noise */
float simplex3d(vec3 p) {
/* 1. find current tetrahedron T and it's four vertices */
/* s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices */
/* x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices*/
/* calculate s and x */
vec3 s = floor(p + dot(p, vec3(F3)));
vec3 x = p - s + dot(s, vec3(G3));
/* calculate i1 and i2 */
vec3 e = step(vec3(0.0), x - x.yzx);
vec3 i1 = e*(1.0 - e.zxy);
vec3 i2 = 1.0 - e.zxy*(1.0 - e);
/* x1, x2, x3 */
vec3 x1 = x - i1 + G3;
vec3 x2 = x - i2 + 2.0*G3;
vec3 x3 = x - 1.0 + 3.0*G3;
/* 2. find four surflets and store them in d */
vec4 w, d;
/* calculate surflet weights */
w.x = dot(x, x);
w.y = dot(x1, x1);
w.z = dot(x2, x2);
w.w = dot(x3, x3);
/* w fades from 0.6 at the center of the surflet to 0.0 at the margin */
w = max(0.6 - w, 0.0);
/* calculate surflet components */
d.x = dot(random3(s), x);
d.y = dot(random3(s + i1), x1);
d.z = dot(random3(s + i2), x2);
d.w = dot(random3(s + 1.0), x3);
/* multiply d by w^4 */
w *= w;
w *= w;
d *= w;
/* 3. return the sum of the four surflets */
return dot(d, vec4(52.0));
}
/* const matrices for 3d rotation */
const mat3 rot1 = mat3(-0.37, 0.36, 0.85,-0.14,-0.93, 0.34,0.92, 0.01,0.4);
const mat3 rot2 = mat3(-0.55,-0.39, 0.74, 0.33,-0.91,-0.24,0.77, 0.12,0.63);
const mat3 rot3 = mat3(-0.71, 0.52,-0.47,-0.08,-0.72,-0.68,-0.7,-0.45,0.56);
/* directional artifacts can be reduced by rotating each octave */
float simplex3d_fractal(vec3 m) {
return 0.5333333*simplex3d(m*rot1)
+0.2666667*simplex3d(2.0*m*rot2)
+0.1333333*simplex3d(4.0*m*rot3)
+0.0666667*simplex3d(8.0*m);
}
float depthToSilhouette(float depth) {
if(depth <= 0.4) return 0;
// if(depth > 0.1) return 0;
else return 1;
}
void main() {
vec2 pixel = vec2(1.0);//./u_resolution;
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);
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,1,1);
// color = texture(u_buffer1, st);
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
//
vec4 color = vec4(1,0,0,1);
// color = texture(u_buffer0, st);
gl_FragColor = color;
#else
if (uCalib) {
vec4 depth = texture(uDepth, st);
depth.r *= 100;
depth.a = 0;
vec4 v4l2 = texture(uV4l2cam, st);
gl_FragColor = depth + v4l2;
}
else {
// vec4 bufColor = texture(u_buffer1, st);
vec4 color = vec4(st/1000,1,1);
color = texture(uFluid, st);
gl_FragColor = color;
}
#endif
}

View file

@ -3,11 +3,21 @@
//======================================================================== //========================================================================
int main( ){ int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context // 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
settings.setSize(1920, 1200);
#endif
ofCreateWindow(settings);
ofRunApp(new ofApp());
// this kicks off the running of my app }
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}

View file

@ -126,8 +126,15 @@ void ofApp::setup()
setupThermal(); setupThermal();
setupFluid(); setupFluid();
fbos.insert({"main", ofFbo()}); mainShader.allocate(ofGetWidth(), ofGetHeight());
fbos.at("main").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB); mainShader.load("shaders/main.frag");
std::vector<std::string> fboNames = {"main", "fluid"};
for (auto s : fboNames)
{
fbos.insert({s, ofFbo()});
fbos.at(s).allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB);
}
} }
ofVec3f ofApp::getDepthAt(int x, int y) ofVec3f ofApp::getDepthAt(int x, int y)
@ -227,12 +234,12 @@ void ofApp::updateFluid()
{ {
fluid.addColor(v4l2Buffer.at(v4l2BufferCount), 0.1f); fluid.addColor(v4l2Buffer.at(v4l2BufferCount), 0.1f);
ofPoint m = ofPoint(mouseX,mouseY); ofPoint m = ofPoint(mouseX, mouseY);
ofPoint d = (m - oldM)*10.0; ofPoint d = (m - oldM) * 10.0;
oldM = m; oldM = m;
ofPoint c = ofPoint(640*0.5, 480*0.5) - m; ofPoint c = ofPoint(640 * 0.5, 480 * 0.5) - m;
c.normalize(); c.normalize();
fluid.addTemporalForce(m, d, ofFloatColor(0)*sin(ofGetElapsedTimef()),15.0f,20); fluid.addTemporalForce(toGlm(m), toGlm(d), ofFloatColor(0,0,0), 15.0f, 20);
// Update // Update
// //
@ -272,9 +279,25 @@ void ofApp::update()
void ofApp::drawMain() void ofApp::drawMain()
{ {
ofBackgroundGradient(ofColor::gray, ofColor::black, OF_GRADIENT_LINEAR); // ofBackgroundGradient(ofColor::gray, ofColor::black, OF_GRADIENT_LINEAR);
fbos.at("fluid").begin();
ofClear(0);
fluid.draw(); fluid.draw();
fbos.at("fluid").end();
// fbos.at("fluid").draw(0, 0);
auto tex = kinectDevice.getDepthTex();
mainShader.setUniformTexture("uDepth", tex);
mainShader.setUniformTexture("uV4l2cam", v4l2Buffer.at(v4l2BufferCount));
mainShader.setUniform1i("uCalib", calibMode == true ? 1 : 0);
mainShader.setUniform2f("uCalibXY", registrationXY);
mainShader.setUniform1f("uCalibScale", registrationScale);
mainShader.setUniformTexture("uFluid", fbos.at("fluid"));
mainShader.render();
mainShader.draw(0, 0);
} }
void ofApp::drawDebug() void ofApp::drawDebug()
@ -289,57 +312,46 @@ void ofApp::draw()
drawDebug(); drawDebug();
} }
void ofApp::keyPressed(int key) void ofApp::keyPressed(int key)
{ {
} }
void ofApp::keyReleased(int key) void ofApp::keyReleased(int key)
{ {
} }
void ofApp::mouseMoved(int x, int y) void ofApp::mouseMoved(int x, int y)
{ {
} }
void ofApp::mouseDragged(int x, int y, int button) void ofApp::mouseDragged(int x, int y, int button)
{ {
} }
void ofApp::mousePressed(int x, int y, int button) void ofApp::mousePressed(int x, int y, int button)
{ {
} }
void ofApp::mouseReleased(int x, int y, int button) void ofApp::mouseReleased(int x, int y, int button)
{ {
} }
void ofApp::mouseEntered(int x, int y) void ofApp::mouseEntered(int x, int y)
{ {
} }
void ofApp::mouseExited(int x, int y) void ofApp::mouseExited(int x, int y)
{ {
} }
void ofApp::windowResized(int w, int h) void ofApp::windowResized(int w, int h)
{ {
} }
void ofApp::gotMessage(ofMessage msg) void ofApp::gotMessage(ofMessage msg)
{ {
} }
void ofApp::dragEvent(ofDragInfo dragInfo) void ofApp::dragEvent(ofDragInfo dragInfo)
{ {
} }

View file

@ -2,6 +2,7 @@
#include "ofMain.h" #include "ofMain.h"
#include "ofxGui.h" #include "ofxGui.h"
#include "ofxShaderFilter.h"
#include "ofxAzureKinect.h" #include "ofxAzureKinect.h"
#include "ofxFluid.h" #include "ofxFluid.h"
#include "ofxV4L2.h" #include "ofxV4L2.h"
@ -40,6 +41,8 @@ public:
std::map<string, ofFloatImage> gradients; std::map<string, ofFloatImage> gradients;
std::vector<std::string> gradientNames{"warm1", "warm2", "cold1", "cold2"}; std::vector<std::string> gradientNames{"warm1", "warm2", "cold1", "cold2"};
ofxShaderFilter mainShader;
ofxAzureKinect::Device kinectDevice; ofxAzureKinect::Device kinectDevice;
ofxFluid fluid; ofxFluid fluid;