Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Shader that adds
  3.  
  4. const float GAMMA = 1.0/1.2;
  5. const float BLIND_FACTOR = 0.7;
  6. const float BLIND_THRESH = 0.5;
  7.  
  8. const float EDGE_THRESHOLD = 0.1;
  9. const float EDGE_THICKNESS = 1.0;
  10.  
  11. const float INFINITY = 1000.0;
  12.  
  13. uniform sampler2D sampler0;
  14. uniform sampler2D sampler1;
  15. uniform sampler2D sampler2;
  16.  
  17. uniform float near;
  18. uniform float far;
  19.  
  20. uniform float aspectRatio;
  21. uniform float displayHeight;
  22. uniform float displayWidth;
  23.  
  24. float getDepth(vec2 coord);
  25.  
  26. void main() {
  27.     gl_FragColor = texture2D(sampler0, gl_TexCoord[0].st);
  28.    
  29.     vec2 o11 = vec2(1.0, aspectRatio)*EDGE_THICKNESS/displayWidth;
  30.     vec2 base = gl_TexCoord[0].st - 2*o11;
  31.  
  32.     float depth = getDepth(gl_TexCoord[0].st);
  33.     float avg = depth;
  34.     float laplace = 24*depth;
  35.     float sample;
  36.     int n = 1;
  37.  
  38.     for (int i = 0; i < 5; ++i) {
  39.         for (int j = 0; j < 5; ++j) {
  40.             if (i != 2 || j != 2) {
  41.                 sample = getDepth(base + vec2(float(i) * o11.s, float(j) * o11.t));
  42.                 laplace -= sample;
  43.                 if (sample < 1.0) {
  44.                     ++n;
  45.                     avg += sample*sample;
  46.                 }
  47.             }
  48.         }
  49.     }
  50.    
  51.     avg /= n;
  52.  
  53.     if (laplace > EDGE_THRESHOLD) {
  54.         avg = clamp(avg, 0.0, 1.0);
  55.         gl_FragColor.rgb = mix(vec3(0.0), gl_Fog.color.rgb, 0.5*avg*clamp(depth, 0.0, 1.0));
  56.     }
  57. }
  58.  
  59. float getDepth(vec2 coord) {
  60.     // Return linearized depth in [0.0, 1.0]
  61.     float depth = texture2D(sampler1, coord).x;
  62.    
  63.     if (depth == 1.0) {
  64.         // Attempt to detect sky
  65.         return INFINITY;
  66.     }
  67.  
  68.     return (near - depth*far)/(near + depth*(far - near));
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement