Browse Source

fix clipping of approximate spheres

Alexander Rose 1 year ago
parent
commit
f9265a7049
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/mol-gl/shader/spheres.frag.ts

+ 6 - 7
src/mol-gl/shader/spheres.frag.ts

@@ -83,8 +83,6 @@ bool SphereImpostor(out vec3 modelPos, out vec3 cameraPos, out vec3 cameraNormal
 }
 
 void main(void){
-    vec3 modelPos;
-    vec3 cameraPos;
     vec3 cameraNormal;
     float fragmentDepth;
     bool clipped = false;
@@ -92,8 +90,7 @@ void main(void){
     #ifdef dApproximate
         vec3 pointDir = -vPointViewPosition - vPoint;
         if (dot(pointDir, pointDir) > vRadius * vRadius) discard;
-        cameraPos = -vPointViewPosition;
-        modelPos = vPoint;
+        vec3 vViewPosition = -vPointViewPosition;
         fragmentDepth = gl_FragCoord.z;
         #ifndef dIgnoreLight
             pointDir.z -= cos(length(pointDir) / vRadius);
@@ -101,6 +98,8 @@ void main(void){
         #endif
         interior = false;
     #else
+        vec3 modelPos;
+        vec3 cameraPos;
         bool hit = SphereImpostor(modelPos, cameraPos, cameraNormal, interior, fragmentDepth);
         if (!hit) discard;
 
@@ -108,10 +107,10 @@ void main(void){
         if (fragmentDepth > 1.0) discard;
 
         gl_FragDepthEXT = fragmentDepth;
-    #endif
 
-    vec3 vViewPosition = cameraPos;
-    vec3 vModelPosition = modelPos;
+        vec3 vModelPosition = modelPos;
+        vec3 vViewPosition = cameraPos;
+    #endif
 
     #include clip_pixel
     #include assign_material_color