Ver Fonte

clip object support for non mesh geometries

- spheres
- lines
- points
- text
Alexander Rose há 4 anos atrás
pai
commit
4d7a128528

+ 1 - 1
src/mol-gl/shader/chunks/assign-position.glsl.ts

@@ -7,7 +7,7 @@ mat4 modelView = uView * model;
     vec3 position = aPosition;
 #endif
 vec4 position4 = vec4(position, 1.0);
-vModelPosition = (model * position4).xyz;
+vModelPosition = (model * position4).xyz; // for clipping in frag shader
 vec4 mvPosition = modelView * position4;
 vViewPosition = mvPosition.xyz;
 gl_Position = uProjection * mvPosition;

+ 1 - 1
src/mol-gl/shader/chunks/clip-instance.glsl.ts

@@ -5,7 +5,7 @@ export default `
         flag = int(floor(vClipping * 255.0 + 0.5));
     #endif
 
-    vec4 mCenter = model * vec4(uInvariantBoundingSphere.xyz, 1.0);
+    vec4 mCenter = uModel * aTransform * vec4(uInvariantBoundingSphere.xyz, 1.0);
     if (clipTest(vec4(mCenter.xyz, uInvariantBoundingSphere.w), flag))
         // move out of [ -w, +w ] to 'discard' in vert shader
         gl_Position.z = 2.0 * gl_Position.w;

+ 4 - 3
src/mol-gl/shader/chunks/clip-pixel.glsl.ts

@@ -1,11 +1,12 @@
 export default `
 #if defined(dClipVariant_pixel) && dClipObjectCount != 0
-    int flag = 0;
     #if defined(dClipping)
-        flag = int(floor(vClipping * 255.0 + 0.5));
+        int clippingFlag = int(floor(vClipping * 255.0 + 0.5));
+    #else
+        int clippingFlag = 0;
     #endif
 
-    if (clipTest(vec4(vModelPosition, 0.0), flag))
+    if (clipTest(vec4(vModelPosition, 0.0), clippingFlag))
         discard;
 #endif
 `;

+ 3 - 1
src/mol-gl/shader/lines.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -11,8 +11,10 @@ precision highp int;
 #include common
 #include common_frag_params
 #include color_frag_params
+#include common_clip
 
 void main(){
+    #include clip_pixel
     #include assign_material_color
 
     #if defined(dRenderVariant_pick)

+ 9 - 3
src/mol-gl/shader/lines.vert.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  *
@@ -15,6 +15,7 @@ precision highp int;
 #include common_vert_params
 #include color_vert_params
 #include size_vert_params
+#include common_clip
 
 uniform float uPixelRatio;
 uniform float uViewportHeight;
@@ -42,6 +43,7 @@ void main(){
     #include assign_group
     #include assign_color_varying
     #include assign_marker_varying
+    #include assign_clipping_varying
     #include assign_size
 
     mat4 modelView = uView * uModel * aTransform;
@@ -51,10 +53,12 @@ void main(){
     vec4 end = modelView * vec4(aEnd, 1.0);
 
     // assign position
-    vec3 position = (aMapping.y < 0.5) ? aStart : aEnd;
-    vec4 mvPosition = modelView * vec4(position, 1.0);
+    vec4 position4 = vec4((aMapping.y < 0.5) ? aStart : aEnd, 1.0);
+    vec4 mvPosition = modelView * position4;
     vViewPosition = mvPosition.xyz;
 
+    vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader
+
     // special case for perspective projection, and segments that terminate either in, or behind, the camera plane
     // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
     // but we need to perform ndc-space calculations in the shader, so we must address this issue directly
@@ -114,5 +118,7 @@ void main(){
     offset *= clip.w;
     clip.xy += offset;
     gl_Position = clip;
+
+    #include clip_instance
 }
 `;

+ 3 - 1
src/mol-gl/shader/points.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -11,6 +11,7 @@ precision highp int;
 #include common
 #include common_frag_params
 #include color_frag_params
+#include common_clip
 
 #ifdef dPointFilledCircle
     uniform float uPointEdgeBleach;
