From ea8d680277fd4626008ee9acc5ae2ca77322e2de Mon Sep 17 00:00:00 2001 From: micuat Date: Tue, 20 Oct 2020 11:16:21 +0200 Subject: [PATCH] whatever --- zoneb/bin/data/shaders/bound.frag | 2 +- zoneb/bin/data/shaders/particle.frag | 27 +++++++++++++++++++++------ zoneb/bin/data/shaders/render.frag | 3 ++- zoneb/bin/data/shaders/render.geom | 4 ++++ zoneb/bin/data/shaders/render.vert | 9 +++++++-- zoneb/src/ofApp.cpp | 3 ++- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/zoneb/bin/data/shaders/bound.frag b/zoneb/bin/data/shaders/bound.frag index 36238ff..677b88b 100644 --- a/zoneb/bin/data/shaders/bound.frag +++ b/zoneb/bin/data/shaders/bound.frag @@ -105,7 +105,7 @@ void main() { // dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st/u_resolution).r)); gl_FragColor = vec4(dispColor, 1.0); gl_FragColor += pointCloudColor; // not good - gl_FragColor = pointCloudColor; // not good + gl_FragColor = vec4(pointCloudColor.rgb, 1.0); // not good // gl_FragColor = texture2D(u_v4l2cam, st/3); diff --git a/zoneb/bin/data/shaders/particle.frag b/zoneb/bin/data/shaders/particle.frag index 05075d3..606a846 100644 --- a/zoneb/bin/data/shaders/particle.frag +++ b/zoneb/bin/data/shaders/particle.frag @@ -4,6 +4,7 @@ precision mediump float; uniform sampler2D u_depth; uniform sampler2D u_world; +uniform sampler2D u_v4l2cam; uniform ivec2 uFrameSize; uniform ivec2 uDepthFrameSize; @@ -117,6 +118,18 @@ void main() { if(depth < 0.012) vValid = 0; if(depth > 0.04) vValid = 0; + vec2 v4l2st = st; + v4l2st /= 3; + v4l2st -= vec2(0.5); + v4l2st *= 1.45; + v4l2st += vec2(0.5); + v4l2st.s += 0.15; + v4l2st.t += 0.16; + float thermo = texture2D(u_v4l2cam, v4l2st).r; + + vec4 pos = texture2D(u_buffer1, st); + float age = pos.w;//mod(pos.w, 100); + float lastThermo = floor(pos.w / 100); if(vValid == 1 && mod(u_time * 3 + random3(vec3(v_texcoord, 0)).r, 1.0) < 0.5) { vec4 posWorld = vec4(1); @@ -127,19 +140,21 @@ void main() { // Flip X as OpenGL and K4A have different conventions on which direction is positive. posWorld.x *= -1; - // float tmp = mix(texture2D(u_depth, st).r, texture2D(u_buffer1, st).r, 0.9); // color = vec4(vec3(tmp), 1.0); color.rgb = posWorld.rgb; - color.a = vValid; + // color.a = thermo * 100;//vValid; + color.a = 0.1; } else { - vec4 pos = texture2D(u_buffer1, st); - float th = 3.1415 * 4 * simplex3d_fractal(pos.xyz * 0.001); + float th = 3.1415 * 4 * simplex3d_fractal(vec3(pos.xyz * 0.001 + vec3(0, 0, u_time * 0.01))); float phi = 3.1415 * simplex3d_fractal(pos.xyz * 0.002); pos.x += cos(th) * cos(phi) * 7; pos.y += sin(th) * cos(phi) * 7; pos.z += sin(phi) * 7; + // age = min(1, age + 0.01); + pos.w = age; + color = pos; } @@ -154,8 +169,8 @@ void main() { gl_FragColor = texture2D(u_buffer0, st); #else // Main Buffer - vec3 buf1 = texture2D(u_buffer1, st).rgb; - gl_FragColor = vec4(buf1, 1.0); + vec4 buf1 = texture2D(u_buffer1, st); + gl_FragColor = buf1; #endif diff --git a/zoneb/bin/data/shaders/render.frag b/zoneb/bin/data/shaders/render.frag index 883e5d3..ab9d39e 100644 --- a/zoneb/bin/data/shaders/render.frag +++ b/zoneb/bin/data/shaders/render.frag @@ -10,6 +10,7 @@ uniform sampler2D u_gradient; uniform sampler2D u_particle; in vec2 gTexCoord; +in float gTemperature; void main() { @@ -20,7 +21,7 @@ void main() st += vec2(0.5); st.s += 0.15; st.t += 0.16; - float thermo = texture2D(u_v4l2cam, st).r; + float thermo = gTemperature;//texture2D(u_v4l2cam, st).r; gl_FragColor = vec4(texture2D(u_gradient, vec2(thermo, 0.5)).rgb, 1); // gl_FragColor = texture2D(u_particle, gTexCoord); // gl_FragColor = vec4(1); diff --git a/zoneb/bin/data/shaders/render.geom b/zoneb/bin/data/shaders/render.geom index 1e61044..1edb035 100644 --- a/zoneb/bin/data/shaders/render.geom +++ b/zoneb/bin/data/shaders/render.geom @@ -16,6 +16,9 @@ in vec4 vPosition[]; in vec2 vTexCoord[]; flat in int vValid[]; +in float vTemperature[]; +out float gTemperature; + out vec2 gTexCoord; void main() @@ -23,6 +26,7 @@ void main() if (vValid[0] == 0) return; gTexCoord = vTexCoord[0]; + gTemperature = vTemperature[0]; for (int i = 0; i < gl_in.length(); ++i) { diff --git a/zoneb/bin/data/shaders/render.vert b/zoneb/bin/data/shaders/render.vert index 82cbe6e..c40cb06 100644 --- a/zoneb/bin/data/shaders/render.vert +++ b/zoneb/bin/data/shaders/render.vert @@ -21,6 +21,8 @@ out vec4 vPosition; out vec2 vTexCoord; flat out int vValid; +out float vTemperature; + void main() { vTexCoord = vec2(gl_InstanceID % uFrameSize.x, gl_InstanceID / uFrameSize.x) / uDepthFrameSize; @@ -29,8 +31,11 @@ void main() // vValid = (depth != 0 && ray.x != 0 && ray.y != 0) ? 1 : 0; - vec4 posWorld = vec4(1); - posWorld = texture2D(u_particle, vTexCoord); + vec4 posWorld = texture2D(u_particle, vTexCoord); + + vTemperature = posWorld.w; + + posWorld.w = 1; // posWorld.xyz *= 65535; // // posWorld.xy = vTexCoord * 10000; diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index c9764c5..1758a96 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -69,7 +69,7 @@ void ofApp::setup() boundShader.load("shaders/bound.frag"); fbos.insert({"ofcam", ofFbo()}); - fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB); + fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB); gradient.load("gradient.png"); } @@ -162,6 +162,7 @@ void ofApp::draw() auto wtex = kinectDevice.getDepthToWorldTex(); particleShader.setUniformTexture("u_depth", dtex); particleShader.setUniformTexture("u_world", wtex); + particleShader.setUniformTexture("u_v4l2cam", v4l2Tex); particleShader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight()); particleShader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight()); particleShader.render();