Guest User

Untitled

a guest
Jan 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.88 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <shader language="GLSL">
  3.   <vertex><![CDATA[
  4.    void main()
  5.    {
  6.      gl_Position    = ftransform();
  7.      gl_TexCoord[0] = gl_MultiTexCoord0;
  8.    }
  9.  ]]></vertex>
  10.  
  11.   <fragment><![CDATA[
  12.    uniform sampler2D rubyTexture;
  13.    uniform vec2      rubyTextureSize;
  14.    uniform vec2      rubyInputSize;
  15.    uniform vec2      rubyOutputSize;
  16.  
  17.    #define round(x) floor( (x) + 0.5 )
  18.    #define gamma 2.2
  19.    #define tex2D(x,y) pow(texture2D(x,y),vec4(gamma))
  20.  
  21.    void main()
  22.    {
  23.      vec2 texelSize = 1.0 / rubyTextureSize;
  24.      vec2 subtexelSize = texelSize / vec2(3.0,1.0);
  25.  
  26.      vec2 range = 1.0/rubyOutputSize * rubyInputSize/rubyTextureSize / 2.0 * 0.99;
  27.  
  28.      float left   = gl_TexCoord[0].x - range.x;
  29.      float top    = gl_TexCoord[0].y + range.y;
  30.      float right  = gl_TexCoord[0].x + range.x;
  31.      float bottom = gl_TexCoord[0].y - range.y;
  32.  
  33.      float subpix = mod(round(gl_TexCoord[0].x/subtexelSize.x),3.0);
  34.      vec4 lcol, rcol;
  35.      float c0 = clamp(1.0-subpix,0.0,1.0);
  36.      float c1 = clamp(2.0-subpix,0.0,1.0)*(1.0-c0);
  37.      float c2 = (1.0-c0)*(1.0-c1);
  38.      lcol = vec4(c1,c2,c0,0.0);
  39.      rcol = vec4(c0,c1,c2,0.0);
  40.  
  41.      vec4 topLeftColor     = tex2D(rubyTexture, (floor(vec2(left, top)     / texelSize) + 0.5) * texelSize) * lcol;
  42.      vec4 bottomRightColor = tex2D(rubyTexture, (floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize) * rcol;
  43.      vec4 bottomLeftColor  = tex2D(rubyTexture, (floor(vec2(left, bottom)  / texelSize) + 0.5) * texelSize) * lcol;
  44.      vec4 topRightColor    = tex2D(rubyTexture, (floor(vec2(right, top)    / texelSize) + 0.5) * texelSize) * rcol;
  45.  
  46.      vec2 border = round(gl_TexCoord[0].st/subtexelSize);
  47.      float shrx = 0.0;
  48.      float shry = 0.02;
  49.      vec2 bordertl = clamp((border+vec2(-shrx,+shry)) * subtexelSize,
  50.                            vec2(left, bottom), vec2(right, top));
  51.      vec2 borderbl = clamp((border+vec2(-shrx,-shry)) * subtexelSize,
  52.                            vec2(left, bottom), vec2(right, top));
  53.      vec2 borderbr = clamp((border+vec2(+shrx,-shry)) * subtexelSize,
  54.                            vec2(left, bottom), vec2(right, top));
  55.      vec2 bordertr = clamp((border+vec2(+shrx,+shry)) * subtexelSize,
  56.                            vec2(left, bottom), vec2(right, top));
  57.      float totalArea = 4.0 * range.x * range.y;
  58.  
  59.      vec4 averageColor;
  60.      averageColor  = ((bordertl.x - left)  * (top - bordertl.y)    / totalArea) * topLeftColor;
  61.      averageColor += ((right - borderbr.x) * (borderbr.y - bottom) / totalArea) * bottomRightColor;
  62.      averageColor += ((borderbl.x - left)  * (borderbl.y - bottom) / totalArea) * bottomLeftColor;
  63.      averageColor += ((right - bordertr.x) * (top - bordertr.y)    / totalArea) * topRightColor;
  64.  
  65.      gl_FragColor = pow(averageColor,vec4(1.0/gamma));
  66.    }
  67.  ]]></fragment>
  68. </shader>
Add Comment
Please, Sign In to add comment