1 <?xml version="1.0" encoding="UTF-8"?>
2 <shader language="GLSL">
6 gl_Position = ftransform();
7 gl_TexCoord[0] = gl_MultiTexCoord0;
11 <fragment filter="nearest"><![CDATA[
12 uniform sampler2D rubyTexture;
13 uniform vec2 rubyTextureSize;
15 #define round(x) floor( (x) + 0.5 )
19 vec2 texelSize = 1.0 / rubyTextureSize;
22 range.x = dFdx(gl_TexCoord[0].x) / 2.0 * 0.99;
23 range.y = dFdy(gl_TexCoord[0].y) / 2.0 * 0.99;
25 float left = gl_TexCoord[0].x - range.x;
26 float top = gl_TexCoord[0].y + range.y;
27 float right = gl_TexCoord[0].x + range.x;
28 float bottom = gl_TexCoord[0].y - range.y;
30 vec4 topLeftColor = texture2D(rubyTexture, (floor(vec2(left, top) / texelSize) + 0.5) * texelSize);
31 vec4 bottomRightColor = texture2D(rubyTexture, (floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize);
32 vec4 bottomLeftColor = texture2D(rubyTexture, (floor(vec2(left, bottom) / texelSize) + 0.5) * texelSize);
33 vec4 topRightColor = texture2D(rubyTexture, (floor(vec2(right, top) / texelSize) + 0.5) * texelSize);
36 round(gl_TexCoord[0].st / texelSize) * texelSize,
41 float totalArea = 4.0 * range.x * range.y;
44 averageColor = ((border.x - left) * (top - border.y) / totalArea) * topLeftColor;
45 averageColor += ((right - border.x) * (border.y - bottom) / totalArea) * bottomRightColor;
46 averageColor += ((border.x - left) * (border.y - bottom) / totalArea) * bottomLeftColor;
47 averageColor += ((right - border.x) * (top - border.y) / totalArea) * topRightColor;
49 gl_FragColor = averageColor;