realityplayground-of/zoneb/bin/data/shaders/bound.frag

197 lines
5 KiB
GLSL
Raw Normal View History

2020-10-18 13:25:49 +00:00
#ifdef GL_ES
precision mediump float;
#endif
2020-10-21 08:59:26 +00:00
uniform sampler2DRect u_depth;
2020-11-06 15:00:40 +00:00
uniform sampler2DRect u_color;
2020-11-06 16:27:22 +00:00
uniform sampler2DRect u_ir;
2020-10-21 08:59:26 +00:00
uniform sampler2DRect u_ofcam;
uniform sampler2DRect u_energy;
2020-10-21 08:59:26 +00:00
uniform sampler2DRect u_v4l2cam;
uniform sampler2DRect u_buffer0;
uniform sampler2DRect u_buffer1;
2020-11-06 15:29:21 +00:00
uniform sampler2DRect u_gradient;
2020-10-18 13:25:49 +00:00
2020-10-26 12:57:33 +00:00
uniform bool u_calib;
uniform vec2 u_calibXY;
uniform float u_calibScale;
2020-10-18 13:25:49 +00:00
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
uniform bool u_init;
varying vec2 v_texcoord;
2020-10-21 10:05:45 +00:00
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);
}
2020-10-18 13:25:49 +00:00
void main() {
2020-10-21 08:59:26 +00:00
vec2 pixel = vec2(1.0);//./u_resolution;
2020-10-18 13:54:25 +00:00
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);
2020-10-18 13:25:49 +00:00
vec2 st = v_texcoord;
2020-11-01 18:19:56 +00:00
st.x = 1200.0 - st.x; // horizontal flip
2020-10-18 13:25:49 +00:00
#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)
2020-10-31 21:39:40 +00:00
vec4 color = vec4(0,0,0,0);
2020-10-18 13:25:49 +00:00
if(u_init) {
2020-10-31 21:39:40 +00:00
color = vec4(texture(u_energy, st).rgba);
color = vec4(mix(texture(u_buffer1, st).rgb * 0.95, color.rgb, color.a), 1);
2020-10-18 13:25:49 +00:00
}
else {
float kernel[9];
2020-10-31 21:39:40 +00:00
kernel[0] = 0.125*2;
kernel[1] = 0.25*2;
kernel[2] = 0.125*2;
kernel[3] = 0.25*2;
2020-10-18 13:25:49 +00:00
kernel[4] = 1.0;
2020-10-31 21:39:40 +00:00
kernel[5] = 0.25*2;
kernel[6] = 0.125*2;
kernel[7] = 0.25*2;
kernel[8] = 0.125*2;
2020-10-18 13:25:49 +00:00
float lap = 0;
2020-10-31 21:39:40 +00:00
vec4 cc = vec4(0);
2020-10-18 13:25:49 +00:00
2020-10-31 21:39:40 +00:00
color = texture(u_buffer1, st);
2020-10-18 13:25:49 +00:00
}
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
//
2020-10-31 21:39:40 +00:00
vec4 color = vec4(0,0,0,1);
color = texture(u_buffer0, st);
gl_FragColor = color;
2020-10-18 13:25:49 +00:00
#else
// Main Buffer
2020-10-26 12:57:33 +00:00
if (u_calib) {
2020-11-06 16:27:22 +00:00
if (false) {
vec4 depth = texture(u_depth, st);
depth.r *= 100;
depth.a = 0;
// vec4 v4l2 = texture(u_v4l2cam, st);
vec4 v4l2 = texture(u_v4l2cam, (st + vec2(300, 0)) / vec2(3.7,3.5) + vec2(4, 86));
v4l2 = texture(u_gradient, vec2(v4l2.r * 3425, 0));
gl_FragColor = depth + v4l2;
float fader = sin(u_time * 3.1415 / 10);
fader = fader * 0.5 + 0.5;
// vec4 cc = vec4(texture(u_ir, st/4+vec2(100,200)).rgb * 2, 1);
vec4 cc = vec4(texture(u_color, st + vec2(300, 0)).rgb, 1);
gl_FragColor = mix(vec4(v4l2.rgb,1), cc, fader);
}
else {
vec4 depth = texture(u_depth, st);
depth.r *= 100;
depth.a = 0;
vec4 v4l2 = texture(u_v4l2cam, st);
gl_FragColor = depth + v4l2;
}
2020-10-26 12:57:33 +00:00
}
else {
vec4 pointCloudColor = texture(u_ofcam, st);
vec4 energyColor = texture(u_energy, st);
gl_FragColor = vec4(mix(pointCloudColor.rgb, energyColor.rgb, energyColor.a), 1.0);
2020-10-26 12:57:33 +00:00
}
2020-10-19 09:00:40 +00:00
2020-10-18 13:25:49 +00:00
#endif
}