Browse Source

fix text zOffset with orthographic projection

Alexander Rose 2 years ago
parent
commit
29693ebe8c
2 changed files with 9 additions and 9 deletions
  1. 2 0
      CHANGELOG.md
  2. 7 9
      src/mol-gl/shader/text.vert.ts

+ 2 - 0
CHANGELOG.md

@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
 
 ## [Unreleased]
 
+Fix wrong offset when rendering text with orthographic projection
+
 ## [v3.30.0] - 2023-01-29
 
 - Improve `Dnatco` extension

+ 7 - 9
src/mol-gl/shader/text.vert.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -29,7 +29,7 @@ uniform float uOffsetX;
 uniform float uOffsetY;
 uniform float uOffsetZ;
 
-// uniform bool ortho;
+uniform float uIsOrtho;
 uniform float uPixelRatio;
 uniform vec4 uViewport;
 
@@ -77,13 +77,11 @@ void main(void){
     mvCorner.x += offsetX;
     mvCorner.y += offsetY;
 
-    // TODO
-    // if(ortho){
-    //     mvCorner.xyz += normalize(-uCameraPosition) * offsetZ;
-    // } else {
-    //     mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ;
-    // }
-    mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ;
+    if (uIsOrtho == 1.0) {
+        mvCorner.z += offsetZ;
+    } else {
+        mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ;
+    }
 
     gl_Position = uProjection * mvCorner;