Advertisement
Guest User

Outline Postprocessing Effect - Nyuuzero

a guest
Feb 5th, 2011
14,812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. /*
  2. * Simple outline postprocessing effect
  3. * Author: nyuuzero
  4. */
  5.  
  6. uniform sampler2D sampler0;
  7. uniform sampler2D sampler1;
  8. uniform sampler2D sampler2;
  9.  
  10. uniform float displayWidth;
  11. uniform float displayHeight;
  12. uniform float aspectRatio;
  13. uniform float near;
  14. uniform float far;
  15.  
  16. float rand(vec2 co){
  17.     return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
  18. }
  19.  
  20. float getLinearDepth(vec2 coords)
  21. {
  22.    return (2 * near) / (far + near - texture2D( sampler1, coords ).x * (far - near));
  23. }
  24.  
  25. float generateOutline(vec2 coords)
  26. {
  27.    // pixelsize
  28.    float horizontalPixelSize = 1.0 / displayWidth;
  29.    float verticalPixelSize = 1.0 / displayHeight;
  30.    
  31.    // generate outline
  32.    float tempDepth =
  33.       getLinearDepth(coords + vec2(horizontalPixelSize,verticalPixelSize)) +
  34.       getLinearDepth(coords + vec2(-horizontalPixelSize,verticalPixelSize)) +
  35.       getLinearDepth(coords + vec2(0.0,-verticalPixelSize));
  36.      
  37.    tempDepth /= 3;
  38.    
  39.    return getLinearDepth(coords)-tempDepth;
  40. }
  41.  
  42. void main()
  43. {
  44.    gl_FragColor = mix(texture2D( sampler0, gl_TexCoord[0].st ),vec4(0.0,0.0,0.0,0.0),clamp(generateOutline(gl_TexCoord[0].st)*100,0.0,0.9));
  45.    //gl_FragColor *= 1.0 - clamp(generateOutline(gl_TexCoord[0].st)*100,0.0,1.0);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement