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

wip, gl compute teaks

parent 2f220936
Branches
Tags
No related merge requests found
...@@ -85,7 +85,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture) ...@@ -85,7 +85,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))
const maxSize = Math.pow(2, levels) const maxSize = Math.pow(2, levels)
// console.log('levels', levels) // console.log('levels', levels, 'maxSize', maxSize)
const initialTexture = getLevelTexture(ctx, levels) const initialTexture = getLevelTexture(ctx, levels)
......
...@@ -76,8 +76,7 @@ export function calcActiveVoxels(ctx: WebGLContext, cornerTex: Texture, gridDime ...@@ -76,8 +76,7 @@ export function calcActiveVoxels(ctx: WebGLContext, cornerTex: Texture, gridDime
gl.viewport(0, 0, width, height) gl.viewport(0, 0, width, height)
renderable.render() renderable.render()
// const at = readTexture(ctx, activeVoxelsTex) // console.log('at', readTexture(ctx, activeVoxelsTex))
// console.log('at', at)
return activeVoxelsTex return activeVoxelsTex
} }
\ No newline at end of file
...@@ -78,19 +78,19 @@ function setRenderingDefaults(gl: GLRenderingContext) { ...@@ -78,19 +78,19 @@ function setRenderingDefaults(gl: GLRenderingContext) {
gl.disable(gl.BLEND) gl.disable(gl.BLEND)
gl.disable(gl.DEPTH_TEST) gl.disable(gl.DEPTH_TEST)
gl.depthMask(false) gl.depthMask(false)
gl.enable(gl.SCISSOR_TEST)
} }
export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Texture, volumeData: Texture, histogramPyramid: HistogramPyramid, gridDimensions: Vec3, transform: Mat4, isoValue: number) { export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Texture, volumeData: Texture, histogramPyramid: HistogramPyramid, gridDimensions: Vec3, transform: Mat4, isoValue: number, vertexGroupTexture?: Texture, normalTexture?: Texture) {
const { gl, framebufferCache } = ctx const { gl, framebufferCache } = ctx
const { pyramidTex, height, levels, scale, count } = histogramPyramid const { pyramidTex, height, levels, scale, count } = histogramPyramid
const framebuffer = framebufferCache.get(FramebufferName).value const framebuffer = framebufferCache.get(FramebufferName).value
framebuffer.bind()
const vertexGroupTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest') if (!vertexGroupTexture) vertexGroupTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest')
vertexGroupTexture.define(pyramidTex.width, pyramidTex.height) vertexGroupTexture.define(pyramidTex.width, pyramidTex.height)
const normalTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest') if (!normalTexture) normalTexture = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest')
normalTexture.define(pyramidTex.width, pyramidTex.height) normalTexture.define(pyramidTex.width, pyramidTex.height)
// const infoTex = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest') // const infoTex = createTexture(ctx, 'image-float32', 'rgba', 'float', 'nearest')
...@@ -119,7 +119,7 @@ export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Tex ...@@ -119,7 +119,7 @@ export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Tex
// indexTex.attachFramebuffer(framebuffer, 5) // indexTex.attachFramebuffer(framebuffer, 5)
const { drawBuffers } = ctx.extensions const { drawBuffers } = ctx.extensions
if (!drawBuffers) throw new Error('need draw buffers') if (!drawBuffers) throw new Error('need WebGL draw buffers')
drawBuffers.drawBuffers([ drawBuffers.drawBuffers([
drawBuffers.COLOR_ATTACHMENT0, drawBuffers.COLOR_ATTACHMENT0,
......
...@@ -110,10 +110,9 @@ void main(void) { ...@@ -110,10 +110,9 @@ void main(void) {
// get index into triIndices table // get index into triIndices table
float mcIndex = 16. * edgeIndex + currentVertex; float mcIndex = 16. * edgeIndex + currentVertex;
vec4 mcData = texture2D(tTriIndices, vec2(intMod(mcIndex, 64.), floor(mcIndex / 64.)) / 64.); vec4 mcData = texture2D(tTriIndices, vec2(intMod(mcIndex, 64.), floor(mcIndex / 64.)) / 64.);
mcIndex = floor(mcData.a * 255.0 + 0.5);
// bit mask to avoid conditionals (see comment below) for getting MC case corner // bit mask to avoid conditionals (see comment below) for getting MC case corner
vec4 m0 = vec4(mcIndex); vec4 m0 = vec4(floor(mcData.a * 255.0 + 0.5));
// get edge value masks // get edge value masks
vec4 m1 = vec4(equal(m0, vec4(0., 1., 2., 3.))); vec4 m1 = vec4(equal(m0, vec4(0., 1., 2., 3.)));
......
...@@ -86,7 +86,7 @@ async function createGaussianSurfaceTextureMesh(ctx: VisualContext, unit: Unit, ...@@ -86,7 +86,7 @@ async function createGaussianSurfaceTextureMesh(ctx: VisualContext, unit: Unit,
const compacted = createHistogramPyramid(ctx.webgl, activeVoxelsTex) const compacted = createHistogramPyramid(ctx.webgl, activeVoxelsTex)
// ctx.webgl.waitForGpuCommandsCompleteSync() // ctx.webgl.waitForGpuCommandsCompleteSync()
const gv = createIsosurfaceBuffers(ctx.webgl, activeVoxelsTex, densityTextureData.texture, compacted, densityTextureData.gridDimension, densityTextureData.transform, isoLevel) const gv = createIsosurfaceBuffers(ctx.webgl, activeVoxelsTex, densityTextureData.texture, compacted, densityTextureData.gridDimension, densityTextureData.transform, isoLevel, textureMesh ? textureMesh.vertexGroupTexture.ref.value : undefined, textureMesh ? textureMesh.normalTexture.ref.value : undefined)
// ctx.webgl.waitForGpuCommandsCompleteSync() // ctx.webgl.waitForGpuCommandsCompleteSync()
// const boundingSphere = Sphere3D.zero() // const boundingSphere = Sphere3D.zero()
......
...@@ -61,29 +61,29 @@ async function init() { ...@@ -61,29 +61,29 @@ async function init() {
} }
const isoValue = Math.exp(-props.smoothness) const isoValue = Math.exp(-props.smoothness)
// if (true) { if (true) {
// console.time('gpu gaussian2') console.time('gpu gaussian2')
// const densityTextureData2 = await computeGaussianDensityTexture2d(position, box, radius, props, webgl).run() const densityTextureData2 = await computeGaussianDensityTexture2d(position, box, radius, props, webgl).run()
// webgl.waitForGpuCommandsCompleteSync() webgl.waitForGpuCommandsCompleteSync()
// console.timeEnd('gpu gaussian2') console.timeEnd('gpu gaussian2')
// console.time('gpu mc2') console.time('gpu mc2')
// console.time('gpu mc active2') console.time('gpu mc active2')
// const activeVoxelsTex2 = calcActiveVoxels(webgl, densityTextureData2.texture, densityTextureData2.gridDimension, isoValue) const activeVoxelsTex2 = calcActiveVoxels(webgl, densityTextureData2.texture, densityTextureData2.gridDimension, isoValue)
// webgl.waitForGpuCommandsCompleteSync() webgl.waitForGpuCommandsCompleteSync()
// console.timeEnd('gpu mc active2') console.timeEnd('gpu mc active2')
// console.time('gpu mc pyramid2') console.time('gpu mc pyramid2')
// const compacted2 = createHistogramPyramid(webgl, activeVoxelsTex2) const compacted2 = createHistogramPyramid(webgl, activeVoxelsTex2)
// webgl.waitForGpuCommandsCompleteSync() webgl.waitForGpuCommandsCompleteSync()
// console.timeEnd('gpu mc pyramid2') console.timeEnd('gpu mc pyramid2')
// console.time('gpu mc vert2') console.time('gpu mc vert2')
// const gv2 = createIsosurfaceBuffers(webgl, activeVoxelsTex2, densityTextureData2.texture, compacted2, densityTextureData2.gridDimension, densityTextureData2.transform, isoValue) createIsosurfaceBuffers(webgl, activeVoxelsTex2, densityTextureData2.texture, compacted2, densityTextureData2.gridDimension, densityTextureData2.transform, isoValue)
// webgl.waitForGpuCommandsCompleteSync() webgl.waitForGpuCommandsCompleteSync()
// console.timeEnd('gpu mc vert2') console.timeEnd('gpu mc vert2')
// console.timeEnd('gpu mc2') console.timeEnd('gpu mc2')
// } }
console.time('gpu gaussian') console.time('gpu gaussian')
const densityTextureData = await computeGaussianDensityTexture2d(position, box, radius, props, webgl).run() const densityTextureData = await computeGaussianDensityTexture2d(position, box, radius, props, webgl).run()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment