瀏覽代碼

add alphaThickness parameter for spheres

Alexander Rose 1 年之前
父節點
當前提交
310300bde8
共有 4 個文件被更改,包括 11 次插入1 次删除
  1. 1 0
      CHANGELOG.md
  2. 3 0
      src/mol-geo/geometry/spheres/spheres.ts
  3. 1 0
      src/mol-gl/renderable/spheres.ts
  4. 6 1
      src/mol-gl/shader/spheres.frag.ts

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ Note that since we don't clearly distinguish between a public and private interf
 - Add optional `file?: CifFile` to `MmcifFormat.data`
 - Add support for `WEBGL_clip_cull_distance`
 - Add `MultiSampleParams.reduceFlicker` (to be able to switch it off)
+- Add `alphaThickness` parameter to adjust alpha of spheres for radius
 
 ## [v3.39.0] - 2023-09-02
 

+ 3 - 0
src/mol-geo/geometry/spheres/spheres.ts

@@ -151,6 +151,7 @@ export namespace Spheres {
         transparentBackfaces: PD.Select('off', PD.arrayToOptions(['off', 'on', 'opaque']), BaseGeometry.ShadingCategory),
         solidInterior: PD.Boolean(true, BaseGeometry.ShadingCategory),
         approximate: PD.Boolean(false, { ...BaseGeometry.ShadingCategory, description: 'Faster rendering, but has artifacts.' }),
+        alphaThickness: PD.Numeric(0, { min: 0, max: 20, step: 1 }, { ...BaseGeometry.ShadingCategory, description: 'If not zero, adjusts alpha for radius.' }),
         bumpFrequency: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory),
         bumpAmplitude: PD.Numeric(1, { min: 0, max: 5, step: 0.1 }, BaseGeometry.ShadingCategory),
     };
@@ -236,6 +237,7 @@ export namespace Spheres {
             dTransparentBackfaces: ValueCell.create(props.transparentBackfaces),
             dSolidInterior: ValueCell.create(props.solidInterior),
             dApproximate: ValueCell.create(props.approximate),
+            uAlphaThickness: ValueCell.create(props.alphaThickness),
             uBumpFrequency: ValueCell.create(props.bumpFrequency),
             uBumpAmplitude: ValueCell.create(props.bumpAmplitude),
 
@@ -259,6 +261,7 @@ export namespace Spheres {
         ValueCell.updateIfChanged(values.dTransparentBackfaces, props.transparentBackfaces);
         ValueCell.updateIfChanged(values.dSolidInterior, props.solidInterior);
         ValueCell.updateIfChanged(values.dApproximate, props.approximate);
+        ValueCell.updateIfChanged(values.uAlphaThickness, props.alphaThickness);
         ValueCell.updateIfChanged(values.uBumpFrequency, props.bumpFrequency);
         ValueCell.updateIfChanged(values.uBumpAmplitude, props.bumpAmplitude);
     }

+ 1 - 0
src/mol-gl/renderable/spheres.ts

@@ -25,6 +25,7 @@ export const SpheresSchema = {
     dTransparentBackfaces: DefineSpec('string', ['off', 'on', 'opaque']),
     dSolidInterior: DefineSpec('boolean'),
     dApproximate: DefineSpec('boolean'),
+    uAlphaThickness: UniformSpec('f'),
     uBumpFrequency: UniformSpec('f', 'material'),
     uBumpAmplitude: UniformSpec('f', 'material'),
 

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

@@ -17,6 +17,7 @@ precision highp int;
 #include common_clip
 
 uniform mat4 uInvView;
+uniform float uAlphaThickness;
 
 varying float vRadius;
 varying vec3 vPoint;
@@ -91,7 +92,7 @@ void main(void){
         if (dot(pointDir, pointDir) > vRadius * vRadius) discard;
         vec3 vViewPosition = -vPointViewPosition;
         fragmentDepth = gl_FragCoord.z;
-        #ifndef dIgnoreLight
+        #if !defined(dIgnoreLight) || defined(dXrayShaded)
             pointDir.z -= cos(length(pointDir) / vRadius);
             cameraNormal = -normalize(pointDir / vRadius);
         #endif
@@ -132,6 +133,10 @@ void main(void){
         vec3 normal = -cameraNormal;
         #include apply_light_color
 
+        if (uRenderMask == MaskTransparent && uAlphaThickness > 0.0) {
+            gl_FragColor.a *= min(1.0, vRadius / uAlphaThickness);
+        }
+
         #include apply_interior_color
         #include apply_marker_color
         #include apply_fog