[cairo] [RFC] Cairo GLES2 and GL_CLAMP_TO_BORDER
Martin Krastev
martin.krastev at genesi-usa.com
Tue Feb 22 15:17:59 PST 2011
Hi Alexandros,
I have reasons to believe the skeletal fragment shader below is more-or-less
what you've been looking for. Please note it has been tuned for emulating
GL_CLAMP_TO_BORDER with bilinear only, and as such it has certain
requirements for the TMU setup:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Also, I've left some things, which would naturally enter as uniforms, as
constants here, to underline how those expressions can be done host-side.
And oh, the border color is implied black : )
varying vec2 tc_i; // texcoord interpolant, pardon my
archaic naming convention
uniform sampler2D albedo;
const vec2 dim = vec2(4.0);
const vec2 edge = vec2(0.5) - vec2(0.5) / dim;
const vec2 bord = vec2(0.5) + vec2(0.5) / dim;
void main()
{
vec2 fade = vec2(1.0);
vec2 tc_d = abs(tc_i - 0.5);
if (tc_d.x > edge.x)
fade.x = (bord.x - tc_d.x) * dim.x;
if (tc_d.y > edge.y)
fade.y = (bord.y - tc_d.y) * dim.y;
fade = clamp(fade, 0.0, 1.0);
gl_FragColor = texture2D(albedo, tc_i) * fade.x * fade.y;
}
Best regards,
martin
ps: Judging by your postings on the subject, I think you were getting to
that solution yourself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110223/e716b680/attachment.html>
More information about the cairo
mailing list