Advertisement
onilink_

Untitled

Mar 16th, 2022
2,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 120
  2.  
  3. varying vec2 uv;
  4. varying vec4 color;
  5.  
  6. uniform sampler2D tex;
  7. uniform vec4 blending_color;
  8. uniform vec2 texture_size;
  9.  
  10. uniform vec2 k;
  11.  
  12. float kernel(float x)
  13. {
  14.     x = abs(x);
  15.     if(x < k.x) {
  16.         return 1 - x * k.y;
  17.     }
  18.     return 0.0;
  19. }
  20.  
  21. vec4 filtering(sampler2D texture_sampler, vec2 uv)
  22. {
  23.     // size of one texel (< 1.0)
  24.     float texel_wid = 1.0 / texture_size.x;
  25.     float texel_hei = 1.0 / texture_size.y;
  26.    
  27.     vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
  28.     vec4 denom = vec4(0.0, 0.0, 0.0, 0.0);
  29.    
  30.     // get the decimal part
  31.     float a = fract(uv.x * texture_size.x);
  32.     float b = fract(uv.y * texture_size.y);
  33.    
  34.    
  35.     // Sampling
  36.     float f1  = kernel(-a);
  37.    
  38.     {
  39.         vec4 color = texture2D(texture_sampler, uv);
  40.        
  41.         float f = f1 * kernel(b);
  42.         vec4 c1c2 = vec4(f, f, f, f);
  43.        
  44.         sum = sum + (color * c1c2);
  45.         denom = denom + c1c2;
  46.        
  47.        
  48.         color = texture2D(texture_sampler, uv + vec2(0, texel_hei));
  49.        
  50.         f = f1 * kernel(b - 1.0);
  51.         c1c2 = vec4(f, f, f, f);
  52.        
  53.         sum = sum + (color * c1c2);
  54.         denom = denom + c1c2;
  55.     }
  56.    
  57.     f1 = kernel(1.0 - a);
  58.    
  59.     {
  60.         vec4 color = texture2D(texture_sampler, uv + vec2(texel_wid, 0));
  61.        
  62.         float f = f1 * kernel(b);
  63.         vec4 c1c2 = vec4(f, f, f, f);
  64.        
  65.         sum = sum + (color * c1c2);
  66.         denom = denom + c1c2;
  67.        
  68.        
  69.         color = texture2D(texture_sampler, uv + vec2(texel_wid, texel_hei));
  70.        
  71.         f = f1 * kernel(b - 1.0);
  72.         c1c2 = vec4(f, f, f, f);
  73.        
  74.         sum = sum + (color * c1c2);
  75.         denom = denom + c1c2;
  76.     }
  77.    
  78.     return sum / denom;
  79. }
  80.  
  81. void main()
  82. {
  83.     gl_FragColor = filtering(tex, uv) * color * blending_color;
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement