medfall

A super great game engine
Log | Files | Refs

depth_edge.glsl (1229B)


      1 uniform sampler2D model_depth;
      2 
      3 #ifdef VERTEX_SHADER
      4 
      5 in vec2 position;
      6 
      7 void main() {
      8 	gl_Position = vec4( position, 0.0, 1.0 );
      9 }
     10 
     11 #else
     12 
     13 void main() {
     14 	vec2 pixel = vec2( 1.0 / textureSize( model_depth, 0 ) );
     15 	vec3 pole = vec3( -1.0, 0.0, 1.0 );
     16 
     17 	vec2 uv = gl_FragCoord.xy / textureSize( model_depth, 0 );
     18 
     19 	/* float d0 = texture( model_depth, uv + pixel.xy * pole.xx ).r; // x1, y1 */
     20 	float d1 = texture( model_depth, uv + pixel.xy * pole.yx ).r; // x2, y1
     21 	/* float d2 = texture( model_depth, uv + pixel.xy * pole.zx ).r; // x3, y1 */
     22 	float d3 = texture( model_depth, uv + pixel.xy * pole.xy ).r; // x1, y2
     23 	float d4 = texture( model_depth, uv + pixel.xy * pole.yy ).r; // x2, y2
     24 	float d5 = texture( model_depth, uv + pixel.xy * pole.zy ).r; // x3, y2
     25 	/* float d6 = texture( model_depth, uv + pixel.xy * pole.xz ).r; // x1, y3 */
     26 	float d7 = texture( model_depth, uv + pixel.xy * pole.yz ).r; // x2, y3
     27 	/* float d8 = texture( model_depth, uv + pixel.xy * pole.zz ).r; // x3, y3 */
     28 
     29 	float a = d1 * d3 * d5 * d7;
     30 	float b = d1 + d3 + d5 + d7;
     31 
     32 	// if a == 0, at least one 0 depth
     33 	// if b != 0, at least one non-0 depth
     34 
     35 	if( a == 0.0 && b != 0.0 ) {
     36 		gl_FragDepth = d4;
     37 	}
     38 	else {
     39 		gl_FragDepth = 0.0;
     40 	}
     41 }
     42 
     43 #endif