Skip to content
Snippets Groups Projects
Commit 20ad92a5 authored by Alexander Rose's avatar Alexander Rose
Browse files

gaussian density tweaks

parent 0e617e8b
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ export interface ComputeRenderable<T extends RenderableValues> { ...@@ -61,7 +61,7 @@ export interface ComputeRenderable<T extends RenderableValues> {
readonly values: T readonly values: T
render: () => void render: () => void
getProgram: () => Program use: () => void
update: () => void update: () => void
dispose: () => void dispose: () => void
} }
...@@ -72,7 +72,7 @@ export function createComputeRenderable<T extends Values<RenderableSchema>>(rend ...@@ -72,7 +72,7 @@ export function createComputeRenderable<T extends Values<RenderableSchema>>(rend
values, values,
render: () => renderItem.render('draw'), render: () => renderItem.render('draw'),
getProgram: () => renderItem.getProgram('draw'), use: () => renderItem.getProgram('draw').use(),
update: () => renderItem.update(), update: () => renderItem.update(),
dispose: () => renderItem.destroy() dispose: () => renderItem.destroy()
} }
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Renderable, RenderableState, createRenderable } from '../renderable'
import { WebGLContext } from '../webgl/context';
import { createRenderItem } from '../webgl/render-item';
import { AttributeSpec, Values, UniformSpec, ValueSpec, DefineSpec, TextureSpec } from './schema';
import { GaussianDensityShaderCode } from '../shader-code';
export const GaussianDensitySchema = {
drawCount: ValueSpec('number'),
instanceCount: ValueSpec('number'),
aRadius: AttributeSpec('float32', 1, 0),
aPosition: AttributeSpec('float32', 3, 0),
aGroup: AttributeSpec('float32', 1, 0),
uCurrentSlice: UniformSpec('f'),
uCurrentX: UniformSpec('f'),
uCurrentY: UniformSpec('f'),
uBboxMin: UniformSpec('v3'),
uBboxMax: UniformSpec('v3'),
uBboxSize: UniformSpec('v3'),
uGridDim: UniformSpec('v3'),
uGridTexDim: UniformSpec('v3'),
uAlpha: UniformSpec('f'),
tMinDistanceTex: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
dGridTexType: DefineSpec('string', ['2d', '3d']),
dCalcType: DefineSpec('string', ['density', 'minDistance', 'groupId']),
}
export type GaussianDensitySchema = typeof GaussianDensitySchema
export type GaussianDensityValues = Values<GaussianDensitySchema>
export function GaussianDensityRenderable(ctx: WebGLContext, id: number, values: GaussianDensityValues, state: RenderableState): Renderable<GaussianDensityValues> {
const schema = { ...GaussianDensitySchema }
const shaderCode = GaussianDensityShaderCode
const renderItem = createRenderItem(ctx, 'points', shaderCode, schema, values, -1)
return createRenderable(renderItem, values, state);
}
\ No newline at end of file
/** /**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
...@@ -10,11 +10,15 @@ import { RuntimeContext, Task } from 'mol-task'; ...@@ -10,11 +10,15 @@ import { RuntimeContext, Task } from 'mol-task';
import { PositionData, DensityData } from './common'; import { PositionData, DensityData } from './common';
import { GaussianDensityCPU } from './gaussian-density/cpu'; import { GaussianDensityCPU } from './gaussian-density/cpu';
import { WebGLContext } from 'mol-gl/webgl/context'; import { WebGLContext } from 'mol-gl/webgl/context';
import { Texture } from 'mol-gl/webgl/texture';
// import { GaussianDensityGPU } from './gaussian-density/gpu'; // import { GaussianDensityGPU, GaussianDensityTexture } from './gaussian-density/gpu';
const GaussianDensityGPU = typeof document !== 'undefined' const GaussianDensityGPU = typeof document !== 'undefined'
? (require('./gaussian-density/gpu') as typeof import('./gaussian-density/gpu')).GaussianDensityGPU ? (require('./gaussian-density/gpu') as typeof import('./gaussian-density/gpu')).GaussianDensityGPU
: void 0; : void 0;
const GaussianDensityTexture = typeof document !== 'undefined'
? (require('./gaussian-density/gpu') as typeof import('./gaussian-density/gpu')).GaussianDensityTexture
: void 0;
export const DefaultGaussianDensityGPUProps = { export const DefaultGaussianDensityGPUProps = {
resolution: 1, resolution: 1,
...@@ -37,9 +41,9 @@ export function getDelta(box: Box3D, resolution: number) { ...@@ -37,9 +41,9 @@ export function getDelta(box: Box3D, resolution: number) {
return delta return delta
} }
export function computeGaussianDensity(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityProps) { export function computeGaussianDensity(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityProps, webgl?: WebGLContext) {
return Task.create('Gaussian Density', async ctx => { return Task.create('Gaussian Density', async ctx => {
return await GaussianDensity(ctx, position, box, radius, props) return await GaussianDensity(ctx, position, box, radius, props, webgl)
}); });
} }
...@@ -51,4 +55,11 @@ export async function GaussianDensity(ctx: RuntimeContext, position: PositionDat ...@@ -51,4 +55,11 @@ export async function GaussianDensity(ctx: RuntimeContext, position: PositionDat
} else { } else {
return await GaussianDensityCPU(ctx, position, box, radius, props) return await GaussianDensityCPU(ctx, position, box, radius, props)
} }
}
export function computeGaussianDensityTexture(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityGPUProps, webgl: WebGLContext, texture?: Texture) {
if (!GaussianDensityTexture) throw 'GPU computation not supported on this platform';
return Task.create('Gaussian Density', async ctx => {
return await GaussianDensityTexture(ctx, webgl, position, box, radius, props, texture);
});
} }
\ No newline at end of file
...@@ -277,7 +277,7 @@ function setupMinDistanceRendering(webgl: WebGLContext, renderable: ComputeRende ...@@ -277,7 +277,7 @@ function setupMinDistanceRendering(webgl: WebGLContext, renderable: ComputeRende
const { gl } = webgl const { gl } = webgl
ValueCell.update(renderable.values.dCalcType, 'minDistance') ValueCell.update(renderable.values.dCalcType, 'minDistance')
renderable.update() renderable.update()
renderable.getProgram().use() renderable.use()
gl.blendFunc(gl.ONE, gl.ONE) gl.blendFunc(gl.ONE, gl.ONE)
// the shader writes 1 - dist so we set blending to MAX // the shader writes 1 - dist so we set blending to MAX
gl.blendEquation(webgl.extensions.blendMinMax.MAX) gl.blendEquation(webgl.extensions.blendMinMax.MAX)
...@@ -287,7 +287,7 @@ function setupDensityRendering(webgl: WebGLContext, renderable: ComputeRenderabl ...@@ -287,7 +287,7 @@ function setupDensityRendering(webgl: WebGLContext, renderable: ComputeRenderabl
const { gl } = webgl const { gl } = webgl
ValueCell.update(renderable.values.dCalcType, 'density') ValueCell.update(renderable.values.dCalcType, 'density')
renderable.update() renderable.update()
renderable.getProgram().use() renderable.use()
gl.blendFunc(gl.ONE, gl.ONE) gl.blendFunc(gl.ONE, gl.ONE)
gl.blendEquation(gl.FUNC_ADD) gl.blendEquation(gl.FUNC_ADD)
} }
...@@ -296,7 +296,7 @@ function setupGroupIdRendering(webgl: WebGLContext, renderable: ComputeRenderabl ...@@ -296,7 +296,7 @@ function setupGroupIdRendering(webgl: WebGLContext, renderable: ComputeRenderabl
const { gl } = webgl const { gl } = webgl
ValueCell.update(renderable.values.dCalcType, 'groupId') ValueCell.update(renderable.values.dCalcType, 'groupId')
renderable.update() renderable.update()
renderable.getProgram().use() renderable.use()
// overwrite color, don't change alpha // overwrite color, don't change alpha
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ZERO, gl.ONE) gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ZERO, gl.ONE)
gl.blendEquation(gl.FUNC_ADD) gl.blendEquation(gl.FUNC_ADD)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment