#ifdef GL_ES precision mediump float; #endif uniform sampler2D u_depth; uniform sampler2D u_buffer0; uniform sampler2D u_buffer1; uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; uniform bool u_init; varying vec2 v_texcoord; void main() { 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) { float tmp = texture2D(u_depth, st).r; if(tmp > 0.005) { color.rgb = vec3(1); } } else { vec2 pixel = 1./u_resolution; 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; 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); float lap = 0; for (int i=0; i < 9; i++){ float tmp = texture2D(u_buffer1, st + offset[i]).r; // lap += tmp * kernel[i] / 2.5; if(tmp > 0.005) { color.rgb = vec3(1); } } } 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 // gl_FragColor = texture2D(u_buffer0, st); #else // Main Buffer vec3 dispColor = vec3(0, 0, 1); dispColor.r = texture2D(u_depth, st).r > 0.005 ? 1 : 0; dispColor.g = texture2D(u_buffer1, st).r; // color.r = 1.; gl_FragColor = vec4(dispColor, 1.0); // gl_FragColor = color; #endif }