diff --git a/zoneb/bin/data/cold1.png b/zoneb/bin/data/cold1.png new file mode 100644 index 0000000..d589f2a Binary files /dev/null and b/zoneb/bin/data/cold1.png differ diff --git a/zoneb/bin/data/cold2.png b/zoneb/bin/data/cold2.png new file mode 100644 index 0000000..391f647 Binary files /dev/null and b/zoneb/bin/data/cold2.png differ diff --git a/zoneb/bin/data/shaders/particles/draw.frag b/zoneb/bin/data/shaders/particles/draw.frag index 4961d68..346fc48 100755 --- a/zoneb/bin/data/shaders/particles/draw.frag +++ b/zoneb/bin/data/shaders/particles/draw.frag @@ -5,7 +5,10 @@ uniform sampler2DRect particles2; uniform sampler2DRect u_depth; uniform sampler2DRect u_world; uniform sampler2DRect u_v4l2cam; -uniform sampler2DRect imageTexture; +uniform sampler2DRect warm1; +uniform sampler2DRect warm2; +uniform sampler2DRect cold1; +uniform sampler2DRect cold2; uniform vec3 uHottest0; uniform vec3 uHottest1; @@ -17,15 +20,93 @@ in vec3 vPos; in float vTemperature; in float vAge; + +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); +} + void main() { - vec3 remapedColor = texture(imageTexture, vec2(vTemperature*1600, 0.5)).xyz; + vec2 palette = vec2(vTemperature*3425, 0.5); + vec3 remapedColorW = texture(warm1, palette).xyz; + vec3 remapedColorC = texture(cold2, palette).xyz; + float d = 50; + float rate = smoothstep(500 - d, 500 + d, length(vPos.x - uHottest3d1.x) + simplex3d(vPos * vec3(0.001, 0.001, 0.1)) * 100); + vec3 remapedColor = mix(remapedColorW, remapedColorC, rate); float alpha = max(0, 1 - pow(vAge,4)); vec4 color = vec4(remapedColor, alpha); - if(length(vPos.x - uHottest3d1.x) < 500) { - color = vec4(0,1,0,1); - } fragColor = color; } diff --git a/zoneb/bin/data/warm1.png b/zoneb/bin/data/warm1.png new file mode 100644 index 0000000..3d798c1 Binary files /dev/null and b/zoneb/bin/data/warm1.png differ diff --git a/zoneb/bin/data/warm2.png b/zoneb/bin/data/warm2.png new file mode 100644 index 0000000..2bcb854 Binary files /dev/null and b/zoneb/bin/data/warm2.png differ diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index 2251dd6..c979eec 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -109,7 +109,11 @@ void ofApp::setupParticles() particles.whateverImages.insert({"u_depth", kinectDevice.getDepthTex()}); particles.whateverImages.insert({"u_world", kinectDevice.getDepthToWorldTex()}); particles.whateverImages.insert({"u_v4l2cam", v4l2Tex}); - particles.whateverImages.insert({"imageTexture", gradient.getTexture()}); + + for (auto i : gradients) + { + particles.whateverImages.insert({i.first, i.second.getTexture()}); + } // listen for update event to set additonal update uniforms ofAddListener(particles.updateEvent, this, &ofApp::onParticlesUpdate); @@ -126,7 +130,7 @@ void ofApp::setupGui() gui.setPosition(10, 10); debugGui.setup("DEBUG"); - debugGui.add(dummyMode.setup("dummy", true)); // should be false + debugGui.add(dummyMode.setup("dummy", true)); // should be false debugGui.add(dummyXY.setup("XY", {256, 256}, {0, 0}, {511, 511})); // should be false debugGui.add(debugFps.setup("FPS", "0")); debugGui.setPosition(230, 10); @@ -148,8 +152,11 @@ void ofApp::setup() fbos.insert({"ofcam", ofFbo()}); fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB); - gradient.load("gradient.jpg"); - + for (auto s : gradientNames) + { + gradients.insert({s, ofFloatImage()}); + gradients.at(s).load(s + ".png"); + } setupParticles(); } @@ -281,7 +288,6 @@ void ofApp::drawMain() boundShader.setUniformTexture("u_depth", tex); boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam")); boundShader.setUniformTexture("u_v4l2cam", v4l2Tex); - boundShader.setUniformTexture("u_gradient", gradient); boundShader.setUniform1i("u_init", 1); boundShader.render(); boundShader.setUniform1i("u_init", 0); diff --git a/zoneb/src/ofApp.h b/zoneb/src/ofApp.h index 6693766..0109791 100644 --- a/zoneb/src/ofApp.h +++ b/zoneb/src/ofApp.h @@ -50,13 +50,13 @@ private: ofxShaderFilter boundShader; std::map fbos; + std::map gradients; + std::vector gradientNames {"warm1", "warm2", "cold1", "cold2"}; ofxV4L2 v4l2Cam; ofTexture v4l2Tex; ofPixels v4l2Pixels; - ofFloatImage gradient; - ofxGpuParticles particles; std::vector> hotspots;