Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <shader language="GLSL">
- <vertex><![CDATA[
- void main()
- {
- gl_Position = ftransform();
- gl_TexCoord[0] = gl_MultiTexCoord0;
- }
- ]]></vertex>
- <fragment><![CDATA[
- uniform sampler2D rubyTexture;
- uniform vec2 rubyTextureSize;
- uniform vec2 rubyInputSize;
- uniform vec2 rubyOutputSize;
- #define round(x) floor( (x) + 0.5 )
- #define gamma 2.2
- #define tex2D(x,y) pow(texture2D(x,y),vec4(gamma))
- void main()
- {
- vec2 texelSize = 1.0 / rubyTextureSize;
- vec2 subtexelSize = texelSize / vec2(3.0,1.0);
- vec2 range = 1.0/rubyOutputSize * rubyInputSize/rubyTextureSize / 2.0 * 0.99;
- float left = gl_TexCoord[0].x - range.x;
- float top = gl_TexCoord[0].y + range.y;
- float right = gl_TexCoord[0].x + range.x;
- float bottom = gl_TexCoord[0].y - range.y;
- float subpix = mod(round(gl_TexCoord[0].x/subtexelSize.x),3.0);
- vec4 lcol, rcol;
- float c0 = clamp(1.0-subpix,0.0,1.0);
- float c1 = clamp(2.0-subpix,0.0,1.0)*(1.0-c0);
- float c2 = (1.0-c0)*(1.0-c1);
- lcol = vec4(c1,c2,c0,0.0);
- rcol = vec4(c0,c1,c2,0.0);
- vec4 topLeftColor = tex2D(rubyTexture, (floor(vec2(left, top) / texelSize) + 0.5) * texelSize) * lcol;
- vec4 bottomRightColor = tex2D(rubyTexture, (floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize) * rcol;
- vec4 bottomLeftColor = tex2D(rubyTexture, (floor(vec2(left, bottom) / texelSize) + 0.5) * texelSize) * lcol;
- vec4 topRightColor = tex2D(rubyTexture, (floor(vec2(right, top) / texelSize) + 0.5) * texelSize) * rcol;
- vec2 border = round(gl_TexCoord[0].st/subtexelSize);
- float shrx = 0.0;
- float shry = 0.02;
- vec2 bordertl = clamp((border+vec2(-shrx,+shry)) * subtexelSize,
- vec2(left, bottom), vec2(right, top));
- vec2 borderbl = clamp((border+vec2(-shrx,-shry)) * subtexelSize,
- vec2(left, bottom), vec2(right, top));
- vec2 borderbr = clamp((border+vec2(+shrx,-shry)) * subtexelSize,
- vec2(left, bottom), vec2(right, top));
- vec2 bordertr = clamp((border+vec2(+shrx,+shry)) * subtexelSize,
- vec2(left, bottom), vec2(right, top));
- float totalArea = 4.0 * range.x * range.y;
- vec4 averageColor;
- averageColor = ((bordertl.x - left) * (top - bordertl.y) / totalArea) * topLeftColor;
- averageColor += ((right - borderbr.x) * (borderbr.y - bottom) / totalArea) * bottomRightColor;
- averageColor += ((borderbl.x - left) * (borderbl.y - bottom) / totalArea) * bottomLeftColor;
- averageColor += ((right - bordertr.x) * (top - bordertr.y) / totalArea) * topRightColor;
- gl_FragColor = pow(averageColor,vec4(1.0/gamma));
- }
- ]]></fragment>
- </shader>
Add Comment
Please, Sign In to add comment