diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2019-05-03 12:23:55 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2019-05-03 12:38:57 +0000 |
commit | d2fcbf12bbec125a49b276d0f9be8ce24abf2525 (patch) | |
tree | 77524e818834e2d015cf2f6b71825aa30adf242c | |
parent | 6945d224433d731aaff1f83bf4d05ba812c8c36c (diff) |
Fix projection of distance field text and shader compliance
We were ignoring the projection matrix when calculating the
alpha range of the distance field algorithm. In Qt Quick this
is not necessary since there is no depth in the scene, but
in 3D of course it became very obvious as the text moved
closer to the camera.
Note that there is still an issue visible when combining a
scaling model matrix with proximity to the camera, but since
this is a clear improvement, I commit it by itself and defer
the other problem to a follow-up patch.
Second note: This also fixes a bug where the texture width and
height was not cast to float, which is not according to spec and
will break on some drivers.
Task-number: QT3DS-3343
Change-Id: Iddf00614c307ffc73119ecb37a4dfbb52dad78b1
Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
4 files changed, 6 insertions, 10 deletions
diff --git a/src/runtime/shaders/distancefieldtext.vert b/src/runtime/shaders/distancefieldtext.vert index 7a111bc..fa96ff7 100644 --- a/src/runtime/shaders/distancefieldtext.vert +++ b/src/runtime/shaders/distancefieldtext.vert @@ -1,5 +1,4 @@ uniform highp mat4 mvp; -uniform highp mat4 modelView; uniform highp float fontScale; uniform int textureWidth; uniform int textureHeight; @@ -57,7 +56,7 @@ highp float determinant(highp mat4 m) void main() { - highp float scale = fontScale * sqrt(abs(determinant(modelView))); + highp float scale = fontScale * sqrt(abs(determinant(mvp))); alphas = alphaRange(scale); sampleCoord = tCoord * vec2(1.0 / float(textureWidth), 1.0 / float(textureHeight)); gl_Position = mvp * vCoord; diff --git a/src/runtime/shaders/distancefieldtext_core.vert b/src/runtime/shaders/distancefieldtext_core.vert index b31f350..a64062c 100644 --- a/src/runtime/shaders/distancefieldtext_core.vert +++ b/src/runtime/shaders/distancefieldtext_core.vert @@ -8,7 +8,6 @@ out vec2 sampleCoord; out vec2 alphas; uniform mat4 mvp; -uniform mat4 modelView; uniform int textureWidth; uniform int textureHeight; uniform float fontScale; @@ -38,8 +37,8 @@ vec2 alphaRange(float scale) void main() { - float scale = fontScale * sqrt(abs(determinant(modelView))); + float scale = fontScale * sqrt(abs(determinant(mvp))); alphas = alphaRange(scale); - sampleCoord = tCoord * vec2(1.0 / textureWidth, 1.0 / textureHeight); + sampleCoord = tCoord * vec2(1.0 / float(textureWidth), 1.0 / float(textureHeight)); gl_Position = mvp * vCoord; } diff --git a/src/runtime/shaders/distancefieldtext_dropshadow.vert b/src/runtime/shaders/distancefieldtext_dropshadow.vert index 65e8e00..e44e880 100644 --- a/src/runtime/shaders/distancefieldtext_dropshadow.vert +++ b/src/runtime/shaders/distancefieldtext_dropshadow.vert @@ -1,5 +1,4 @@ uniform highp mat4 mvp; -uniform highp mat4 modelView; uniform highp float fontScale; uniform int textureWidth; uniform int textureHeight; @@ -61,7 +60,7 @@ highp float determinant(highp mat4 m) void main() { - highp float scale = fontScale * sqrt(abs(determinant(modelView))); + highp float scale = fontScale * sqrt(abs(determinant(mvp))); alphas = alphaRange(scale); highp vec2 textureSizeMultiplier = vec2(1.0 / highp float(textureWidth), 1.0 / float(textureHeight)); diff --git a/src/runtime/shaders/distancefieldtext_dropshadow_core.vert b/src/runtime/shaders/distancefieldtext_dropshadow_core.vert index 727dac5..f01e01b 100644 --- a/src/runtime/shaders/distancefieldtext_dropshadow_core.vert +++ b/src/runtime/shaders/distancefieldtext_dropshadow_core.vert @@ -11,7 +11,6 @@ out vec2 alphas; out vec4 normalizedTextureBounds; uniform mat4 mvp; -uniform mat4 modelView; uniform int textureWidth; uniform int textureHeight; uniform float fontScale; @@ -42,10 +41,10 @@ vec2 alphaRange(float scale) void main() { - float scale = fontScale * sqrt(abs(determinant(modelView))); + float scale = fontScale * sqrt(abs(determinant(mvp))); alphas = alphaRange(scale); - vec2 textureSizeMultiplier = vec2(1.0 / textureWidth, 1.0 / textureHeight); + vec2 textureSizeMultiplier = vec2(1.0 / float(textureWidth), 1.0 / float(textureHeight)); sampleCoord = tCoord * textureSizeMultiplier; shadowSampleCoord = (tCoord - shadowOffset) * textureSizeMultiplier; |