Browse Source

fixed gpu gaussian density grid shift

Alexander Rose 6 years ago
parent
commit
34c82b110e

+ 2 - 1
src/mol-gl/compute/histogram-pyramid/reduction.ts

@@ -80,6 +80,7 @@ export interface HistogramPyramid {
 export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture): HistogramPyramid {
     const { gl, framebufferCache } = ctx
 
+    // printTexture(ctx, inputTexture, 2)
     const inputTextureMaxDim = Math.max(inputTexture.width, inputTexture.height)
 
     // This part set the levels
@@ -139,7 +140,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture)
         offset += size;
     }
 
-    // printTexture(ctx, pyramidTexture, 3)
+    // printTexture(ctx, pyramidTexture, 2)
 
     //
 

+ 9 - 6
src/mol-math/geometry/gaussian-density/gpu.ts

@@ -8,7 +8,7 @@
 import { RuntimeContext } from 'mol-task'
 import { PositionData, DensityData, DensityTextureData } from '../common'
 import { Box3D } from '../../geometry'
-import { GaussianDensityGPUProps, getDelta } from '../gaussian-density'
+import { GaussianDensityGPUProps } from '../gaussian-density'
 import { OrderedSet } from 'mol-data/int'
 import { Vec3, Tensor, Mat4 } from '../../linear-algebra'
 import { ValueCell } from 'mol-util'
@@ -229,12 +229,15 @@ async function prepareGaussianDensityData(ctx: RuntimeContext, position: Positio
     }
 
     const pad = maxRadius * 2 + resolution
-    const expandedBox = Box3D.expand(Box3D.empty(), box, Vec3.create(pad, pad, pad));
-    const extent = Vec3.sub(Vec3.zero(), expandedBox.max, expandedBox.min)
+    const expandedBox = Box3D.expand(Box3D(), box, Vec3.create(pad, pad, pad));
+    const expandedDim = Box3D.size(Vec3(), expandedBox)
 
-    const delta = getDelta(expandedBox, resolution)
-    const dim = Vec3.zero()
-    Vec3.ceil(dim, Vec3.mul(dim, extent, delta))
+    const scaledBox = Box3D.scale(Box3D(), expandedBox, 1 / resolution)
+    const dim = Box3D.size(Vec3(), scaledBox)
+    Vec3.ceil(dim, dim)
+    const delta = Vec3.div(Vec3(), dim, expandedDim)
+
+    // console.log({ maxRadius, resolution, pad, box, expandedBox, delta })
     // console.log('grid dim gpu', dim)
 
     return { drawCount: n, positions, radii, groups, delta, expandedBox, dim }

+ 3 - 10
src/tests/browser/marching-cubes.ts

@@ -45,15 +45,8 @@ async function init() {
         z: [0, 2],
         indices: OrderedSet.ofSortedArray([0, 1]),
     }
-    const box = Box3D.create(Vec3.create(-1, -1, -1), Vec3.create(3, 3, 3))
-    // const position: PositionData = {
-    //     x: [0],
-    //     y: [0],
-    //     z: [0],
-    //     indices: OrderedSet.ofSortedArray([0]),
-    // }
-    // const box = Box3D.create(Vec3.create(-1, -1, -1), Vec3.create(1, 1, 1))
-    const radius = () => 1.4
+    const box = Box3D.create(Vec3.create(0, 0, 0), Vec3.create(2, 2, 2))
+    const radius = () => 1.8
     const props = {
         resolution: 0.1,
         radiusOffset: 0,
@@ -61,7 +54,7 @@ async function init() {
     }
     const isoValue = Math.exp(-props.smoothness)
 
-    if (true) {
+    if (false) {
         console.time('gpu gaussian2')
         const densityTextureData2 = await computeGaussianDensityTexture2d(position, box, radius, props, webgl).run()
         webgl.waitForGpuCommandsCompleteSync()