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