Advertisement
Megusta

Cross Processing and Better Bloom

Apr 3rd, 2011
9,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //                                  Shader Modified From Martinsh's Blender GLSL 2D Filter Demo:                               //
  3. //http://blenderartists.org/forum/showthread.php?156482-HDR-many-simple-GLSL-2D-Filters-v2.0&s=bbeb20ac111931da170fd6f8fea28d25//
  4. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5.  
  6. uniform sampler2D sampler0;
  7.  
  8. const float BRIGHT_PASS_THRESHOLD = 0.5;
  9. const float BRIGHT_PASS_OFFSET = 0.5;
  10. float contrast = 1.05;
  11.  
  12. //Bloom
  13. #define blurclamp 0.002
  14. #define bias 0.01
  15.  
  16. #define KERNEL_SIZE  3.0
  17.  
  18. vec2 texcoord = vec2(gl_TexCoord[0]).st;
  19. vec4 texcolor = texture2D(sampler0, gl_TexCoord[0].st);
  20.  
  21. vec4 bright(vec2 coo)
  22. {
  23.     vec4 color = texture2D(sampler0, coo);
  24.    
  25.     color = max(color - BRIGHT_PASS_THRESHOLD, 0.0);
  26.    
  27.     return color / (color + BRIGHT_PASS_OFFSET);   
  28. }
  29. //
  30.  
  31. //Cross Processing
  32. vec4 gradient(vec4 coo)
  33. {
  34.     vec4 stripes = coo;
  35.     stripes.r =  stripes.r*1.3+0.01;
  36.     stripes.g = stripes.g*1.2;
  37.     stripes.b = stripes.b*0.7+0.15;
  38.     stripes.a = texcolor.a;
  39.     return stripes;
  40. }
  41. //
  42.  
  43. void main(void)
  44. {
  45.     vec2 blur = vec2(clamp( bias, -blurclamp, blurclamp ));
  46.    
  47.     vec4 col = vec4( 0, 0, 0, 0 );
  48.     for ( float x = -KERNEL_SIZE + 1.0; x < KERNEL_SIZE; x += 1.0 )
  49.     {
  50.     for ( float y = -KERNEL_SIZE + 1.0; y < KERNEL_SIZE; y += 1.0 )
  51.     {
  52.          col += bright( texcoord + vec2( blur.x * x, blur.y * y ) );
  53.     }
  54.     }
  55.     col /= ((KERNEL_SIZE+KERNEL_SIZE)-1.0)*((KERNEL_SIZE+KERNEL_SIZE)-1.0);
  56.    
  57.         vec4 value = texture2D(sampler0, texcoord);
  58.        
  59.         vec4 fin = col + gradient(value);
  60.        
  61.     gl_FragColor = (fin - 0.5) * contrast + 0.5;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement