fix segfault & comment shaders

This commit is contained in:
micuat 2020-10-21 12:05:45 +02:00
parent 3390203fd7
commit a6df066962
4 changed files with 107 additions and 25 deletions

View file

@ -16,6 +16,82 @@ uniform bool u_init;
varying vec2 v_texcoord; 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) { float depthToSilhouette(float depth) {
if(depth <= 0.4) return 0; if(depth <= 0.4) return 0;
// if(depth > 0.1) return 0; // if(depth > 0.1) return 0;
@ -49,9 +125,19 @@ void main() {
// BUFFER_1 (u_buffer1) // BUFFER_1 (u_buffer1)
vec4 color = vec4(0,0,0,1); vec4 color = vec4(0,0,0,1);
if(u_init) { if(u_init) {
vec3 tmpc = texture(u_ofcam, st).rgb; int brightCount = 0;
float tmp = tmpc.r;// + tmpc.g + tmpc.b; // for (int i=0; i < 9; i++){
color.rgb = vec3(depthToSilhouette(tmp)); // 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 {
@ -86,14 +172,14 @@ void main() {
gl_FragColor = texture(u_buffer0, st); gl_FragColor = texture(u_buffer0, st);
#else #else
// Main Buffer // Main Buffer
float buf1 = texture(u_buffer1, st).r; vec2 st2 = st + vec2(simplex3d_fractal(vec3(st,0)/80), simplex3d_fractal(vec3(0,st.ts)/80)) * 16;
vec3 dispColor = vec3(0, 0, 0); vec3 dispColor = vec3(0, 0, 0);
vec4 pointCloudColor = texture(u_ofcam, st); vec4 pointCloudColor = texture(u_ofcam, st);
float maxVal = 0; float maxVal = 0;
float minVal = 1; float minVal = 1;
for (int i=0; i < 9; i++){ for (int i=0; i < 9; i++){
float tmp = texture(u_buffer1, st + offset[i]/4).r > 0.5 ? 1 : 0; float tmp = texture(u_buffer1, st2 + offset[i]/2).r > 0.5 ? 1 : 0;
maxVal = max(maxVal, tmp); maxVal = max(maxVal, tmp);
minVal = min(minVal, tmp); minVal = min(minVal, tmp);
} }
@ -102,10 +188,8 @@ void main() {
dispColor.rgb = vec3(1); dispColor.rgb = vec3(1);
} }
// dispColor.rgb = vec3(depthToSilhouette(texture(u_depth, st/u_resolution).r));
gl_FragColor = vec4(dispColor, 1.0); gl_FragColor = vec4(dispColor, 1.0);
gl_FragColor.rgb += pointCloudColor.rgb; // not good gl_FragColor.rgb += pointCloudColor.rgb; // not good
// gl_FragColor = texture(u_buffer1, st); // not good
#endif #endif

View file

@ -13,8 +13,7 @@ in float vAge;
void main() void main()
{ {
// fragColor = vec4(1);//vec4(texture(u_world, texCoordVarying.st).rgb,1); vec3 remapedColor = texture(imageTexture, vec2(vTemperature*1600, 0.5)).xyz;
// fragColor = vec4(texCoordVarying.st/100,1.0,1.0);//vec4(texture(u_world, texCoordVarying.st).rgb,1); float alpha = max(0, 1 - pow(vAge,4));
// fragColor = vec4(texture(u_v4l2cam, texCoordVarying.st).rgb,1); fragColor = vec4(remapedColor, alpha);
fragColor = vec4(texture(imageTexture, vec2(vTemperature*1600, 0.5)).xyz,max(0, 1 - pow(vAge,4)));
} }

View file

@ -119,40 +119,39 @@ void main()
float vValid = (depth != 0 && ray.x != 0 && ray.y != 0) ? 1 : 0; float vValid = (depth != 0 && ray.x != 0 && ray.y != 0) ? 1 : 0;
// if(depth < 0.012) vValid = 0;
// if(depth > 0.04) vValid = 0;
vec4 posWorld = vec4(1); vec4 posWorld = vec4(1);
posWorld.z = -depth * 65535.0; // Remap to float range. posWorld.z = -depth * 65535.0; // Remap to float range.
posWorld.x = ray.x * posWorld.z; posWorld.x = ray.x * posWorld.z;
posWorld.y = ray.y * posWorld.z; posWorld.y = ray.y * posWorld.z;
float age = misc.y; float age = misc.y;
if(age > 1) { if(age > 1) { // reached target
target.w = 0; target.w = 0;
if(vValid == 1) { if(vValid == 1) { // rebirth if point is valid
age = 0; age = 0;
} }
} }
if(vValid == 1 && target.w == 0) { if(vValid == 1 && target.w == 0) { // point valid && no target -> move to the point
pos = posWorld.xyz; pos = posWorld.xyz;
age = 0; age = 0;
target.xyz = pos; target.xyz = pos;
} }
else if (target.w > 0) { else if (target.w > 0) { // targeted
age += 0.001; age += 0.001;
thermo = misc.x; thermo = misc.x;
} }
else { else { // wandering
age += 0.01; age += 0.1;
// age += 0.01;
thermo = misc.x; thermo = misc.x;
} }
if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { if(vValid == 1 && target.w > 0 && length(target.xy - pos.xy) < 100) { // arrived
age += 0.03; age += 0.03;
} }
// wandering
vec3 force = vec3(0,0,0); vec3 force = vec3(0,0,0);
float th = 3.1415 * 4 * simplex3d_fractal(vec3(pos.xyz * 0.001)); float th = 3.1415 * 4 * simplex3d_fractal(vec3(pos.xyz * 0.001));
float phi = 3.1415 * simplex3d_fractal(pos.xyz * 0.002); float phi = 3.1415 * simplex3d_fractal(pos.xyz * 0.002);
@ -161,7 +160,7 @@ void main()
force.z += sin(phi); force.z += sin(phi);
force *= 100; force *= 100;
if(age < 0.001) { if(age < 0.001) { // targetting
target.w = 0; target.w = 0;
if(random3(pos).x > pow(length(texCoordVarying.st - uHottest0.st)/5,16*16)+0) { if(random3(pos).x > pow(length(texCoordVarying.st - uHottest0.st)/5,16*16)+0) {
vec2 h = uHottest1.st; vec2 h = uHottest1.st;
@ -201,7 +200,7 @@ void main()
// } // }
} }
if(target.w > 0) { if(target.w > 0) { // go to target
float th = atan(-pos.y + target.y, -pos.x + target.x); float th = atan(-pos.y + target.y, -pos.x + target.x);
float phi = atan(-pos.z + target.z, length(target.xy-pos.xy)); float phi = atan(-pos.z + target.z, length(target.xy-pos.xy));
th += 3.1415 / 4 * simplex3d_fractal(vec3(pos.xyz * 0.001)); th += 3.1415 / 4 * simplex3d_fractal(vec3(pos.xyz * 0.001));

View file

@ -209,7 +209,7 @@ void ofApp::onParticlesUpdate(ofxShader &shader)
{ {
shader.setUniform3f("uHottest1", hotspots.at(1).at(0)); shader.setUniform3f("uHottest1", hotspots.at(1).at(0));
} }
else if (hotspots.size() > 0 && hotspots.at(0).size() > 0) else if (hotspots.size() > 0 && hotspots.at(0).size() > 1)
{ {
shader.setUniform3f("uHottest1", hotspots.at(0).at(1)); shader.setUniform3f("uHottest1", hotspots.at(0).at(1));
} }
@ -243,7 +243,7 @@ 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 < 60; i++) for (int i = 0; i < 30; i++)
{ {
boundShader.render(); boundShader.render();
} }