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

112 lines
2.6 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;
uniform sampler2DRect u_ofcam;
uniform sampler2DRect u_v4l2cam;
uniform sampler2DRect u_buffer0;
uniform sampler2DRect u_buffer1;
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-18 13:54:25 +00:00
float depthToSilhouette(float depth) {
2020-10-21 08:59:26 +00:00
if(depth <= 0.4) return 0;
// if(depth > 0.1) return 0;
2020-10-18 13:54:25 +00:00
else return 1;
}
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;
// st.y = 1.0 - st.y;
#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)
vec4 color = vec4(0,0,0,1);
if(u_init) {
2020-10-21 08:59:26 +00:00
vec3 tmpc = texture(u_ofcam, st).rgb;
float tmp = tmpc.r;// + tmpc.g + tmpc.b;
2020-10-18 13:54:25 +00:00
color.rgb = vec3(depthToSilhouette(tmp));
2020-10-18 13:25:49 +00:00
}
else {
float kernel[9];
kernel[0] = 0.125;
kernel[1] = 0.25;
kernel[2] = 0.125;
kernel[3] = 0.25;
kernel[4] = 1.0;
kernel[5] = 0.25;
kernel[6] = 0.125;
kernel[7] = 0.25;
kernel[8] = 0.125;
float lap = 0;
for (int i=0; i < 9; i++){
2020-10-21 08:59:26 +00:00
float tmp = texture(u_buffer1, st + offset[i]).r;
2020-10-18 13:54:25 +00:00
lap += tmp * kernel[i] / 2.5;
2020-10-18 13:25:49 +00:00
}
2020-10-18 13:54:25 +00:00
color = vec4(vec3(lap * 2.0), 1.0);
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-21 08:59:26 +00:00
gl_FragColor = texture(u_buffer0, st);
2020-10-18 13:25:49 +00:00
#else
// Main Buffer
2020-10-21 08:59:26 +00:00
float buf1 = texture(u_buffer1, st).r;
vec3 dispColor = vec3(0, 0, 0);
2020-10-21 08:59:26 +00:00
vec4 pointCloudColor = texture(u_ofcam, st);
2020-10-21 08:59:26 +00:00
float maxVal = 0;
float minVal = 1;
2020-10-18 13:54:25 +00:00
for (int i=0; i < 9; i++){
2020-10-21 08:59:26 +00:00
float tmp = texture(u_buffer1, st + offset[i]/4).r > 0.5 ? 1 : 0;
2020-10-18 13:54:25 +00:00
maxVal = max(maxVal, tmp);
minVal = min(minVal, tmp);
}
2020-10-18 13:25:49 +00:00
2020-10-21 08:59:26 +00:00
if(maxVal - minVal >= 0.5) {
2020-10-18 13:54:25 +00:00
dispColor.rgb = vec3(1);
}
2020-10-18 13:25:49 +00:00
2020-10-21 08:59:26 +00:00
// dispColor.rgb = vec3(depthToSilhouette(texture(u_depth, st/u_resolution).r));
2020-10-18 13:54:25 +00:00
gl_FragColor = vec4(dispColor, 1.0);
2020-10-21 08:59:26 +00:00
gl_FragColor.rgb += pointCloudColor.rgb; // not good
// gl_FragColor = texture(u_buffer1, st); // not good
2020-10-19 09:00:40 +00:00
2020-10-18 13:25:49 +00:00
#endif
}