Skip to content

feat(render3d): add composable 3D post-processing (Bloom, SSAO, Depth of Field) - #727

Merged
houko merged 9 commits into
mainfrom
feat/render3d-post-processing-282
Nov 24, 2026
Merged

houko merged 9 commits into
mainfrom
feat/render3d-post-processing-282

Conversation

@houko

@houko houko commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements composable offscreen 3D post-processing in packages/game/render3d/post3d.go over NSGo gpu.RenderTarget attachments (FormatRGBA16Float / FormatRGBA8Unorm color + FormatDepth32Float depth):

  • Bloom (BloomPass, BloomConfig): HDR/LDR bright extraction with quadratic Threshold + SoftKnee, configurable separable 9-tap Gaussian blur (BlurPasses, Radius, HalfRes) across offscreen ping-pong render targets, and additive composition with Intensity.
  • SSAO (SSAOPass, SSAOConfig): view-space position and edge-preserving 4-neighbor depth-difference normal reconstruction, deterministic 4–16-sample hemisphere kernel with stratified 4×4 tangent rotation, optional depth-aware bilateral blur (BlurRadius, DepthThreshold), inspectable AOTexture(), and multiplicative scene compositing.
  • Depth of Field (DepthOfFieldPass, DepthOfFieldConfig): perspective and orthographic [0, 1] depth linearization, signed Circle of Confusion prepass around FocusDistance ± FocusRange, and 18-tap two-ring disc bokeh gather that prevents background blur from bleeding across sharp in-focus silhouettes.
  • Composable Stack (PostStack3D): executes enabled stages in order (SSAO → Depth of Field → Bloom) via ping-pong offscreen targets, supports standalone passes via PostPassRecorder (*gpu.Frame and *gpu.Encoder), Resize(dev, w, h), and Retained device-loss restoration (including automatic pipeline/bind-group rebuild on restored devices).
  • Portability: fragment-only WGSL with explicit textureSampleLevel, FilterNearest depth sampling, and precomputed/algebraic weights (no compute shaders, dpdx/dpdy, or exp/log2), verified on both full and nsgotest.NoGPUCompute (WebGL 2 / GLES 3.0) profiles.

Closes #282

Verification

  • gofmt -l on tracked Go files: clean
  • go run ./cmd/gameschema -check: passed
  • go tool nsgo check -target macos,windows,linux,android,web: passed across all 8 architectures
  • go tool nsgo test ./render3d: 87 passed, 0 failed (including golden reference renders post3d_bloom.png, post3d_ssao.png, post3d_dof.png, post3d_combined.png, NoGPUCompute profile, and Retained device-loss recovery)
  • go tool nsgo test . -- -run 'TestFormatPackagesRunConformance|TestFormatsPage|TestStabilityTable': 3 passed, 0 failed
  • go run ./tools/changelog check: passed
  • bun run verify-notes: passed (20 notes verified)

@github-actions github-actions Bot added enhancement New feature or request documentation Improvements or additions to documentation size/XL pkg/render3d area/agents conflict Conflicts with the target branch; resolve before merging labels Nov 24, 2026
@houko
houko force-pushed the feat/render3d-post-processing-282 branch from 1b4c64e to 27c75bf Compare November 24, 2026 18:21
@houko

houko commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and addressed the review:

  • Uses the existing RenderPassRecorder (dynres.go) instead of a second PostPassRecorder interface.
  • The last stage now picks its pipeline from the destination's format: nil writes to the swapchain in OutputFormat, a texture must be in ColorFormat or OutputFormat, anything else returns ErrInvalidPostProcess (stack, each pass, and the passthrough blit).
  • Inputs and destinations whose size differs from the pass/stack, and a destination that is also an input, are rejected.
  • ColorFormat is limited to RGBA16Float, RGBA8Unorm(SRGB) and BGRA8Unorm(SRGB).
  • DepthOfFieldConfigFromCamera and SSAOConfigFromCamera read near/far/kind from cam.ProjMatrix(), so projection defaults and orthographic near planes at or behind the camera match the depth buffer; orthographic configs no longer require Near > 0.
  • New PostStack3D.SetCamera(cam) refreshes the SSAO projection and DoF clip planes after a resize or zoom; the 60-degree fallback for a zero ProjMatrix is documented.
  • SetSSAO / SetDepthOfField / SetBloom keep the current config when given a zero one.
  • Tests reuse assertReference and add cases for caller-owned destinations, size/hazard checks, format validation, toggles, SetCamera, orthographic DoF, the SSAO fallback and HalfRes toggling. Comments are no longer hard-wrapped.

Not added: a test for Apply after a non-retained device loss (the existing retained recovery test still covers the loss path).

@github-actions github-actions Bot removed the conflict Conflicts with the target branch; resolve before merging label Nov 24, 2026
@houko
houko merged commit c6ba3f1 into main Nov 24, 2026
21 of 33 checks passed
@houko
houko deleted the feat/render3d-post-processing-282 branch November 24, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents documentation Improvements or additions to documentation enhancement New feature or request pkg/render3d size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3D effects: post-processing

1 participant