1 <?xml version="1.0" encoding="UTF-8"?>
3 Copyright (c) 2011, 2012 Fes
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted, provided that the above
7 copyright notice and this permission notice appear in all copies.
9 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 (Fes gave their permission to have this shader distributed under this
18 licence in this forum post:
20 http://board.byuu.org/viewtopic.php?p=57295#p57295
25 <shader language="GLSL">
29 gl_Position = ftransform();
30 gl_TexCoord[0] = gl_MultiTexCoord0;
34 <fragment filter="nearest"><![CDATA[
35 uniform sampler2D rubyTexture;
36 uniform vec2 rubyTextureSize;
38 #define round(x) floor( (x) + 0.5 )
42 vec2 texelSize = 1.0 / rubyTextureSize;
43 vec2 texCoord = gl_TexCoord[0].xy;
45 vec2 range = vec2(abs(dFdx(texCoord.x)), abs(dFdy(texCoord.y)));
46 range = range / 2.0 * 0.999;
48 float left = texCoord.x - range.x;
49 float top = texCoord.y + range.y;
50 float right = texCoord.x + range.x;
51 float bottom = texCoord.y - range.y;
53 vec4 topLeftColor = texture2D(rubyTexture, vec2(left, top));
54 vec4 bottomRightColor = texture2D(rubyTexture, vec2(right, bottom));
55 vec4 bottomLeftColor = texture2D(rubyTexture, vec2(left, bottom));
56 vec4 topRightColor = texture2D(rubyTexture, vec2(right, top));
59 round(texCoord / texelSize) * texelSize,
64 float totalArea = 4.0 * range.x * range.y;
67 averageColor = ((border.x - left) * (top - border.y) / totalArea) * topLeftColor;
68 averageColor += ((right - border.x) * (border.y - bottom) / totalArea) * bottomRightColor;
69 averageColor += ((border.x - left) * (border.y - bottom) / totalArea) * bottomLeftColor;
70 averageColor += ((right - border.x) * (top - border.y) / totalArea) * topRightColor;
72 gl_FragColor = averageColor;