Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. //This requires a linear mag filter
  2. vec4 bicubic(sampler2DArray sampler, vec3 coords) {
  3.   //Gather and process some basics (TODO: move to vertex shader)
  4.   vec2 size = vec2(textureSize(sampler, int(textureQueryLod(sampler,coords.xy).x)).xy);
  5.   vec2 invsize = 1./size;
  6.   coords *= vec3(size,1);
  7.  
  8.   //Compute central coordinate of upper left texel of the nearest 4 texel patch
  9.   vec2 texelCoords = floor(coords.xy-0.5)+0.5;
  10.   vec2 f = coords.xy-texelCoords;
  11.  
  12.   //Powers
  13.   vec2 f2 = f*f;
  14.   vec2 f3 = f2 * f;
  15.  
  16.   //Compute weights
  17.   vec2 w0 = f2 - 0.5 * (f3 + f);
  18.   vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.;
  19.   vec2 w3 = 0.5 * (f3-f2);
  20.   vec2 w2 = 1. - w0 - w1 - w3;
  21.  
  22.   //Compute sampling coordinates
  23.   vec2 s0 = w0 + w1;
  24.   vec2 s1 = w2 + w3;
  25.  
  26.   vec2 f0 = w1 / s0;
  27.   vec2 f1 = w3 / s1;
  28.  
  29.   vec2 t0 = texelCoords - 1. + f0;
  30.   vec2 t1 = texelCoords + 1. + f1;
  31.   t0*=invsize;
  32.   t1*=invsize;
  33.  
  34.   return texture(sampler, vec3(t0,coords.z)) * s0.x * s0.y
  35.   + texture(sampler, vec3(t1.x,t0.y,coords.z)) * s1.x * s0.y
  36.   + texture(sampler, vec3(t0.x,t1.y,coords.z)) * s0.x * s1.y
  37.   + texture(sampler, vec3(t1,coords.z)) * s1.x * s1.y;
  38. }
  39.  
  40. void main()
  41. {
  42. if (UV.x>0.5){
  43. vec3 tUV = UV-vec3(0.5,0,0);
  44. vec2 size = vec2(textureSize(sampler, int(textureQueryLod(sampler,UV.xy).x)).xy);
  45.   tUV.xy = floor(size*tUV.xy)+0.5;
  46.   tUV.xy /= size;
  47.  
  48.  
  49. fragColor = vec4(texture(sampler,tUV).rgb,tracer);
  50. } else {
  51. fragColor = vec4(bicubic(sampler,UV).rgb,tracer);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement