Forráskód Böngészése

fix xrayShader & ignoreLight not working together

Alexander Rose 3 éve
szülő
commit
6fa50eb8d5

+ 2 - 0
CHANGELOG.md

@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
 
 ## [Unreleased]
 
+- Fix xrayShader & ignoreLight not working at the same time
+
 ## [v3.0.2] - 2022-01-30
 
 - Fix color smoothing of elongated structures (by fixing ``Sphere.expand`` for spheres with highly directional extrema)

+ 50 - 46
src/mol-gl/shader/chunks/apply-light-color.glsl.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  *
@@ -8,61 +8,65 @@
  */
 
 export const apply_light_color = `
-#ifdef bumpEnabled
-    if (uBumpFrequency > 0.0 && uBumpAmplitude > 0.0) {
-        vec3 bumpNormal = perturbNormal(-vViewPosition, normal, fbm(vModelPosition * uBumpFrequency), (uBumpAmplitude * bumpiness) / uBumpFrequency);
-        #ifdef enabledFragDepth
-            if (!isNaN(bumpNormal.x) && !isNaN(bumpNormal.y) && !isNaN(bumpNormal.z)) {
+#ifdef dIgnoreLight
+    gl_FragColor = material;
+#else
+    #ifdef bumpEnabled
+        if (uBumpFrequency > 0.0 && uBumpAmplitude > 0.0) {
+            vec3 bumpNormal = perturbNormal(-vViewPosition, normal, fbm(vModelPosition * uBumpFrequency), (uBumpAmplitude * bumpiness) / uBumpFrequency);
+            #ifdef enabledFragDepth
+                if (!isNaN(bumpNormal.x) && !isNaN(bumpNormal.y) && !isNaN(bumpNormal.z)) {
+                    normal = bumpNormal;
+                }
+            #else
                 normal = bumpNormal;
-            }
-        #else
-            normal = bumpNormal;
-        #endif
-    }
-#endif
+            #endif
+        }
+    #endif
 
-vec4 color = material;
+    vec4 color = material;
 
-ReflectedLight reflectedLight = ReflectedLight(vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
+    ReflectedLight reflectedLight = ReflectedLight(vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
 
-PhysicalMaterial physicalMaterial;
-physicalMaterial.diffuseColor = color.rgb * (1.0 - metalness);
-#ifdef enabledFragDepth
-    physicalMaterial.roughness = min(max(roughness, 0.0525), 1.0);
-#else
-    vec3 dxy = max(abs(dFdx(normal)), abs(dFdy(normal)));
-    float geometryRoughness = max(max(dxy.x, dxy.y), dxy.z);
-    physicalMaterial.roughness = min(max(roughness, 0.0525) + geometryRoughness, 1.0);
-#endif
-physicalMaterial.specularColor = mix(vec3(0.04), color.rgb, metalness);
-physicalMaterial.specularF90 = 1.0;
+    PhysicalMaterial physicalMaterial;
+    physicalMaterial.diffuseColor = color.rgb * (1.0 - metalness);
+    #ifdef enabledFragDepth
+        physicalMaterial.roughness = min(max(roughness, 0.0525), 1.0);
+    #else
+        vec3 dxy = max(abs(dFdx(normal)), abs(dFdy(normal)));
+        float geometryRoughness = max(max(dxy.x, dxy.y), dxy.z);
+        physicalMaterial.roughness = min(max(roughness, 0.0525) + geometryRoughness, 1.0);
+    #endif
+    physicalMaterial.specularColor = mix(vec3(0.04), color.rgb, metalness);
+    physicalMaterial.specularF90 = 1.0;
 
-GeometricContext geometry;
-geometry.position = -vViewPosition;
-geometry.normal = normal;
-geometry.viewDir = normalize(vViewPosition);
+    GeometricContext geometry;
+    geometry.position = -vViewPosition;
+    geometry.normal = normal;
+    geometry.viewDir = normalize(vViewPosition);
 
-IncidentLight directLight;
-#pragma unroll_loop_start
-for (int i = 0; i < dLightCount; ++i) {
-    directLight.direction = uLightDirection[i];
-    directLight.color = uLightColor[i] * PI; // * PI for punctual light
-    RE_Direct_Physical(directLight, geometry, physicalMaterial, reflectedLight);
-}
-#pragma unroll_loop_end
+    IncidentLight directLight;
+    #pragma unroll_loop_start
+    for (int i = 0; i < dLightCount; ++i) {
+        directLight.direction = uLightDirection[i];
+        directLight.color = uLightColor[i] * PI; // * PI for punctual light
+        RE_Direct_Physical(directLight, geometry, physicalMaterial, reflectedLight);
+    }
+    #pragma unroll_loop_end
 
-vec3 irradiance = uAmbientColor * PI; // * PI for punctual light
-RE_IndirectDiffuse_Physical(irradiance, geometry, physicalMaterial, reflectedLight);
+    vec3 irradiance = uAmbientColor * PI; // * PI for punctual light
+    RE_IndirectDiffuse_Physical(irradiance, geometry, physicalMaterial, reflectedLight);
 
-// indirect specular only metals
-vec3 radiance = uAmbientColor * metalness;
-vec3 iblIrradiance = uAmbientColor * metalness;
-vec3 clearcoatRadiance = vec3(0.0);
-RE_IndirectSpecular_Physical(radiance, iblIrradiance, clearcoatRadiance, geometry, physicalMaterial, reflectedLight);
+    // indirect specular only metals
+    vec3 radiance = uAmbientColor * metalness;
+    vec3 iblIrradiance = uAmbientColor * metalness;
+    vec3 clearcoatRadiance = vec3(0.0);
+    RE_IndirectSpecular_Physical(radiance, iblIrradiance, clearcoatRadiance, geometry, physicalMaterial, reflectedLight);
 
-vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular;
+    vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular;
 
-gl_FragColor = vec4(outgoingLight, color.a);
+    gl_FragColor = vec4(outgoingLight, color.a);
+#endif
 
 #ifdef dXrayShaded
     gl_FragColor.a *= 1.0 - pow(abs(dot(normal, vec3(0.0, 0.0, 1.0))), uXrayEdgeFalloff);

+ 4 - 8
src/mol-gl/shader/cylinders.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -127,13 +127,9 @@ void main() {
     #elif defined(dRenderVariant_marking)
         gl_FragColor = material;
     #elif defined(dRenderVariant_color)
-        #ifdef dIgnoreLight
-            gl_FragColor = material;
-        #else
-            mat3 normalMatrix = transpose3(inverse3(mat3(uView)));
-            vec3 normal = normalize(normalMatrix * -normalize(intersection.yzw));
-            #include apply_light_color
-        #endif
+        mat3 normalMatrix = transpose3(inverse3(mat3(uView)));
+        vec3 normal = normalize(normalMatrix * -normalize(intersection.yzw));
+        #include apply_light_color
 
         #include apply_interior_color
         #include apply_marker_color

+ 15 - 21
src/mol-gl/shader/direct-volume.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author Michael Krone <michael.krone@uni-tuebingen.de>
@@ -166,9 +166,7 @@ vec3 v3m4(vec3 p, mat4 m) {
 float preFogAlphaBlended = 0.0;
 
 vec4 raymarch(vec3 startLoc, vec3 step, vec3 rayDir) {
-    #if !defined(dIgnoreLight)
-        mat3 normalMatrix = transpose3(inverse3(mat3(uModelView * vTransform)));
-    #endif
+    mat3 normalMatrix = transpose3(inverse3(mat3(uModelView * vTransform)));
     mat4 cartnToUnit = uCartnToUnit * inverse4(vTransform);
     #if defined(dClipVariant_pixel) && dClipObjectCount != 0
         mat4 modelTransform = uModel * vTransform * uTransform;
@@ -296,24 +294,20 @@ vec4 raymarch(vec3 startLoc, vec3 step, vec3 rayDir) {
             material.rgb = mix(material.rgb, overpaint.rgb, overpaint.a);
         #endif
 
-        #ifdef dIgnoreLight
+        if (material.a >= 0.01) {
+            #ifdef dPackedGroup
+                // compute gradient by central differences
+                gradient.x = textureVal(unitPos - dx).a - textureVal(unitPos + dx).a;
+                gradient.y = textureVal(unitPos - dy).a - textureVal(unitPos + dy).a;
+                gradient.z = textureVal(unitPos - dz).a - textureVal(unitPos + dz).a;
+            #else
+                gradient = cell.xyz * 2.0 - 1.0;
+            #endif
+            vec3 normal = -normalize(normalMatrix * normalize(gradient));
+            #include apply_light_color
+        } else {
             gl_FragColor.rgb = material.rgb;
-        #else
-            if (material.a >= 0.01) {
-                #ifdef dPackedGroup
-                    // compute gradient by central differences
-                    gradient.x = textureVal(unitPos - dx).a - textureVal(unitPos + dx).a;
-                    gradient.y = textureVal(unitPos - dy).a - textureVal(unitPos + dy).a;
-                    gradient.z = textureVal(unitPos - dz).a - textureVal(unitPos + dz).a;
-                #else
-                    gradient = cell.xyz * 2.0 - 1.0;
-                #endif
-                vec3 normal = -normalize(normalMatrix * normalize(gradient));
-                #include apply_light_color
-            } else {
-                gl_FragColor.rgb = material.rgb;
-            }
-        #endif
+        }
 
         gl_FragColor.a = material.a * uAlpha * uTransferScale;
 

+ 6 - 10
src/mol-gl/shader/mesh.frag.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -43,17 +43,13 @@ void main() {
     #elif defined(dRenderVariant_marking)
         gl_FragColor = material;
     #elif defined(dRenderVariant_color)
-        #ifdef dIgnoreLight
-            gl_FragColor = material;
+        #if defined(dFlatShaded)
+            vec3 normal = -faceNormal;
         #else
-            #if defined(dFlatShaded)
-                vec3 normal = -faceNormal;
-            #else
-                vec3 normal = -normalize(vNormal);
-                if (uDoubleSided) normal *= float(frontFacing) * 2.0 - 1.0;
-            #endif
-            #include apply_light_color
+            vec3 normal = -normalize(vNormal);
+            if (uDoubleSided) normal *= float(frontFacing) * 2.0 - 1.0;
         #endif
+        #include apply_light_color
 
         #include apply_interior_color
         #include apply_marker_color

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -92,12 +92,8 @@ void main(void){
     #elif defined(dRenderVariant_marking)
         gl_FragColor = material;
     #elif defined(dRenderVariant_color)
-        #ifdef dIgnoreLight
-            gl_FragColor = material;
-        #else
-            vec3 normal = -cameraNormal;
-            #include apply_light_color
-        #endif
+        vec3 normal = -cameraNormal;
+        #include apply_light_color
 
         #include apply_interior_color
         #include apply_marker_color