diff options
author | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2009-10-14 15:22:57 (GMT) |
---|---|---|
committer | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2009-10-14 15:42:52 (GMT) |
commit | 33d2bd641fd031d1a4e38198bf50538344a4ccdb (patch) | |
tree | 1ebdd7a17b849e901863b2adcad7c10657d62147 /src/opengl/util/ellipse_aa.glsl | |
parent | 111558d709d7d55318bdf3de99442f26e246fcdc (diff) | |
download | Qt-33d2bd641fd031d1a4e38198bf50538344a4ccdb.zip Qt-33d2bd641fd031d1a4e38198bf50538344a4ccdb.tar.gz Qt-33d2bd641fd031d1a4e38198bf50538344a4ccdb.tar.bz2 |
Cleaned up OpenGL1 paint engine GLSL code.
Fixed warnings about int->float and float->vecN conversions. Removed
unused shader files.
Reviewed-by: Trond
Diffstat (limited to 'src/opengl/util/ellipse_aa.glsl')
-rw-r--r-- | src/opengl/util/ellipse_aa.glsl | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/opengl/util/ellipse_aa.glsl b/src/opengl/util/ellipse_aa.glsl index f7a6454..257e3bb 100644 --- a/src/opengl/util/ellipse_aa.glsl +++ b/src/opengl/util/ellipse_aa.glsl @@ -1,6 +1,58 @@ -#include "ellipse_functions.glsl" +uniform vec3 inv_matrix_m0; +uniform vec3 inv_matrix_m1; +uniform vec3 inv_matrix_m2; + +uniform vec2 ellipse_offset; + +// ellipse equation + +// s^2/a^2 + t^2/b^2 = 1 +// +// implicit equation: +// g(s,t) = 1 - s^2/r_s^2 - t^2/r_t^2 + +// distance from ellipse: +// grad = [dg/dx dg/dy] +// d(s, t) ~= g(s, t) / |grad| + +// dg/dx = dg/ds * ds/dx + dg/dt * dt/dx +// dg/dy = dg/ds * ds/dy + dg/dt * dt/dy + +float ellipse_aa() +{ + mat3 mat; + + mat[0] = inv_matrix_m0; + mat[1] = inv_matrix_m1; + mat[2] = inv_matrix_m2; + + vec3 hcoords = mat * vec3(gl_FragCoord.xy + ellipse_offset, 1); + float inv_w = 1.0 / hcoords.z; + vec2 st = hcoords.xy * inv_w; + + vec4 xy = vec4(mat[0].xy, mat[1].xy); + vec2 h = vec2(mat[0].z, mat[1].z); + + vec4 dstdxy = (xy.xzyw - h.xyxy * st.xxyy) * inv_w; + + //dstdxy.x = (mat[0].x - mat[0].z * st.x) * inv_w; // ds/dx + //dstdxy.y = (mat[1].x - mat[1].z * st.x) * inv_w; // ds/dy + //dstdxy.z = (mat[0].y - mat[0].z * st.y) * inv_w; // dt/dx + //dstdxy.w = (mat[1].y - mat[1].z * st.y) * inv_w; // dt/dy + + vec2 inv_r = gl_TexCoord[0].xy; + vec2 n = st * inv_r; + float g = 1.0 - dot(n, n); + + vec2 dgdst = -2.0 * n * inv_r; + + vec2 grad = vec2(dot(dgdst, dstdxy.xz), + dot(dgdst, dstdxy.yw)); + + return smoothstep(-0.5, 0.5, g * inversesqrt(dot(grad, grad))); +} void main() { - gl_FragColor = ellipse_aa(); + gl_FragColor = ellipse_aa().xxxx; } |