Skip to content

fix(vtkVolumeFS): fix samples weighting in average blending - #3631

Open
Jo-Byr wants to merge 1 commit into
Kitware:masterfrom
Jo-Byr:fix-average-blending-sample-weighting
Open

fix(vtkVolumeFS): fix samples weighting in average blending#3631
Jo-Byr wants to merge 1 commit into
Kitware:masterfrom
Jo-Byr:fix-average-blending-sample-weighting

Conversation

@Jo-Byr

@Jo-Byr Jo-Byr commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Context

Average blend mode has some weighting errors resulting in a noise texture being applied on the volume.

This is mostly visible if the number of samples on the volume is low, as the last sample is weighted more than it should, which is less visible if it's averaged with more samples.

Results

Said errors are fixed

Changes

Remove weighting of unique samples
Add missing weight to numerator of last sample in average and additive blending

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat to have correctly formatted code

@Jo-Byr
Jo-Byr requested a review from finetjul September 4, 2026 13:09
@Jo-Byr Jo-Byr self-assigned this Sep 4, 2026

@sankhesh sankhesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daker

daker commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

@Jo-Byr Can you apply the same to WebGPU

diff --git a/Sources/Rendering/WebGPU/VolumePassFSQ/index.js b/Sources/Rendering/WebGPU/VolumePassFSQ/index.js
index 172a346510..0fbda7b240 100644
--- a/Sources/Rendering/WebGPU/VolumePassFSQ/index.js
+++ b/Sources/Rendering/WebGPU/VolumePassFSQ/index.js
@@ -1400,13 +1400,9 @@ fn traverseAverage(vTex: texture_3d<f32>, vNum: i32, rowIdx: i32, rayLengthSC: f
   let firstValue = getTextureValue(vTex, tpos, vNum);
   if (raySpan <= 1.0)
   {
-    // Match the OpenGL mapper's effective coverage for a subsample projection
-    // ray. Its rasterized entry/exit interval is 5/4 of the analytic interval
-    // used by this fullscreen WebGPU pass.
-    let thinRayWeight = raySpan * 1.25;
     traverseVals[vNum] = processVolumeSample(
       vTex, fragPos, vNum, rowIdx,
-      minPosSC + rayStepSC * rayBounds.x, tpos, firstValue * thinRayWeight, tfunRows, false);
+      minPosSC + rayStepSC * rayBounds.x, tpos, firstValue, tfunRows, false);
     return;
   }
 
@@ -1438,7 +1434,7 @@ fn traverseAverage(vTex: texture_3d<f32>, vNum: i32, rowIdx: i32, rayLengthSC: f
   let endValue = getTextureValue(vTex, endTpos, vNum);
   if (valueWithinIPRange(endValue, vNum))
   {
-    sum = sum + endValue;
+    sum = sum + endValue * (rayBounds.y - curDist);
     totalWeight = totalWeight + rayBounds.y - curDist;
   }
 
@@ -1486,7 +1482,7 @@ fn traverseAdditive(vTex: texture_3d<f32>, vNum: i32, rowIdx: i32, rayLengthSC:
   {
     traverseVals[vNum] = processVolumeSample(
       vTex, fragPos, vNum, rowIdx,
-      minPosSC + rayStepSC * rayBounds.x, tpos, firstValue * raySpan, tfunRows, false);
+      minPosSC + rayStepSC * rayBounds.x, tpos, firstValue, tfunRows, false);
     return;
   }
 
@@ -1514,7 +1510,7 @@ fn traverseAdditive(vTex: texture_3d<f32>, vNum: i32, rowIdx: i32, rayLengthSC:
   let endValue = getTextureValue(vTex, endTpos, vNum);
   if (valueWithinIPRange(endValue, vNum))
   {
-    sum = sum + endValue;
+    sum = sum + endValue * (rayBounds.y - curDist);
   }
   traverseVals[vNum] = processVolumeSample(
     vTex, fragPos, vNum, rowIdx,

Remove weighting of unique samples
Add missing weight to numerator of last sample in average
and additive blending
@Jo-Byr
Jo-Byr force-pushed the fix-average-blending-sample-weighting branch from aeb1dbd to 34d5fa2 Compare September 7, 2026 07:27

@daker daker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants