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

wip, compute shader tweaks

parent d4d92199
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ function getHistopyramidReductionRenderable(ctx: WebGLContext, initialTexture: T ...@@ -40,7 +40,7 @@ function getHistopyramidReductionRenderable(ctx: WebGLContext, initialTexture: T
} }
/** name for shared framebuffer used for histogram-pyramid operations */ /** name for shared framebuffer used for histogram-pyramid operations */
const FramebufferName = 'histogram-pyramid' const FramebufferName = 'histogram-pyramid-reduction'
function setRenderingDefaults(gl: GLRenderingContext) { function setRenderingDefaults(gl: GLRenderingContext) {
gl.disable(gl.CULL_FACE) gl.disable(gl.CULL_FACE)
...@@ -66,7 +66,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture) ...@@ -66,7 +66,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture)
// This part set the levels // This part set the levels
const levels = Math.ceil(Math.log(inputTextureMaxDim) / Math.log(2)) const levels = Math.ceil(Math.log(inputTextureMaxDim) / Math.log(2))
console.log('levels', levels) // console.log('levels', levels)
const initialTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest') const initialTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest')
initialTexture.load({ array: new Float32Array(4), width: 1, height: 1 }) initialTexture.load({ array: new Float32Array(4), width: 1, height: 1 })
...@@ -101,7 +101,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture) ...@@ -101,7 +101,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture)
levelTextures[currLevel].attachFramebuffer(framebuffer, 0) levelTextures[currLevel].attachFramebuffer(framebuffer, 0)
const size = Math.pow(2, currLevel) const size = Math.pow(2, currLevel)
console.log('size', size, 'draw-level', currLevel, 'read-level', levels - i) // console.log('size', size, 'draw-level', currLevel, 'read-level', levels - i)
gl.clear(gl.COLOR_BUFFER_BIT) gl.clear(gl.COLOR_BUFFER_BIT)
ValueCell.update(renderable.values.uSize, Math.pow(2, i + 1) / initialTextureMaxDim) ValueCell.update(renderable.values.uSize, Math.pow(2, i + 1) / initialTextureMaxDim)
...@@ -140,7 +140,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture) ...@@ -140,7 +140,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture)
const finalCount = getHistopyramidSum(ctx, levelTextures[0]) const finalCount = getHistopyramidSum(ctx, levelTextures[0])
const height = Math.ceil(finalCount / Math.pow(2, levels)) const height = Math.ceil(finalCount / Math.pow(2, levels))
console.log('height', height, 'finalCount', finalCount) // console.log('height', height, 'finalCount', finalCount)
// //
......
...@@ -12,7 +12,7 @@ import { Texture, createTexture } from 'mol-gl/webgl/texture'; ...@@ -12,7 +12,7 @@ import { Texture, createTexture } from 'mol-gl/webgl/texture';
import { ShaderCode } from 'mol-gl/shader-code'; import { ShaderCode } from 'mol-gl/shader-code';
import { ValueCell } from 'mol-util'; import { ValueCell } from 'mol-util';
import { decodeFloatRGB } from 'mol-util/float-packing'; import { decodeFloatRGB } from 'mol-util/float-packing';
import { readTexture, QuadSchema, QuadValues } from '../util'; import { QuadSchema, QuadValues } from '../util';
const HistopyramidSumSchema = { const HistopyramidSumSchema = {
...QuadSchema, ...QuadSchema,
...@@ -36,25 +36,29 @@ function getHistopyramidSumRenderable(ctx: WebGLContext, texture: Texture) { ...@@ -36,25 +36,29 @@ function getHistopyramidSumRenderable(ctx: WebGLContext, texture: Texture) {
} }
/** name for shared framebuffer used for histogram-pyramid operations */ /** name for shared framebuffer used for histogram-pyramid operations */
const FramebufferName = 'histogram-pyramid' const FramebufferName = 'histogram-pyramid-sum'
const sumArray = new Uint8Array(4)
export function getHistopyramidSum(ctx: WebGLContext, pyramidTopTexture: Texture) { export function getHistopyramidSum(ctx: WebGLContext, pyramidTopTexture: Texture) {
const { gl, framebufferCache } = ctx const { gl, framebufferCache } = ctx
const framebuffer = framebufferCache.get(FramebufferName).value const framebuffer = framebufferCache.get(FramebufferName).value
framebuffer.bind()
gl.viewport(0, 0, 1, 1)
const encodeFloatRenderable = getHistopyramidSumRenderable(ctx, pyramidTopTexture) const renderable = getHistopyramidSumRenderable(ctx, pyramidTopTexture)
encodeFloatRenderable.update() renderable.update()
encodeFloatRenderable.use() renderable.use()
// TODO cache globally for reuse // TODO cache globally for reuse
const encodedFloatTexture = createTexture(ctx, 'image-uint8', 'rgba', 'ubyte', 'nearest') const sumTexture = createTexture(ctx, 'image-uint8', 'rgba', 'ubyte', 'nearest')
encodedFloatTexture.define(1, 1) sumTexture.define(1, 1)
encodedFloatTexture.attachFramebuffer(framebuffer, 0) sumTexture.attachFramebuffer(framebuffer, 0)
gl.viewport(0, 0, 1, 1) renderable.render()
encodeFloatRenderable.render() ctx.readPixels(0, 0, 1, 1, sumArray)
ctx.unbindFramebuffer()
const sumImage = readTexture(ctx, encodedFloatTexture) return decodeFloatRGB(sumArray[0], sumArray[1], sumArray[2])
return decodeFloatRGB(sumImage.array[0], sumImage.array[1], sumImage.array[2])
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ import { QuadSchema, QuadValues } from '../util'; ...@@ -17,7 +17,7 @@ import { QuadSchema, QuadValues } from '../util';
import { getTriCount } from './tables'; import { getTriCount } from './tables';
/** name for shared framebuffer used for gpu marching cubes operations */ /** name for shared framebuffer used for gpu marching cubes operations */
const FramebufferName = 'marching-cubes' const FramebufferName = 'marching-cubes-active-voxels'
const ActiveVoxelsSchema = { const ActiveVoxelsSchema = {
...QuadSchema, ...QuadSchema,
......
...@@ -18,7 +18,7 @@ import { HistogramPyramid } from '../histogram-pyramid/reduction'; ...@@ -18,7 +18,7 @@ import { HistogramPyramid } from '../histogram-pyramid/reduction';
import { getTriIndices } from './tables'; import { getTriIndices } from './tables';
/** name for shared framebuffer used for gpu marching cubes operations */ /** name for shared framebuffer used for gpu marching cubes operations */
const FramebufferName = 'marching-cubes' const FramebufferName = 'marching-cubes-isosurface'
const IsosurfaceSchema = { const IsosurfaceSchema = {
...QuadSchema, ...QuadSchema,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment