summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Dapena Paz <jdapena@igalia.com>2013-12-17 12:19:41 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-17 20:35:54 +0100
commit3bb9504f1ba458fac713200cb4dfcb2592c8f0ea (patch)
tree1e9a74917e854849924fb658de0f300854e5cbd4
parent8a716a29721d900069d82878c45cf87a356adba3 (diff)
[texmap] Borders on rotating images are hidden/wrongly rendered with edge distance antialiasing
https://bugs.webkit.org/show_bug.cgi?id=124653 Reviewed by Noam Rosenthal. Texture mapper edge distance antialiasing texture sampling was causing borders to be shaded (and made them almost disappear in some cases). This was because calculation of sampling happened on vertex shader, so the border of the texture would go to the border of the inflation area. What algorithm should do is sampling the border pixel for all the inflation area (it is the closest pixel to all the samples in inflation area), and then use the standard sampling for the other parts of the texture. No new test because this is already covered by test transforms/3d/point-mapping/3d-point-mapping.html * platform/graphics/texmap/TextureMapperShaderProgram.cpp: fix edge distance antialiasing texture sampling. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160096 268f45cc-cd09-0410-ab3c-d52691b4dbfc Task-number: QTBUG-34975 Change-Id: I77654e806d6b198680cb2e6c0dbc1a6adb295222 Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
-rw-r--r--Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp65
1 files changed, 43 insertions, 22 deletions
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp
index 3f64c4b8a..f4b9a7e98 100644
--- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp
@@ -127,6 +127,7 @@ static const char* vertexTemplate =
uniform mat4 u_textureSpaceMatrix;
varying vec2 v_texCoord;
+ varying vec2 v_transformedTexCoord;
varying float v_antialias;
void noop(inout vec2 dummyParameter) { }
@@ -172,9 +173,9 @@ static const char* vertexTemplate =
vec2 position = a_vertex.xy;
applyAntialiasingIfNeeded(position);
- // The texture position needs to be clamped to 0..1 before the texture matrix is applied.
+ v_texCoord = position;
vec4 clampedPosition = clamp(vec4(position, 0., 1.), 0., 1.);
- v_texCoord = (u_textureSpaceMatrix * clampedPosition).xy;
+ v_transformedTexCoord = (u_textureSpaceMatrix * clampedPosition).xy;
gl_Position = u_projectionMatrix * u_modelViewMatrix * vec4(position, 0., 1.);
}
);
@@ -188,6 +189,13 @@ static const char* vertexTemplate =
GLSL_DIRECTIVE(define SamplerFunction texture2D) \
GLSL_DIRECTIVE(endif)
+#define ANTIALIASING_TEX_COORD_DIRECTIVE \
+ GLSL_DIRECTIVE(if defined(ENABLE_Antialiasing) && defined(ENABLE_Texture)) \
+ GLSL_DIRECTIVE(define transformTexCoord fragmentTransformTexCoord) \
+ GLSL_DIRECTIVE(else) \
+ GLSL_DIRECTIVE(define transformTexCoord vertexTransformTexCoord) \
+ GLSL_DIRECTIVE(endif)
+
#define ENABLE_APPLIER(Name) "#define ENABLE_"#Name"\n#define apply"#Name"IfNeeded apply"#Name"\n"
#define DISABLE_APPLIER(Name) "#define apply"#Name"IfNeeded noop\n"
#define BLUR_CONSTANTS \
@@ -197,6 +205,7 @@ static const char* vertexTemplate =
static const char* fragmentTemplate =
RECT_TEXTURE_DIRECTIVE
+ ANTIALIASING_TEX_COORD_DIRECTIVE
BLUR_CONSTANTS
STRINGIFY(
precision mediump float;
@@ -205,17 +214,28 @@ static const char* fragmentTemplate =
uniform float u_opacity;
varying float v_antialias;
varying vec2 v_texCoord;
+ varying vec2 v_transformedTexCoord;
uniform float u_filterAmount;
uniform vec2 u_blurRadius;
uniform vec2 u_shadowOffset;
uniform vec4 u_color;
uniform float u_gaussianKernel[GAUSSIAN_KERNEL_HALF_WIDTH];
+ uniform mat4 u_textureSpaceMatrix;
void noop(inout vec4 dummyParameter) { }
+ void noop(inout vec4 dummyParameter, vec2 texCoord) { }
+
+ float antialias() { return smoothstep(0., 1., v_antialias); }
+
+ vec2 fragmentTransformTexCoord()
+ {
+ vec4 clampedPosition = clamp(vec4(v_texCoord, 0., 1.), 0., 1.);
+ return (u_textureSpaceMatrix * clampedPosition).xy;
+ }
- float antialias() { return smoothstep(v_antialias, 0., 1.); }
+ vec2 vertexTransformTexCoord() { return v_transformedTexCoord; }
- void applyTexture(inout vec4 color) { color = SamplerFunction(s_sampler, v_texCoord); }
+ void applyTexture(inout vec4 color, vec2 texCoord) { color = SamplerFunction(s_sampler, texCoord); }
void applyOpacity(inout vec4 color) { color *= u_opacity; }
void applyAntialiasing(inout vec4 color) { color *= antialias(); }
@@ -278,35 +298,35 @@ static const char* fragmentTemplate =
color = vec4(color.r, color.g, color.b, color.a * u_filterAmount);
}
- vec4 sampleColorAtRadius(float radius)
+ vec4 sampleColorAtRadius(float radius, vec2 texCoord)
{
- vec2 coord = v_texCoord + radius * u_blurRadius;
+ vec2 coord = texCoord + radius * u_blurRadius;
return SamplerFunction(s_sampler, coord) * float(coord.x > 0. && coord.y > 0. && coord.x < 1. && coord.y < 1.);
}
- float sampleAlphaAtRadius(float radius)
+ float sampleAlphaAtRadius(float radius, vec2 texCoord)
{
- vec2 coord = v_texCoord - u_shadowOffset + radius * u_blurRadius;
+ vec2 coord = texCoord - u_shadowOffset + radius * u_blurRadius;
return SamplerFunction(s_sampler, coord).a * float(coord.x > 0. && coord.y > 0. && coord.x < 1. && coord.y < 1.);
}
- void applyBlurFilter(inout vec4 color)
+ void applyBlurFilter(inout vec4 color, vec2 texCoord)
{
- vec4 total = sampleColorAtRadius(0.) * u_gaussianKernel[0];
+ vec4 total = sampleColorAtRadius(0., texCoord) * u_gaussianKernel[0];
for (int i = 1; i < GAUSSIAN_KERNEL_HALF_WIDTH; i++) {
- total += sampleColorAtRadius(float(i) * GAUSSIAN_KERNEL_STEP) * u_gaussianKernel[i];
- total += sampleColorAtRadius(float(-1 * i) * GAUSSIAN_KERNEL_STEP) * u_gaussianKernel[i];
+ total += sampleColorAtRadius(float(i) * GAUSSIAN_KERNEL_STEP, texCoord) * u_gaussianKernel[i];
+ total += sampleColorAtRadius(float(-1 * i) * GAUSSIAN_KERNEL_STEP, texCoord) * u_gaussianKernel[i];
}
color = total;
}
- void applyAlphaBlur(inout vec4 color)
+ void applyAlphaBlur(inout vec4 color, vec2 texCoord)
{
- float total = sampleAlphaAtRadius(0.) * u_gaussianKernel[0];
+ float total = sampleAlphaAtRadius(0., texCoord) * u_gaussianKernel[0];
for (int i = 1; i < GAUSSIAN_KERNEL_HALF_WIDTH; i++) {
- total += sampleAlphaAtRadius(float(i) * GAUSSIAN_KERNEL_STEP) * u_gaussianKernel[i];
- total += sampleAlphaAtRadius(float(-1 * i) * GAUSSIAN_KERNEL_STEP) * u_gaussianKernel[i];
+ total += sampleAlphaAtRadius(float(i) * GAUSSIAN_KERNEL_STEP, texCoord) * u_gaussianKernel[i];
+ total += sampleAlphaAtRadius(float(-1 * i) * GAUSSIAN_KERNEL_STEP, texCoord) * u_gaussianKernel[i];
}
color *= total;
@@ -314,9 +334,9 @@ static const char* fragmentTemplate =
vec4 sourceOver(vec4 src, vec4 dst) { return src + dst * (1. - dst.a); }
- void applyContentTexture(inout vec4 color)
+ void applyContentTexture(inout vec4 color, vec2 texCoord)
{
- vec4 contentColor = texture2D(s_contentTexture, v_texCoord);
+ vec4 contentColor = texture2D(s_contentTexture, texCoord);
color = sourceOver(contentColor, color);
}
@@ -325,7 +345,8 @@ static const char* fragmentTemplate =
void main(void)
{
vec4 color = vec4(1., 1., 1., 1.);
- applyTextureIfNeeded(color);
+ vec2 texCoord = transformTexCoord();
+ applyTextureIfNeeded(color, texCoord);
applySolidColorIfNeeded(color);
applyAntialiasingIfNeeded(color);
applyOpacityIfNeeded(color);
@@ -337,9 +358,9 @@ static const char* fragmentTemplate =
applyBrightnessFilterIfNeeded(color);
applyContrastFilterIfNeeded(color);
applyOpacityFilterIfNeeded(color);
- applyBlurFilterIfNeeded(color);
- applyAlphaBlurIfNeeded(color);
- applyContentTextureIfNeeded(color);
+ applyBlurFilterIfNeeded(color, texCoord);
+ applyAlphaBlurIfNeeded(color, texCoord);
+ applyContentTextureIfNeeded(color, texCoord);
gl_FragColor = color;
}
);