Skip to content

ssao: reconstruct SAO taps at their depth texel - #10881

Merged
romainguy merged 3 commits into
google:mainfrom
jeongseok-meta:fix-sao-texel-center
Nov 25, 2026
Merged

romainguy merged 3 commits into
google:mainfrom
jeongseok-meta:fix-sao-texel-center

Conversation

@jeongseok-meta

Copy link
Copy Markdown
Contributor

Fixes #10880.

SAO reads each tap's depth with nearest filtering, so the depth belongs to one texel's center, and each depth mip keeps one texel of each 2x2 block (mipmapDepth.mat). computeAmbientOcclusionSAO() rebuilt the tap's position at the tap's own sub-texel uv instead. On a surface at an angle to the view, that point lies up to a texel's depth change off the surface; the points in front count as occlusion and the ones behind are clamped to zero, so flat, open surfaces got ambient occlusion that grew as the AO buffer got smaller.

The new depthTexelUV() in ssaoUtils.fs returns the uv of the center of the level-0 texel whose depth the sample returned: it follows mipmapDepth.mat's choice in each 2x2 block back to level 0. SAO rebuilds each tap there, so the point lies on the surface.

Far wall of the repro in #10880 (mean value, linear output, post-processing off):

Render size 256 512 1024 2048
Before 11.0 11.6 13.7 16.0
After 16.0 16.0 16.0 16.0
SSAO off 16.0 16.0 16.0 16.0

Real occlusion stays. At the crease between that wall and the floor, SSAO off reads 15.7; after the change it reads 11.1 to 12.7 across the four sizes (before: 8.5 to 12.0). Next to a box standing on the floor, SSAO off reads 23.8; after, 19.6 to 20.8.

Same view at 256, 512, 1024 and 2048 px: as released, with the fix, SSAO off

Testing:

  • Built into MuJoCo 4.0.1's Studio module against Filament rc/1.79.0 (saoImpl.fs and ssaoUtils.fs are the same on main) and ran the repro on Vulkan (Mesa lavapipe, NVIDIA A100) and OpenGL (A100): the table above on every backend. Its check (the far wall reads within half a value of SSAO off at 256 and 1024 px) fails before this change and passes after.
  • matc compiles sao, saoBentNormals, gtao, gtaoBentNormals, bilateralBlur and bilateralBlurBentNormals for OpenGL, Vulkan and Metal, desktop and mobile. I didn't build WebGPU.
  • Frame time: no measurable change on an NVIDIA A100 at 2048 x 2048.
  • The renderdiff SSAO goldens (Duck, lucy) will change where surfaces face away from the camera.

GTAO reads depth the same way but is hardly affected by it (15.97 to 16.0 on the same wall). Rebuilding its taps at texel centers made it noisier there, so this change leaves GTAO as it is.

SAO reads a tap's depth with nearest filtering, so the depth belongs
to one texel's center, and each depth mip keeps one texel of each 2x2
block. The tap's position was rebuilt at its own sub-texel uv, so on a
surface at an angle to the view the point lay up to a texel's depth
change off the surface. Points in front counted as occlusion and
points behind were clamped to zero, so flat, open surfaces got
ambient occlusion that grew as the AO buffer got smaller.

Rebuild each tap at the center of the level-0 texel its depth comes
from.

Fixes google#10880

RDIFF_ACCEPT_NEW_GOLDENS
@romainguy

Copy link
Copy Markdown
Contributor

Thanks! That's a great fix

@romainguy romainguy added the internal Issue/PR does not affect clients label Nov 24, 2026
@romainguy

Copy link
Copy Markdown
Contributor

@jeongseok-meta Can you add RDIFF_ACCEPT_NEW_GOLDENS to your commit message please? Not the PR description, but the actual commit. This will request new goldens to be generated.

Comment on lines +37 to +40
// A nearest-filtered sample at uv returns the depth of one texel's center, and each mip level
// holds the depth of one texel of the 2x2 block below it (see mipmapDepth.mat). This returns the
// uv of the center of the level-0 texel that depth comes from. A position reconstructed there
// lies on the surface; reconstructed at uv itself, it lies up to a texel's depth change off it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could really use a more human comment here (maybe tell ai to write in asd-ste100?)

@jeongseok-meta

jeongseok-meta commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Added it to the commit message, and simplified the comments.

@romainguy
romainguy enabled auto-merge (squash) November 25, 2026 07:08
@romainguy

Copy link
Copy Markdown
Contributor

There seems to be an unrelated test failure: ThreadMapTest.ConcurrentSetReaderDataRace

@romainguy
romainguy merged commit 863e7d7 into google:main Nov 25, 2026
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSAO darkens flat, open surfaces more at smaller render sizes

4 participants