Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 150
  2.  
  3. #in red
  4. #in green
  5. #in blue
  6. #in gain
  7. #in gamma
  8. #in blacklevel
  9. #in ambient
  10. #in BGR
  11.  
  12. #define outgamma 2.2
  13.  
  14. uniform sampler2D source[];
  15. uniform vec4 sourceSize[];
  16. uniform vec4 targetSize;
  17.  
  18. in Vertex {
  19.   vec2 texCoord;
  20. };
  21.  
  22. out vec4 fragColor;
  23.  
  24. #define fetch_offset(coord,offset) (pow(vec3(gain) * texelFetchOffset(source[0], (coord), 0, (offset)).rgb + vec3(blacklevel), vec3(gamma)) + vec3(ambient))
  25.  
  26. // integral of (1 - x^2 - x^4 + x^6)^2
  27. const float coeffs_x[] = float[](1.0, -2.0/3.0, -1.0/5.0, 4.0/7.0, -1.0/9.0, -2.0/11.0, 1.0/13.0);
  28. // integral of (1 - 2x^4 + x^6)^2
  29. const float coeffs_y[] = float[](1.0,      0.0, -4.0/5.0, 2.0/7.0,  4.0/9.0, -4.0/11.0, 1.0/13.0);
  30. float intsmear_func(float z, float coeffs[7])
  31. {
  32.   float z2 = z*z;
  33.   float zn = z;
  34.   float ret = 0.0;
  35.   for (int i = 0; i < 7; i++) {
  36.     ret += zn*coeffs[i];
  37.     zn *= z2;
  38.   }
  39.   return ret;
  40. }
  41. float intsmear(float x, float dx, float d, float coeffs[7])
  42. {
  43.   float zl = clamp((x-dx*0.5)/d,-1.0,1.0);
  44.   float zh = clamp((x+dx*0.5)/d,-1.0,1.0);
  45.   return d * ( intsmear_func(zh,coeffs) - intsmear_func(zl,coeffs) )/dx;
  46. }
  47.  
  48. void main()
  49. {
  50.   vec2 texelSize = 1.0 / sourceSize[0].xy;
  51.   vec2 range = sourceSize[0].xy / (targetSize.xy * sourceSize[0].xy);
  52.  
  53.   vec3 cred   = pow(red,   vec3(outgamma));
  54.   vec3 cgreen = pow(green, vec3(outgamma));
  55.   vec3 cblue  = pow(blue,  vec3(outgamma));
  56.  
  57.   ivec2 tli = ivec2(floor(texCoord/texelSize-vec2(0.4999)));
  58.  
  59.   vec3 lcol, rcol;
  60.   float subpix = (texCoord.x/texelSize.x - 0.4999 - float(tli.x))*3.0;
  61.   float rsubpix = range.x/texelSize.x * 3.0;
  62.   lcol = vec3(intsmear(subpix+1.0,rsubpix, 1.5, coeffs_x),
  63.               intsmear(subpix    ,rsubpix, 1.5, coeffs_x),
  64.               intsmear(subpix-1.0,rsubpix, 1.5, coeffs_x));
  65.   rcol = vec3(intsmear(subpix-2.0,rsubpix, 1.5, coeffs_x),
  66.               intsmear(subpix-3.0,rsubpix, 1.5, coeffs_x),
  67.               intsmear(subpix-4.0,rsubpix, 1.5, coeffs_x));
  68. #ifdef BGR
  69.   lcol.rgb = lcol.bgr;
  70.   rcol.rgb = rcol.bgr;
  71. #endif
  72.   float tcol, bcol;
  73.   subpix = texCoord.y/texelSize.y - 0.4999 - float(tli.y);
  74.   rsubpix = range.y/texelSize.y;
  75.   tcol = intsmear(subpix    ,rsubpix, 0.63, coeffs_y);
  76.   bcol = intsmear(subpix-1.0,rsubpix, 0.63, coeffs_y);
  77.  
  78.   vec3 topLeftColor     = fetch_offset(tli, ivec2(0,0)) * lcol * vec3(tcol);
  79.   vec3 bottomRightColor = fetch_offset(tli, ivec2(1,1)) * rcol * vec3(bcol);
  80.   vec3 bottomLeftColor  = fetch_offset(tli, ivec2(0,1)) * lcol * vec3(bcol);
  81.   vec3 topRightColor    = fetch_offset(tli, ivec2(1,0)) * rcol * vec3(tcol);
  82.  
  83.   vec3 averageColor = topLeftColor + bottomRightColor + bottomLeftColor + topRightColor;
  84.  
  85.   averageColor = mat3x3(cred, cgreen, cblue) * averageColor;
  86.  
  87.   fragColor = vec4(pow(averageColor,vec3(1.0/outgamma)),0.0);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement