Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- varying vec2 uv;
- varying vec4 color;
- uniform sampler2D tex;
- uniform vec4 blending_color;
- uniform vec2 texture_size;
- uniform vec2 k;
- float kernel(float x)
- {
- x = abs(x);
- if(x < k.x) {
- return 1 - x * k.y;
- }
- return 0.0;
- }
- vec4 filtering(sampler2D texture_sampler, vec2 uv)
- {
- // size of one texel (< 1.0)
- float texel_wid = 1.0 / texture_size.x;
- float texel_hei = 1.0 / texture_size.y;
- vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 denom = vec4(0.0, 0.0, 0.0, 0.0);
- // get the decimal part
- float a = fract(uv.x * texture_size.x);
- float b = fract(uv.y * texture_size.y);
- // Sampling
- float f1 = kernel(-a);
- {
- vec4 color = texture2D(texture_sampler, uv);
- float f = f1 * kernel(b);
- vec4 c1c2 = vec4(f, f, f, f);
- sum = sum + (color * c1c2);
- denom = denom + c1c2;
- color = texture2D(texture_sampler, uv + vec2(0, texel_hei));
- f = f1 * kernel(b - 1.0);
- c1c2 = vec4(f, f, f, f);
- sum = sum + (color * c1c2);
- denom = denom + c1c2;
- }
- f1 = kernel(1.0 - a);
- {
- vec4 color = texture2D(texture_sampler, uv + vec2(texel_wid, 0));
- float f = f1 * kernel(b);
- vec4 c1c2 = vec4(f, f, f, f);
- sum = sum + (color * c1c2);
- denom = denom + c1c2;
- color = texture2D(texture_sampler, uv + vec2(texel_wid, texel_hei));
- f = f1 * kernel(b - 1.0);
- c1c2 = vec4(f, f, f, f);
- sum = sum + (color * c1c2);
- denom = denom + c1c2;
- }
- return sum / denom;
- }
- void main()
- {
- gl_FragColor = filtering(tex, uv) * color * blending_color;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement