koolkat

final.fsh

Dec 28th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #version 120
  2. /*
  3. * Simple outline postprocessing effect
  4. * Author: nyuuzero
  5. */
  6.  
  7. #define LINE_THICKNESS 1
  8.  
  9. uniform sampler2D composite;
  10. uniform sampler2D gdepth;
  11. uniform float viewWidth;
  12. uniform float viewHeight;
  13. uniform float near;
  14. uniform float far;
  15. varying vec4 texcoord;
  16.  
  17. float getLinearDepth(vec2 coords)
  18. {
  19.    return (2 * near) / (far + near - texture2D( gdepth, coords ).x * (far - near));
  20. }
  21.  
  22. float generateOutline(vec2 coords)
  23. {
  24.    // pixelsize
  25.    float horizontalPixelSize = 1.0 / viewWidth * LINE_THICKNESS;
  26.    float verticalPixelSize = 1.0 / viewHeight * LINE_THICKNESS;
  27.    
  28.    // generate outline
  29.    float tempDepth =
  30.       getLinearDepth(coords + vec2(horizontalPixelSize,verticalPixelSize)) +
  31.       getLinearDepth(coords + vec2(-horizontalPixelSize,verticalPixelSize)) +
  32.       getLinearDepth(coords + vec2(0.0,-verticalPixelSize));
  33.      
  34.    tempDepth /= 3;
  35.    
  36.    return getLinearDepth(coords)-tempDepth;
  37. }
  38.  
  39. void main()
  40. {
  41.     vec4 color;
  42.     color = mix(texture2D( composite, texcoord.st ),vec4(0.0,0.0,0.0,1.0),clamp(generateOutline(texcoord.st)*100,0.0,0.999));
  43.     //color *= 1.0 - clamp(generateOutline(texcoord.st)*100,0.0,1.0);
  44.     gl_FragColor = color;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment