caching trace
This commit is contained in:
parent
94af82c45a
commit
41f84881b1
7 changed files with 86 additions and 44 deletions
|
@ -1,8 +1,9 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<ZONE_B>
|
<ZONE_B>
|
||||||
<XY>61.2245, 0</XY>
|
<XY>61.2245, -28.5714</XY>
|
||||||
<scale>1.7965</scale>
|
<scale>1.7965</scale>
|
||||||
<device>video3</device>
|
<device>video3</device>
|
||||||
<thermo_delay>7</thermo_delay>
|
<thermo_delay>4</thermo_delay>
|
||||||
<blend_add>1</blend_add>
|
<blend_add>1</blend_add>
|
||||||
|
<render_times>3</render_times>
|
||||||
</ZONE_B>
|
</ZONE_B>
|
||||||
|
|
|
@ -128,42 +128,46 @@ void main() {
|
||||||
// Note: Here is where most of the action happens. But need's to read
|
// 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
|
// te content of the previous pass, for that we are making another buffer
|
||||||
// BUFFER_1 (u_buffer1)
|
// BUFFER_1 (u_buffer1)
|
||||||
vec4 color = vec4(0,0,0,1);
|
vec4 color = vec4(0,0,0,0);
|
||||||
if(u_init) {
|
if(u_init) {
|
||||||
int brightCount = 0;
|
color = vec4(texture(u_energy, st).rgba);
|
||||||
// for (int i=0; i < 9; i++){
|
color = vec4(mix(texture(u_buffer1, st).rgb * 0.95, color.rgb, color.a), 1);
|
||||||
// float tmp = texture(u_buffer1, st + offset[i]/40).r;
|
|
||||||
// if(depthToSilhouette(tmp) > 0) {
|
|
||||||
// brightCount++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
brightCount = 10;
|
|
||||||
if(brightCount > 4) {
|
|
||||||
vec3 tmpc = texture(u_ofcam, st).rgb;
|
|
||||||
float tmp = tmpc.r;// + tmpc.g + tmpc.b;
|
|
||||||
color.rgb = vec3(depthToSilhouette(tmp));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
float kernel[9];
|
float kernel[9];
|
||||||
kernel[0] = 0.125;
|
kernel[0] = 0.125*2;
|
||||||
kernel[1] = 0.25;
|
kernel[1] = 0.25*2;
|
||||||
kernel[2] = 0.125;
|
kernel[2] = 0.125*2;
|
||||||
kernel[3] = 0.25;
|
kernel[3] = 0.25*2;
|
||||||
kernel[4] = 1.0;
|
kernel[4] = 1.0;
|
||||||
kernel[5] = 0.25;
|
kernel[5] = 0.25*2;
|
||||||
kernel[6] = 0.125;
|
kernel[6] = 0.125*2;
|
||||||
kernel[7] = 0.25;
|
kernel[7] = 0.25*2;
|
||||||
kernel[8] = 0.125;
|
kernel[8] = 0.125*2;
|
||||||
|
|
||||||
float lap = 0;
|
float lap = 0;
|
||||||
|
vec4 cc = vec4(0);
|
||||||
|
|
||||||
for (int i=0; i < 9; i++){
|
for (int i=0; i < 9; i++){
|
||||||
float tmp = texture(u_buffer1, st + offset[i]).r;
|
// float tmp = texture(u_buffer1, st + offset[i]).r;
|
||||||
lap += tmp * kernel[i] / 2.5;
|
// lap += tmp * kernel[i] / 2.5;
|
||||||
|
// vec4 ccc = texture(u_buffer1, st + offset[i]);
|
||||||
|
// if(length(ccc.rgb) > length(cc.rgb)) cc = ccc;
|
||||||
|
// if(ccc.r < 1 && ccc.g < 1 && ccc.b < 1) {
|
||||||
|
// cc += ccc * kernel[i] / 4;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
color = vec4(vec3(lap * 2.0), 1.0);
|
// color = vec4(vec3(lap * 2.0), 1.0);
|
||||||
|
// color = vec4(cc.rgba);
|
||||||
|
// // color = vec4(cc.rgba/4);
|
||||||
|
// color.r = min(1, color.r);
|
||||||
|
// color.g = min(1, color.g);
|
||||||
|
// color.b = min(1, color.b);
|
||||||
|
// color.a = min(1, color.a);
|
||||||
|
|
||||||
|
color = texture(u_buffer1, st);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
|
@ -174,7 +178,9 @@ void main() {
|
||||||
// Note: Just copy the content of the BUFFER0 so it can be
|
// Note: Just copy the content of the BUFFER0 so it can be
|
||||||
// read by it in the next frame
|
// read by it in the next frame
|
||||||
//
|
//
|
||||||
gl_FragColor = texture(u_buffer0, st);
|
vec4 color = vec4(0,0,0,1);
|
||||||
|
color = texture(u_buffer0, st);
|
||||||
|
gl_FragColor = color;
|
||||||
#else
|
#else
|
||||||
// Main Buffer
|
// Main Buffer
|
||||||
if (u_calib) {
|
if (u_calib) {
|
||||||
|
@ -187,9 +193,13 @@ void main() {
|
||||||
else {
|
else {
|
||||||
vec4 pointCloudColor = texture(u_ofcam, st);
|
vec4 pointCloudColor = texture(u_ofcam, st);
|
||||||
vec4 energyColor = texture(u_energy, st);
|
vec4 energyColor = texture(u_energy, st);
|
||||||
vec4 color = vec4(mix(vec3(0), pointCloudColor.rgb, pointCloudColor.a), 1.0);
|
vec4 bufColor = texture(u_buffer1, st);
|
||||||
|
float newA = length(bufColor.rgb) / 2;
|
||||||
|
newA = min(1, newA);
|
||||||
|
gl_FragColor = vec4(mix(pointCloudColor.rgb,bufColor.rgb, newA), 1);
|
||||||
|
// gl_FragColor = vec4(mix(pointCloudColor.rgb, bufColor.rgb, min(1, length(bufColor.rgb))), 1.0);
|
||||||
gl_FragColor = vec4(mix(pointCloudColor.rgb, energyColor.rgb, energyColor.a), 1.0);
|
gl_FragColor = vec4(mix(pointCloudColor.rgb, energyColor.rgb, energyColor.a), 1.0);
|
||||||
// gl_FragColor = vec4(mix(vec3(0), energyColor.rgb, energyColor.a), 1.0);
|
// gl_FragColor = vec4(mix(vec3(0), pointCloudColor.rgb, pointCloudColor.a), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -115,10 +115,10 @@ void main()
|
||||||
float rate = 1-smoothstep(D - d, D + d, length(gPos.x + uBetween.x) + n);
|
float rate = 1-smoothstep(D - d, D + d, length(gPos.x + uBetween.x) + n);
|
||||||
rate *= uAreThereTwoPeopleTween;
|
rate *= uAreThereTwoPeopleTween;
|
||||||
vec3 remapedColor = mix(remapedColorC, remapedColorW, rate);
|
vec3 remapedColor = mix(remapedColorC, remapedColorW, rate);
|
||||||
float alpha = max(0, 1 - pow(gAge,4));
|
float alpha = min(1, max(0, 1 - pow(gAge,4)));
|
||||||
if(uEnergy > 0) {
|
if(uEnergy > 0) {
|
||||||
// alpha = 1;
|
// alpha = 1;
|
||||||
alpha *= 0.3;
|
alpha *= 0.15;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alpha *= 0.1;
|
alpha *= 0.1;
|
||||||
|
|
|
@ -47,6 +47,7 @@ void main()
|
||||||
vec3 vOffset;
|
vec3 vOffset;
|
||||||
if(uEnergy > 0) {
|
if(uEnergy > 0) {
|
||||||
if(gAge < 0.01) return;
|
if(gAge < 0.01) return;
|
||||||
|
if(length(gTarget.xyz) > 1000) return;
|
||||||
vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz);
|
vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz);
|
||||||
vOffset += normalize(vOffset) * 10;
|
vOffset += normalize(vOffset) * 10;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,8 +150,8 @@ void main()
|
||||||
|
|
||||||
float age = misc.y;
|
float age = misc.y;
|
||||||
if(age > 1) { // reached target
|
if(age > 1) { // reached target
|
||||||
target.w = 0;
|
|
||||||
if(vValid == 1) { // rebirth if point is valid
|
if(vValid == 1) { // rebirth if point is valid
|
||||||
|
target.w = 0;
|
||||||
age = 0;
|
age = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ void main()
|
||||||
age = 0;
|
age = 0;
|
||||||
}
|
}
|
||||||
else if (target.w > 0) { // targeted
|
else if (target.w > 0) { // targeted
|
||||||
age += 0.002;
|
age += 0.005;
|
||||||
thermo = misc.x;
|
thermo = misc.x;
|
||||||
}
|
}
|
||||||
else { // wandering
|
else { // wandering
|
||||||
|
@ -185,17 +185,17 @@ void main()
|
||||||
force *= 100;
|
force *= 100;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float th = 3.1415 * 4 * simplex3d_fractal(vec3(pos.xyz * 0.01));
|
// float th = 3.1415 * 4 * simplex3d_fractal(vec3(pos.xyz * 0.01));
|
||||||
float phi = 3.1415 * simplex3d_fractal(pos.xyz * 0.02);
|
// float phi = 3.1415 * simplex3d_fractal(pos.xyz * 0.02);
|
||||||
force.x += cos(th) * cos(phi);
|
// force.x += cos(th) * cos(phi);
|
||||||
force.y += sin(th) * cos(phi);
|
// force.y += sin(th) * cos(phi);
|
||||||
force.z += sin(phi);
|
// force.z += sin(phi);
|
||||||
force *= 100;
|
// force *= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(age < 0.001) { // targetting
|
if(age < 0.001) { // targetting
|
||||||
target.w = 0;
|
target.w = 0;
|
||||||
if(random3(pos + vec3(u_time, 0, 0)).x > 2*pow(length(texCoordVarying.st/fraction - uHottest0.st)/25,0.5)) {
|
if(random3(pos + vec3(u_time, 0, 0)).x > 8*pow(length(texCoordVarying.st/fraction - uHottest0.st)/50,1)) {
|
||||||
vec2 h = uHottest1.st;
|
vec2 h = uHottest1.st;
|
||||||
vec4 hray = texture(u_world, h);
|
vec4 hray = texture(u_world, h);
|
||||||
float hdepth = -depth * 65535.0;
|
float hdepth = -depth * 65535.0;
|
||||||
|
@ -203,8 +203,9 @@ void main()
|
||||||
vec3 H = vec3(hray.xy * hdepth, hdepth);
|
vec3 H = vec3(hray.xy * hdepth, hdepth);
|
||||||
target.xyz = H + random3(pos) * 3;
|
target.xyz = H + random3(pos) * 3;
|
||||||
target.w = 1;
|
target.w = 1;
|
||||||
|
thermo += random3(pos).y * 0.2 - 0.1;
|
||||||
}
|
}
|
||||||
else if(random3(pos + vec3(u_time, 0, 0)).x > 2*pow(length(texCoordVarying.st/fraction - uHottest1.st)/25,0.5)) {
|
else if(random3(pos + vec3(u_time, 0, 0)).x > 8*pow(length(texCoordVarying.st/fraction - uHottest1.st)/50,1)) {
|
||||||
vec2 h = uHottest0.st;
|
vec2 h = uHottest0.st;
|
||||||
vec4 hray = texture(u_world, h);
|
vec4 hray = texture(u_world, h);
|
||||||
float hdepth = -depth * 65535.0;
|
float hdepth = -depth * 65535.0;
|
||||||
|
@ -212,6 +213,7 @@ void main()
|
||||||
vec3 H = vec3(hray.xy * hdepth, hdepth);
|
vec3 H = vec3(hray.xy * hdepth, hdepth);
|
||||||
target.xyz = H + random3(pos) * 3;
|
target.xyz = H + random3(pos) * 3;
|
||||||
target.w = 1;
|
target.w = 1;
|
||||||
|
thermo += random3(pos).y * 0.2 - 0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,8 @@ void ofApp::setupGui()
|
||||||
gui.add(v4l2Delay.setup("thermo delay", 0, 0, 59));
|
gui.add(v4l2Delay.setup("thermo delay", 0, 0, 59));
|
||||||
gui.add(captureDeviceName.setup("device", "video3"));
|
gui.add(captureDeviceName.setup("device", "video3"));
|
||||||
gui.add(blendAdd.setup("blend add", false));
|
gui.add(blendAdd.setup("blend add", false));
|
||||||
|
gui.add(renderTimes.setup("render times", 1, 1, 30));
|
||||||
|
gui.add(traceTimes.setup("trace times", 3, 1, 30));
|
||||||
gui.loadFromFile("settings.xml");
|
gui.loadFromFile("settings.xml");
|
||||||
gui.setPosition(10, 10);
|
gui.setPosition(10, 10);
|
||||||
|
|
||||||
|
@ -164,6 +166,13 @@ void ofApp::setup()
|
||||||
fbos.insert({"energy", ofFbo()});
|
fbos.insert({"energy", ofFbo()});
|
||||||
fbos.at("energy").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB);
|
fbos.at("energy").allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB);
|
||||||
|
|
||||||
|
for (int i = 0; i < 30; i++)
|
||||||
|
{
|
||||||
|
traces.push_back(ofFbo());
|
||||||
|
traces.back().allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F_ARB);
|
||||||
|
}
|
||||||
|
curTrace = 0;
|
||||||
|
|
||||||
for (auto s : gradientNames)
|
for (auto s : gradientNames)
|
||||||
{
|
{
|
||||||
gradients.insert({s, ofFloatImage()});
|
gradients.insert({s, ofFloatImage()});
|
||||||
|
@ -347,8 +356,11 @@ void ofApp::drawMain()
|
||||||
boundShader.setUniform1i("u_init", 1);
|
boundShader.setUniform1i("u_init", 1);
|
||||||
boundShader.render();
|
boundShader.render();
|
||||||
boundShader.setUniform1i("u_init", 0);
|
boundShader.setUniform1i("u_init", 0);
|
||||||
|
for (int i = 0; i < renderTimes; i++)
|
||||||
|
{
|
||||||
boundShader.render();
|
boundShader.render();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ofApp::drawDebug()
|
void ofApp::drawDebug()
|
||||||
{
|
{
|
||||||
|
@ -365,7 +377,7 @@ void ofApp::draw()
|
||||||
particles.whateverImages.at("u_world") = kinectDevice.getDepthToWorldTex();
|
particles.whateverImages.at("u_world") = kinectDevice.getDepthToWorldTex();
|
||||||
particles.whateverImages.at("u_v4l2cam") = v4l2Buffer.at(v4l2BufferCount);
|
particles.whateverImages.at("u_v4l2cam") = v4l2Buffer.at(v4l2BufferCount);
|
||||||
|
|
||||||
fbos.at("energy").begin();
|
traces.at(curTrace).begin();
|
||||||
ofClear(0);
|
ofClear(0);
|
||||||
cam.begin();
|
cam.begin();
|
||||||
if (blendAdd)
|
if (blendAdd)
|
||||||
|
@ -384,7 +396,19 @@ void ofApp::draw()
|
||||||
ofDisableBlendMode();
|
ofDisableBlendMode();
|
||||||
}
|
}
|
||||||
cam.end();
|
cam.end();
|
||||||
|
traces.at(curTrace).end();
|
||||||
|
|
||||||
|
fbos.at("energy").begin();
|
||||||
|
ofClear(0);
|
||||||
|
ofEnableBlendMode(OF_BLENDMODE_ADD);
|
||||||
|
for (int i = 0; i < traceTimes; i++)
|
||||||
|
{
|
||||||
|
int index = (curTrace - i + traces.size()) % traces.size();
|
||||||
|
traces.at(index).draw(0, 0);
|
||||||
|
}
|
||||||
|
ofDisableBlendMode();
|
||||||
fbos.at("energy").end();
|
fbos.at("energy").end();
|
||||||
|
curTrace = (curTrace + 1) % traces.size();
|
||||||
|
|
||||||
fbos.at("ofcam").begin();
|
fbos.at("ofcam").begin();
|
||||||
ofClear(0);
|
ofClear(0);
|
||||||
|
|
|
@ -50,6 +50,8 @@ private:
|
||||||
ofxShaderFilter boundShader;
|
ofxShaderFilter boundShader;
|
||||||
|
|
||||||
std::map<string, ofFbo> fbos;
|
std::map<string, ofFbo> fbos;
|
||||||
|
std::vector<ofFbo> traces;
|
||||||
|
int curTrace;
|
||||||
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"};
|
||||||
|
|
||||||
|
@ -74,6 +76,8 @@ private:
|
||||||
ofxIntSlider v4l2Delay;
|
ofxIntSlider v4l2Delay;
|
||||||
ofxInputField<std::string> captureDeviceName;
|
ofxInputField<std::string> captureDeviceName;
|
||||||
ofxToggle blendAdd;
|
ofxToggle blendAdd;
|
||||||
|
ofxIntSlider renderTimes;
|
||||||
|
ofxIntSlider traceTimes;
|
||||||
ofxPanel gui;
|
ofxPanel gui;
|
||||||
|
|
||||||
ofxToggle calibMode;
|
ofxToggle calibMode;
|
||||||
|
|
Loading…
Reference in a new issue