Advertisement
Guest User

Edrem - Luminance Grayscale

a guest
Feb 5th, 2011
5,419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. // Grayscale shader by daxnitro.
  2. // Small edit by Edrem
  3. // It makes the green brighter =D
  4.  
  5. uniform sampler2D sampler0;
  6. uniform sampler2D sampler1;
  7. uniform sampler2D sampler2;
  8.  
  9. uniform float near;
  10. uniform float far;
  11.  
  12. float getBrightness(vec4 color);
  13. float getDepth(vec2 coord);
  14.  
  15. void applyEffect() {
  16.     float brightness = getBrightness(gl_FragColor);
  17.     gl_FragColor = vec4(brightness, brightness, brightness, gl_FragColor[3]);
  18. }
  19.  
  20. void main() {
  21.     vec4 baseColor = texture2D(sampler0, gl_TexCoord[0].st);
  22.    
  23.     gl_FragColor = baseColor;
  24.    
  25.     float depth = getDepth(gl_TexCoord[0].st);
  26.  
  27.     if (gl_FragColor[3] == 0.0) {
  28.         gl_FragColor = gl_Fog.color;
  29.     }
  30.  
  31.     applyEffect(); 
  32. }
  33.  
  34. float getBrightness(vec4 color) {
  35.     return color[0] * 0.299f + color[1] * 0.587f + color[2] * 0.114f;
  36. }
  37.  
  38. float getDepth(vec2 coord) {
  39.     float depth = texture2D(sampler1, coord).x;
  40.     float depth2 = texture2D(sampler2, coord).x;
  41.     if (depth2 < 1.0) {
  42.         depth = depth2;
  43.     }
  44.    
  45.     depth = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
  46.    
  47.     return depth;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement