From 34c82b110ef2b762d02c1515f0b20459d3642044 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Fri, 5 Apr 2019 14:31:17 -0700 Subject: [PATCH] fixed gpu gaussian density grid shift --- src/mol-gl/compute/histogram-pyramid/reduction.ts | 3 ++- src/mol-math/geometry/gaussian-density/gpu.ts | 15 +++++++++------ src/tests/browser/marching-cubes.ts | 13 +++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/mol-gl/compute/histogram-pyramid/reduction.ts b/src/mol-gl/compute/histogram-pyramid/reduction.ts index de0568f38..7e00a876a 100644 --- a/src/mol-gl/compute/histogram-pyramid/reduction.ts +++ b/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) // diff --git a/src/mol-math/geometry/gaussian-density/gpu.ts b/src/mol-math/geometry/gaussian-density/gpu.ts index 5087730d8..2a1f76db3 100644 --- a/src/mol-math/geometry/gaussian-density/gpu.ts +++ b/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 } diff --git a/src/tests/browser/marching-cubes.ts b/src/tests/browser/marching-cubes.ts index a95b54dd5..3f3a187d5 100644 --- a/src/tests/browser/marching-cubes.ts +++ b/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() -- GitLab