Browse Source

tweaks to approximate spheres rendering

Alexander Rose 1 year ago
parent
commit
dccc06d497
2 changed files with 9 additions and 3 deletions
  1. 1 1
      src/mol-gl/shader/spheres.frag.ts
  2. 8 2
      src/mol-gl/shader/spheres.vert.ts

+ 1 - 1
src/mol-gl/shader/spheres.frag.ts

@@ -96,7 +96,7 @@ void main(void){
         modelPos = vPoint;
         fragmentDepth = gl_FragCoord.z;
         #ifndef dIgnoreLight
-            pointDir.z += length(pointDir) - vRadius;
+            pointDir.z -= cos(length(pointDir) / vRadius);
             cameraNormal = -normalize(pointDir / vRadius);
         #endif
         interior = false;

+ 8 - 2
src/mol-gl/shader/spheres.vert.ts

@@ -86,8 +86,14 @@ void main(void){
     vec4 position4 = vec4(aPosition, 1.0);
     vec4 mvPosition = uModelView * aTransform * position4;
 
-    gl_Position = uProjection * vec4(mvPosition.xyz, 1.0);
-    quadraticProjection(size, aPosition);
+    #ifdef dApproximate
+        vec4 mvCorner = vec4(mvPosition.xyz, 1.0);
+        mvCorner.xy += aMapping * vRadius;
+        gl_Position = uProjection * mvCorner;
+    #else
+        gl_Position = uProjection * vec4(mvPosition.xyz, 1.0);
+        quadraticProjection(vRadius, aPosition);
+    #endif
 
     vRadiusSq = vRadius * vRadius;
     vec4 vPoint4 = uInvProjection * gl_Position;