Guest User

Untitled

a guest
Feb 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // set by the vertex shader
  2. varying vec2 tex_coord;
  3. uniform sampler2DRect colorTexture;
  4. uniform sampler2DRect depthTexture;
  5. uniform sampler2DRect normalTexture;
  6. uniform float near;
  7. uniform float far;
  8. uniform int width;
  9. uniform int height;
  10. vec2 top;
  11. vec2 bottom;
  12. vec2 left;
  13. vec2 right;
  14. const float offset = 0.05;
  15.  
  16. void main(void)
  17. {
  18.     top = vec2(tex_coord.x, tex_coord.y - 1);
  19.     bottom = vec2(tex_coord.x, tex_coord.y + 1);
  20.     left = vec2(tex_coord.x - 1, tex_coord.y);
  21.     right = vec2(tex_coord.x + 1, tex_coord.y);
  22.    
  23.     float topD = texture2DRect(depthTexture, top);
  24.     float bottomD = texture2DRect(depthTexture, bottom);
  25.     float leftD = texture2DRect(depthTexture, left);
  26.     float rightD = texture2DRect(depthTexture, right);
  27.    
  28.     //converting the values obtained from the depth buffer
  29.     float topZ = (near*far)/far-topD*(far-near);
  30.     float bottomZ = (near*far)/far-bottomD*(far-near);
  31.     float leftZ = (near*far)/far-leftD*(far-near);
  32.     float rightZ = (near*far)/far-rightD*(far-near);
  33.  
  34.     float magnitude = abs(rightZ - leftZ) + abs(bottomZ - topZ);
  35.     if(magnitude > offset)
  36.     {
  37.         // make it black
  38.         gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
  39.     }
  40.     else
  41.     {
  42.         // leave it as is.
  43.         gl_FragColor = texture2DRect(colorTexture,tex_coord);
  44.     }
  45.     // render a color based on the texture coordinate
  46.    
  47.     //gl_FragCoord = gl_FragCoord;
  48. }
Add Comment
Please, Sign In to add comment