From e1743644f25aede2d8fb79c5839c530542ccae4b Mon Sep 17 00:00:00 2001 From: ctwhome Date: Thu, 14 Mar 2024 09:19:28 +0100 Subject: [PATCH 1/6] WIP --- src/lib/shaders/volume_transfer.frag | 10 +++++----- src/routes/viewer/sceneSetup/updateMaterial.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/shaders/volume_transfer.frag b/src/lib/shaders/volume_transfer.frag index a2d39b2..15752ec 100644 --- a/src/lib/shaders/volume_transfer.frag +++ b/src/lib/shaders/volume_transfer.frag @@ -1,13 +1,13 @@ // This code is based upon Janelia's web-vol-viewer // https://github.com/JaneliaSciComp/web-vol-viewer -precision highp float; +precision mediump float; in vec3 rayDirUnnorm; in vec3 lightDir; uniform sampler2D transferTex; -// uniform lowp sampler3D volumeTex; uniform lowp sampler3D volumeTex; +uniform lowp sampler3D coarseVolumeTex; uniform float dtScale; uniform float finalGamma; uniform vec3 sunLightColor; @@ -66,7 +66,7 @@ void main(void){ tBox.x=max(tBox.x,0.); - ivec3 volumeTexSize=textureSize(volumeTex,0); + ivec3 volumeTexSize=textureSize(coarseVolumeTex,0); // vec3 dt0 = 1.0 / (vec3(volumeTexSize) * abs(rayDir)); vec3 dt0=1./(vec3(volumeTexSize)*abs(rayDir)); float dt=min(dt0.x,min(dt0.y,dt0.z)) * 0.5; @@ -101,8 +101,8 @@ void main(void){ vec3 random=fract(sin(gl_FragCoord.x*12.9898+gl_FragCoord.y*78.233)*43758.5453)*dt*rayDir/8.0; for(float t=tBox.x;t Date: Wed, 27 Mar 2024 20:26:25 +0100 Subject: [PATCH 2/6] Fixed empty space skipping for 3d rain --- src/lib/shaders/volume_transfer.frag | 9 ++--- src/lib/utils/makeRainTransferTex.ts | 9 +++-- .../viewer/fetchAndPrepareData/coarseData.ts | 38 +++++++++++-------- .../viewer/fetchAndPrepareData/fetchSlice.ts | 5 ++- .../viewer/sceneSetup/updateMaterial.ts | 21 +++++++--- 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/lib/shaders/volume_transfer.frag b/src/lib/shaders/volume_transfer.frag index 15752ec..94018f4 100644 --- a/src/lib/shaders/volume_transfer.frag +++ b/src/lib/shaders/volume_transfer.frag @@ -67,9 +67,8 @@ void main(void){ tBox.x=max(tBox.x,0.); ivec3 volumeTexSize=textureSize(coarseVolumeTex,0); - // vec3 dt0 = 1.0 / (vec3(volumeTexSize) * abs(rayDir)); vec3 dt0=1./(vec3(volumeTexSize)*abs(rayDir)); - float dt=min(dt0.x,min(dt0.y,dt0.z)) * 0.5; + float dt=min(dt0.x,min(dt0.y,dt0.z)); // Prevents a lost WebGL context. if(dt<.00001){ @@ -100,9 +99,9 @@ void main(void){ float transmittance_threshold=0.05; vec3 random=fract(sin(gl_FragCoord.x*12.9898+gl_FragCoord.y*78.233)*43758.5453)*dt*rayDir/8.0; for(float t=tBox.x;t x){ + x = value; + } } } } - const index2 = k + j * shape[2] / 8 + i * (shape[2] / 8) * (shape[1] / 8); - dataCoarse[index2] = x + dataCoarse[index2] = x; + index2++; } } } - // console.log("...Done"); + console.log("...Done"); return dataCoarse; } \ No newline at end of file diff --git a/src/routes/viewer/fetchAndPrepareData/fetchSlice.ts b/src/routes/viewer/fetchAndPrepareData/fetchSlice.ts index 276ca1e..a62dc54 100644 --- a/src/routes/viewer/fetchAndPrepareData/fetchSlice.ts +++ b/src/routes/viewer/fetchAndPrepareData/fetchSlice.ts @@ -2,7 +2,7 @@ import { openArray, HTTPStore } from 'zarr'; import type { PersistenceMode } from 'zarr/types/types'; import { dataSlices } from "../stores/allSlices.store"; -import { coarseData } from './coarseData'; +//import { coarseData } from './coarseData'; // downloadZarrPoints export async function fetchSlice({ @@ -27,7 +27,8 @@ export async function fetchSlice({ let dataUint8 = null; if (path == 'qr') { // Coarse data to compress the ammount of data - dataUint8 = coarseData(shape, data); +// dataUint8 = coarseData(shape, data); + dataUint8 = data; } else { dataUint8 = data; diff --git a/src/routes/viewer/sceneSetup/updateMaterial.ts b/src/routes/viewer/sceneSetup/updateMaterial.ts index e031847..76f24c5 100644 --- a/src/routes/viewer/sceneSetup/updateMaterial.ts +++ b/src/routes/viewer/sceneSetup/updateMaterial.ts @@ -25,6 +25,7 @@ export function updateMaterial({ variable, dataUint8 }) { const uniforms = localBox.material.uniforms; const sizes = get(volumeSizes)[variable]; let volumeTexture = null; + let coarseVolumeTexture = null; // // Dispose of the old texture to free up memory. @@ -32,10 +33,12 @@ export function updateMaterial({ variable, dataUint8 }) { if (uniforms?.volumeTex.value !== null) { uniforms.volumeTex.value.dispose(); } + const s0 = Math.ceil(sizes[0] / 8); + const s1 = Math.ceil(sizes[1] / 8); + const s2 = Math.ceil(sizes[2] / 8); switch (variable) { case 'ql': volumeTexture = new THREE.Data3DTexture(dataUint8, sizes[0], sizes[1], sizes[2]); - volumeTexture.format = THREE.RedFormat; volumeTexture.minFilter = THREE.LinearFilter; // Better for volume rendering. volumeTexture.magFilter = THREE.LinearFilter; uniforms.dataScale.value = qlScale; @@ -50,10 +53,11 @@ export function updateMaterial({ variable, dataUint8 }) { break; case 'qr': - // uniforms?.coarseVolumeTex?.value?.dispose(); - + if (uniforms?.coarseVolumeTex.value !== null) { + uniforms.coarseVolumeTex.value.dispose(); + } + volumeTexture = new THREE.Data3DTexture(dataUint8, sizes[0], sizes[1], sizes[2]); - volumeTexture.format = THREE.RedFormat; volumeTexture.minFilter = THREE.NearestFilter; volumeTexture.magFilter = THREE.NearestFilter; uniforms.dataScale.value = qrScale; @@ -61,7 +65,14 @@ export function updateMaterial({ variable, dataUint8 }) { uniforms.alphaNorm.value = 2.0; uniforms.finalGamma.value = finalGamma; - uniforms.coarseVolumeTex.value = new THREE.Data3DTexture(coarseData(sizes, dataUint8), sizes[0] / 8, sizes[1] / 8, sizes[2] / 8);; + coarseVolumeTexture = new THREE.Data3DTexture(coarseData(dataUint8, sizes), s0, s1, s2); + coarseVolumeTexture.format = THREE.RedFormat; + coarseVolumeTexture.minFilter = THREE.NearestFilter; + coarseVolumeTexture.magFilter = THREE.NearestFilter; + coarseVolumeTexture.type = THREE.UnsignedByteType; + coarseVolumeTexture.generateMipmaps = false; // Saves memory. + coarseVolumeTexture.needsUpdate = true; + uniforms.coarseVolumeTex.value = coarseVolumeTexture; break; case 'thetavmix': From b8336a2cdff6eda284b5ae50d76457b16bd5bec7 Mon Sep 17 00:00:00 2001 From: goord Date: Sat, 30 Mar 2024 11:23:08 +0100 Subject: [PATCH 3/6] first version of substepping --- src/lib/shaders/volume.frag | 3 ++- src/lib/shaders/volume_transfer.frag | 5 ++-- src/routes/viewer/+page.svelte | 4 ++- src/routes/viewer/components/TimeLine.svelte | 25 +++++++++++++---- src/routes/viewer/components/Viewer.svelte | 4 ++- src/routes/viewer/sceneSetup/initMaterial.ts | 9 ++++--- .../viewer/sceneSetup/updateMaterial.ts | 27 ++++++++++++++++--- src/routes/viewer/stores/allSlices.store.ts | 2 -- 8 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/lib/shaders/volume.frag b/src/lib/shaders/volume.frag index ecee761..7521585 100644 --- a/src/lib/shaders/volume.frag +++ b/src/lib/shaders/volume.frag @@ -18,6 +18,7 @@ uniform float gHG; uniform float dataEpsilon; uniform vec3 bottomColor; uniform float bottomHeight; +uniform vec3 displacement; // Optional parameters, for when a solid surface is being drawn along with // the volume data. @@ -163,7 +164,7 @@ void main(void){ vec3 dg=vec3(1)/vec3(volumeTexSize); for(float t=tBox.x;t import TimeLine from './components/TimeLine.svelte'; - import { dataSlices, currentTimeIndex, totalSlices } from './stores/allSlices.store'; + import { dataSlices, totalSlices } from './stores/allSlices.store'; import { cloudLayerSettings, rainLayerSettings, @@ -9,6 +9,8 @@ temperatureLayerSettings } from './stores/viewer.store'; + import { currentTimeIndex } from './sceneSetup/updateMaterial'; + import Stats from '$lib/components/Stats.svelte'; import Viewer from './components/Viewer.svelte'; // import Viewer from '$lib/components/viewerExample.svelte'; diff --git a/src/routes/viewer/components/TimeLine.svelte b/src/routes/viewer/components/TimeLine.svelte index 0ddbdc1..ba2d5bd 100644 --- a/src/routes/viewer/components/TimeLine.svelte +++ b/src/routes/viewer/components/TimeLine.svelte @@ -1,14 +1,18 @@