Facebook
From iyad, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 57
  1. uniform sampler2D bgl_RenderedTexture;
  2. uniform sampler2D bgl_DepthTexture;
  3.  
  4.  
  5. vec2 texcoord = vec2(gl_TexCoord[0]).st;
  6.  
  7.  
  8. uniform vec2 bgl_TextureCoordinateOffset[9];
  9.  
  10. vec4 prewitt(sampler2D image, vec2 coords)
  11. {
  12.     vec4 samp[9];
  13.         vec4 border;
  14.         vec4 texcol = texture(image, texcoord);
  15.  
  16.     for (int i = 0; i < 9; i++)
  17.     {
  18.         samp[i] = texture(image, gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
  19.     }
  20.  
  21.     vec4 horizEdge = samp[2] + samp[5] + samp[8] - (samp[0] + samp[3] + samp[6]);
  22.  
  23.     vec4 vertEdge = samp[0] + samp[1] + samp[2] - (samp[6] + samp[7] + samp[8]);
  24.  
  25.         border.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb));
  26.  
  27.  
  28. float br = smoothstep(.005, .01, border.r);
  29. float bg = smoothstep(.005, .01, border.g);
  30. float bb = smoothstep(.005, .01, border.b);
  31.  
  32.  
  33.         texcol.rgb = vec3(mix(1., .0, max(max(br,bg),bb)));
  34.        
  35.  
  36. return texcol;
  37. }
  38.  
  39. void main(void)
  40. {
  41.     gl_FragColor = prewitt(bgl_DepthTexture, texcoord);
  42. }
captcha