Browse Source

more normals tweaks

Alexander Rose 7 years ago
parent
commit
844c1f3daf

+ 1 - 1
src/apps/render-test/state.ts

@@ -161,7 +161,7 @@ export default class State {
         this.surfaceRepr = VolumeRepresentation(Surface)
         await Run(this.surfaceRepr.create(v.volume, {
             isoValue: VolumeIsoValue.relative(v.volume.dataStats, 3.0),
-            alpha: 0.3
+            alpha: 1.0
         }), log, 500)
         viewer.add(this.surfaceRepr)
 

+ 8 - 5
src/mol-geo/representation/volume/surface.ts

@@ -35,7 +35,10 @@ export function computeVolumeSurface(volume: VolumeData, isoValue: VolumeIsoValu
 
 export const DefaultSurfaceProps = {
     isoValue: VolumeIsoValue.relative({ min: 0, max: 0, mean: 0, sigma: 0 }, 0),
-    alpha: 0.5
+    alpha: 0.5,
+    flatShaded: true,
+    flipSided: true,
+    doubleSided: true
 }
 export type SurfaceProps = Partial<typeof DefaultSurfaceProps>
 
@@ -50,7 +53,7 @@ export default function Surface(): VolumeElementRepresentation<SurfaceProps> {
             return Task.create('Point.create', async ctx => {
                 renderObjects.length = 0 // clear
                 curProps = { ...DefaultSurfaceProps, ...props }
-                const { alpha } = curProps
+                const { alpha, flatShaded, flipSided, doubleSided } = curProps
 
                 const mesh = await ctx.runChild(computeVolumeSurface(volume, curProps.isoValue))
 
@@ -70,9 +73,9 @@ export default function Surface(): VolumeElementRepresentation<SurfaceProps> {
                     elementCount: mesh.triangleCount,
                     positionCount: mesh.vertexCount / 3,
 
-                    flatShaded: true,
-                    doubleSided: true,
-                    flipSided: true
+                    flatShaded,
+                    doubleSided,
+                    flipSided
                 })
                 renderObjects.push(surface)
             })

+ 3 - 0
src/mol-gl/shader/mesh.frag

@@ -49,6 +49,9 @@ void main() {
         vec3 fdx = dFdx(vViewPosition);
         vec3 fdy = dFdy(vViewPosition);
         vec3 N = normalize(cross(fdx, fdy));
+        #ifdef FLIP_SIDED
+            N = -N;
+        #endif
     #else
         vec3 N = -normalize(vNormal);
         #ifdef DOUBLE_SIDED