[cairo] [RFC] Cairo GLES2 and GL_CLAMP_TO_BORDER
Alexandros Frantzis
alexandros.frantzis at linaro.org
Mon Feb 21 07:43:05 PST 2011
On Fri, Feb 18, 2011 at 06:26:37PM +0200, Jonathan Morton wrote:
> On Fri, 2011-02-18 at 18:13 +0200, Alexandros Frantzis wrote:
> > create W+1 x H+1 textures
>
> You need four borders, so: s/+1/+2/g.
Oops. Right, thanks!
>
> Another alternative would be to compute the edge fade-to-transparent in
> the shader, using CLAMP_TO_EDGE on the texture itself. The only extra
> information required by the shader for this would be the texture pixel
> dimensions, which would be required anyway if the texture is "manually"
> filtered. I think these could be passed in uniforms.
>
> As a first pass:
>
> sampler2D tex;
> uniform vec2 dims;
> varying vec2 coords;
> vec2 fades = clamp(dims * (1.0 - abs(coords - 0.5)), 0.0, 1.0);
> vec4 colour = texture(tex, coords) * fades.x * fades.y;
> ...
>
The expression I am currently experimenting with is:
clamp(-abs(dims * (coords - 0.5)) + (dims + vec2(1, 1)) * 0.5, 0.0, 1.0)
It works well but we still get some extra failures in the test suite (vs
using GL_CLAMP_TO_BORDER). The differences are small and are mostly
located near the edges. I am still investigating, but my initial guess
is that they are caused by the fact that we are trying to apply this
fade-to-transparency to values that have already been bilinearly
filtered.
The only way around this is to use GL_NEAREST and perform the full
bilinear filtering in the shader ourselves. However, I doubt that this
is worth the computational cost. The current results, although not pixel
perfect, are a reasonable trade-off.
Thanks,
Alexandros
More information about the cairo
mailing list