@@ -20,6 +21,7 @@ const vec2 center = vec2(0.5);
 const float radius = 0.5;
 
 void main(){
+    #include clip_pixel
     #include assign_material_color
 
     #if defined(dRenderVariant_pick)

+ 5 - 1
src/mol-gl/shader/points.vert.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -13,6 +13,7 @@ precision highp int;
 #include common_vert_params
 #include color_vert_params
 #include size_vert_params
+#include common_clip
 
 uniform float uPixelRatio;
 uniform float uViewportHeight;
@@ -26,6 +27,7 @@ void main(){
     #include assign_group
     #include assign_color_varying
     #include assign_marker_varying
+    #include assign_clipping_varying
     #include assign_position
     #include assign_size
 
@@ -36,5 +38,7 @@ void main(){
     #endif
 
     gl_Position = uProjection * mvPosition;
+
+    #include clip_instance
 }
 `;

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -12,6 +12,7 @@ precision highp int;
 #include common_frag_params
 #include color_frag_params
 #include light_frag_params
+#include common_clip
 
 uniform mat4 uProjection;
 
@@ -73,6 +74,8 @@ bool Impostor(out vec3 cameraPos, out vec3 cameraNormal){
 }
 
 void main(void){
+    #include clip_pixel
+
     bool flag = Impostor(cameraPos, cameraNormal);
     #ifndef dDoubleSided
         if (interior)

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -13,6 +13,7 @@ precision highp int;
 #include common_vert_params
 #include color_vert_params
 #include size_vert_params
+#include common_clip
 
 uniform mat4 uModelView;
 uniform mat4 uInvProjection;
@@ -77,11 +78,13 @@ void main(void){
     #include assign_group
     #include assign_color_varying
     #include assign_marker_varying
+    #include assign_clipping_varying
     #include assign_size
 
     vRadius = size * matrixScale(uModelView);
 
-    vec4 mvPosition = uModelView * aTransform * vec4(aPosition, 1.0);
+    vec4 position4 = vec4(aPosition, 1.0);
+    vec4 mvPosition = uModelView * aTransform * position4;
     mvPosition.z -= vRadius; // avoid clipping, added again in fragment shader
 
     gl_Position = uProjection * vec4(mvPosition.xyz, 1.0);
@@ -91,5 +94,9 @@ void main(void){
     vec4 vPoint4 = uInvProjection * gl_Position;
     vPoint = vPoint4.xyz / vPoint4.w;
     vPointViewPosition = -mvPosition.xyz / mvPosition.w;
+
+    vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader
+
+    #include clip_instance
 }
 `;

+ 3 - 1
src/mol-gl/shader/text.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -11,6 +11,7 @@ precision highp int;
 #include common
 #include common_frag_params
 #include color_frag_params
+#include common_clip
 
 uniform sampler2D tFont;
 
@@ -29,6 +30,7 @@ void main2(){
 }
 
 void main(){
+    #include clip_pixel
     #include assign_material_color
 
     if (vTexCoord.x > 1.0) {

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -13,6 +13,7 @@ precision highp int;
 #include common_vert_params
 #include color_vert_params
 #include size_vert_params
+#include common_clip
 
 uniform mat4 uModelView;
 
@@ -40,6 +41,7 @@ void main(void){
     #include assign_group
     #include assign_color_varying
     #include assign_marker_varying
+    #include assign_clipping_varying
     #include assign_size
 
     vTexCoord = aTexCoord;
@@ -50,7 +52,10 @@ void main(void){
     float offsetY = uOffsetY * scale;
     float offsetZ = (uOffsetZ + aDepth * 0.95) * scale;
 
-    vec4 mvPosition = uModelView * aTransform * vec4(aPosition, 1.0);
+    vec4 position4 = vec4(aPosition, 1.0);
+    vec4 mvPosition = uModelView * aTransform * position4;
+
+    vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader
 
     // TODO
     // #ifdef FIXED_SIZE
@@ -83,5 +88,7 @@ void main(void){
     gl_Position = uProjection * mvCorner;
 
     vViewPosition = -mvCorner.xyz;
+
+    #include clip_instance
 }
 `;