Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This requires a linear mag filter
- vec4 bicubic(sampler2DArray sampler, vec3 coords) {
- //Gather and process some basics (TODO: move to vertex shader)
- vec2 size = vec2(textureSize(sampler, int(textureQueryLod(sampler,coords.xy).x)).xy);
- vec2 invsize = 1./size;
- coords *= vec3(size,1);
- //Compute central coordinate of upper left texel of the nearest 4 texel patch
- vec2 texelCoords = floor(coords.xy-0.5)+0.5;
- vec2 f = coords.xy-texelCoords;
- //Powers
- vec2 f2 = f*f;
- vec2 f3 = f2 * f;
- //Compute weights
- vec2 w0 = f2 - 0.5 * (f3 + f);
- vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.;
- vec2 w3 = 0.5 * (f3-f2);
- vec2 w2 = 1. - w0 - w1 - w3;
- //Compute sampling coordinates
- vec2 s0 = w0 + w1;
- vec2 s1 = w2 + w3;
- vec2 f0 = w1 / s0;
- vec2 f1 = w3 / s1;
- vec2 t0 = texelCoords - 1. + f0;
- vec2 t1 = texelCoords + 1. + f1;
- t0*=invsize;
- t1*=invsize;
- return texture(sampler, vec3(t0,coords.z)) * s0.x * s0.y
- + texture(sampler, vec3(t1.x,t0.y,coords.z)) * s1.x * s0.y
- + texture(sampler, vec3(t0.x,t1.y,coords.z)) * s0.x * s1.y
- + texture(sampler, vec3(t1,coords.z)) * s1.x * s1.y;
- }
- void main()
- {
- if (UV.x>0.5){
- vec3 tUV = UV-vec3(0.5,0,0);
- vec2 size = vec2(textureSize(sampler, int(textureQueryLod(sampler,UV.xy).x)).xy);
- tUV.xy = floor(size*tUV.xy)+0.5;
- tUV.xy /= size;
- fragColor = vec4(texture(sampler,tUV).rgb,tracer);
- } else {
- fragColor = vec4(bicubic(sampler,UV).rgb,tracer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement