فهرست منبع

move cylinder color mixing to vertex shader

Alexander Rose 1 سال پیش
والد
کامیت
da034d9502

+ 16 - 7
src/mol-gl/shader/chunks/assign-color-varying.glsl.ts

@@ -5,20 +5,29 @@ export const assign_color_varying = `
     #elif defined(dColorType_instance)
         vColor.rgb = readFromTexture(tColor, aInstance, uColorTexDim).rgb;
     #elif defined(dColorType_group)
-        #if defined(dDualColor)       
-            vColor.rgb = readFromTexture(tColor, group * 2.0, uColorTexDim).rgb;
-            vColor2.rgb = readFromTexture(tColor, group * 2.0 + 1.0, uColorTexDim).rgb;
+        #if defined(dDualColor)
+            vec4 color2;
+            if (aColorMode == 2.0) {
+                vColor.rgb = readFromTexture(tColor, group, uColorTexDim).rgb;
+            } else {
+                vColor.rgb = readFromTexture(tColor, group * 2.0, uColorTexDim).rgb;
+                color2.rgb = readFromTexture(tColor, group * 2.0 + 1.0, uColorTexDim).rgb;
+            }
         #else
             vColor.rgb = readFromTexture(tColor, group, uColorTexDim).rgb;
         #endif
     #elif defined(dColorType_groupInstance)
-        #if defined(dDualColor)       
-            vColor.rgb = readFromTexture(tColor, (aInstance * float(uGroupCount) + group) * 2.0, uColorTexDim).rgb;
-            vColor2.rgb = readFromTexture(tColor, (aInstance * float(uGroupCount) + group) * 2.0 + 1.0, uColorTexDim).rgb;
+        #if defined(dDualColor)
+            vec4 color2;
+            if (aColorMode == 2.0) {
+                vColor.rgb = readFromTexture(tColor, aInstance * float(uGroupCount) + group, uColorTexDim).rgb;
+            } else {
+                vColor.rgb = readFromTexture(tColor, (aInstance * float(uGroupCount) + group) * 2.0, uColorTexDim).rgb;
+                color2.rgb = readFromTexture(tColor, (aInstance * float(uGroupCount) + group) * 2.0 + 1.0, uColorTexDim).rgb;
+            }
         #else
             vColor.rgb = readFromTexture(tColor, aInstance * float(uGroupCount) + group, uColorTexDim).rgb;
         #endif
-        
     #elif defined(dColorType_vertex)
         vColor.rgb = readFromTexture(tColor, VertexID, uColorTexDim).rgb;
     #elif defined(dColorType_vertexInstance)

+ 0 - 11
src/mol-gl/shader/chunks/assign-material-color.glsl.ts

@@ -13,17 +13,6 @@ export const assign_material_color = `
         vec4 material = vec4(uColor, uAlpha);
     #elif defined(dColorType_varying)
         vec4 material = vec4(vColor.rgb, uAlpha);
-        #if defined(dDualColor)
-            //interpolate
-            if (vColorMode >= 0.0 && vColorMode <= 1.0){
-                material = vec4(mix(vColor.rgb, vColor2.rgb, vColorMode).rgb, uAlpha);
-            } else if (vColorMode > 2.9 && vColorMode < 3.1) {
-                vec3 b = vEnd - vStart;
-                vec3 a = vModelPosition - vStart;
-                vec3 projection = dot(a,b) / dot(b,b) * b;
-                material = vec4(mix(vColor.rgb, vColor2.rgb, dot(projection,projection) / dot(b,b) / 2.0).rgb, uAlpha);
-            }
-        #endif
     #endif
 
     // mix material with overpaint

+ 0 - 3
src/mol-gl/shader/chunks/color-frag-params.glsl.ts

@@ -12,9 +12,6 @@ uniform float uBumpiness;
         uniform vec3 uColor;
     #elif defined(dColorType_varying)
         varying vec4 vColor;
-        #ifdef dDualColor
-          varying vec4 vColor2;
-        #endif
     #endif
 
     #ifdef dUsePalette

+ 0 - 3
src/mol-gl/shader/chunks/color-vert-params.glsl.ts

@@ -11,9 +11,6 @@ uniform float uBumpiness;
         attribute vec3 aColor;
     #elif defined(dColorType_texture)
         varying vec4 vColor;
-        #ifdef dDualColor
-          varying vec4 vColor2;
-        #endif
         uniform vec2 uColorTexDim;
         uniform sampler2D tColor;
     #elif defined(dColorType_grid)

+ 0 - 1
src/mol-gl/shader/cylinders.frag.ts

@@ -17,7 +17,6 @@ varying vec3 vStart;
 varying vec3 vEnd;
 varying float vSize;
 varying float vCap;
-varying float vColorMode;
 
 uniform vec3 uCameraDir;
 uniform vec3 uCameraPosition;

+ 15 - 3
src/mol-gl/shader/cylinders.vert.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2020-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2020-2024 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -33,7 +33,6 @@ varying vec3 vStart;
 varying vec3 vEnd;
 varying float vSize;
 varying float vCap;
-varying float vColorMode;
 
 uniform float uIsOrtho;
 uniform vec3 uCameraDir;
@@ -52,14 +51,15 @@ void main() {
     vEnd = (modelTransform * vec4(aEnd, 1.0)).xyz;
     vSize = size * aScale;
     vCap = aCap;
-    vColorMode = aColorMode;
 
     vModelPosition = (vStart + vEnd) * 0.5;
     vec3 camDir = -mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho);
     vec3 dir = vEnd - vStart;
+    float f = aMapping.x > 0.0 ? 1.0 : 0.0;
     // ensure cylinder 'dir' is pointing towards the camera
     if(dot(camDir, dir) < 0.0) {
         dir = -dir;
+        f = 1.0 - f;
     }
 
     vec3 left = cross(camDir, dir);
@@ -79,6 +79,18 @@ void main() {
         gl_Position.z = (uProjection * mvPosition).z;
     }
 
+    #if defined(dDualColor) && defined(dRenderVariant_color) && (defined(dColorType_group) || defined(dColorType_groupInstance))
+        // dual-color mixing
+        // - for aColorMode between 0 and 1 use aColorMode to interpolate
+        // - for aColorMode == 2 do nothing, i.e., use vColor
+        // - for aColorMode == 3 use position on cylinder axis to interpolate
+        if (aColorMode <= 1.0){
+            vColor.rgb = mix(vColor.rgb, color2.rgb, aColorMode);
+        } else if (aColorMode == 3.0) {
+            vColor.rgb = mix(vColor.rgb, color2.rgb, mix(-0.25, 1.25, f / 1.5));
+        }
+    #endif
+
     #include clip_instance
 }
 `;