Skip to content

Add CornellBox denoising and upscaling and refactor rendering passes - #35

Merged
qian-o merged 26 commits into
masterfrom
exp/upscaling
Sep 15, 2026
Merged

qian-o merged 26 commits into
masterfrom
exp/upscaling

Conversation

@qian-o

@qian-o qian-o commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

CornellBox now uses a path-tracing, denoising, upscaling, and tone-mapping pipeline with adjustable render resolution and selectable spatial or temporal upscaling. This replaces its rasterization mode and requires ray-tracing support.

  • Add temporal reprojection and five à-trous filtering passes, using depth, normal, and motion-vector outputs from path tracing.
  • Refactor CornellBox and FluidTank rendering passes around explicit dimensions, shared frame arguments, and consistent resource ownership.
  • Refine FluidTank surface coverage, choose reflection shaders from device capabilities, and always enable antialiasing.
  • Standardize InkCanvas disposal and update ImageSharp to 4.1.2.

Added Zenith.NET.Extensions.Upscaling as a project reference in CornellBox.csproj to enable usage of upscaling extension features. No other changes made.
Refactored TranslateInputKeyToImGuiKey to use range-based mapping for number, letter, and function keys. Updated OnKeyDown/OnKeyUp to use scanCode as parameter. Made OtherSetup safe and removed IniFilename assignment. Added IME unsupported comment to SetImeData. Changed VKSwapChain present mode query to use default for presentModeCount.
- Introduced `UpscalePass` for spatial and temporal upscaling of textures.
- Created `Renderer` class to manage rendering pipeline, including path tracing, denoising, and tonemapping.
- Removed obsolete `RasterizationRenderer` and abstract `Renderer` classes.
- Added shader compilation script for automatic shader generation.
- Updated `Program.cs` and `launchSettings.json` for consistency.
…s definitions and related methods. This file was responsible for generating shader code and has been completely deleted.
- Move ImGui background drawing before overlay in App.cs for correct rendering order.
- Make creation and upload of TemporalConstants and AtrousConstants explicit in DenoisePass.cs; fix Atrous offset calculation location.
- Refactor PathTracingPass.cs Resize to consistently dispose/recreate textures, preventing leaks.
- Simplify TonemapPass.cs Resize to dispose/recreate color texture.
- Remove unsafe from UpscalePass.cs, improve resource disposal, refactor upscaler selection with switch, and simplify dispatch logic.
Refactored Renderer to use auto-properties with custom setters for RenderPrecision and UpscaleMode, triggering resize logic on change. Updated ImGui UI to use local variables and apply changes only when modified. Removed redundant fields and Update method, consolidating state management. Simplified Resize method and cleaned up render logic.
- Refactored ShaderPath in Pass.cs to use 'file' parameter.
- Removed redundant shaderFile variable in DenoisePass.cs; now calls ShaderPath inline.
- Renamed computeShader to shader in PathTracingPass.cs for clarity.
- Added resource layout transition after compute dispatch in PathTracingPass.cs to ensure correct texture usage.
Moves the AddImage call to after the ImGuiHelper.Settings block, ensuring the image is drawn after the settings UI and before the overlay. This changes the rendering order for better UI layering.
Refactored the weight variable calculation in the AtrousMain function by combining multiple lines into a single line for improved readability and conciseness. The calculation logic remains unchanged.
Updated SixLabors.ImageSharp version from 4.1.1 to 4.1.2 in Directory.Packages.props to include latest fixes and improvements.
Removed outputWidth, outputHeight, renderWidth, and renderHeight fields from Renderer. Width and height calculations are now local to methods, using App.Width and App.Height or computing values as needed. This simplifies state management and ensures resizing uses current app dimensions.
Converted constructors of DenoisePass, PathTracingPass, TonemapPass, and UpscalePass to primary constructors. Simplified property initialization in UpscalePass. Renderer now uses App.Width and App.Height directly for pass initialization and resizing, and removes redundant dimension checks.
- Introduced a new `Pass` abstract class to streamline rendering passes.
- Updated `WaterPass` to utilize the new `Pass` structure, improving initialization and resource management.
- Refactored `Renderer` to remove direct context dependencies, enhancing modularity.
- Created `PassArgs` struct to encapsulate rendering parameters, simplifying method signatures across passes.
- Added `FluidTankGeometry` class for scene geometry creation, including boxes and cylinders.
- Refactored `Simulation` class to remove context dependency and improve resource management.
- Enhanced texture and buffer creation methods for better encapsulation and reuse.
- Removed unnecessary helper classes and methods to clean up the codebase.
The return statement in the SampleFluid function was reformatted to improve readability. No changes were made to the logic or functionality; only the code formatting was updated.
Copilot AI lite review requested due to automatic review settings September 15, 2026 14:00

Copilot AI left a comment

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.

🟡 Changes recommended

Critical pass-initialization issues and moderate shader, resize, and caching issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR replaces CornellBox rasterization with a ray-traced denoising/upscaling pipeline and refactors FluidTank rendering and resource ownership.

Changes:

  • Adds path tracing, denoising, spatial/temporal upscaling, and tone mapping.
  • Refactors FluidTank passes, surface coverage, reflections, and antialiasing.
  • Standardizes disposal and updates Vulkan handling and ImageSharp.
File summaries
File Summary
sources/Zenith.NET.Vulkan/VKSwapChain.cs Updates optional pointer handling.
sources/Experiments/InkCanvas/Drawing/Toolbar.cs Standardizes disposal.
sources/Experiments/InkCanvas/Drawing/Stroke.cs Standardizes disposal.
sources/Experiments/InkCanvas/Drawing/CanvasController.cs Standardizes disposal.
sources/Experiments/InkCanvas/Drawing/Canvas.cs Standardizes disposal.
sources/Experiments/FluidTank/Simulation.cs Refactors simulation resources.
sources/Experiments/FluidTank/Renderer.cs Coordinates rendering passes.
sources/Experiments/FluidTank/Passes/WaterPass.cs Adds capability-based reflection shaders.
sources/Experiments/FluidTank/Passes/SurfacePass.cs Adds surface outputs and coverage data.
sources/Experiments/FluidTank/Passes/ScenePass.cs Refactors scene resources.
sources/Experiments/FluidTank/Passes/Pass.cs Adds shared pass lifecycle.
sources/Experiments/FluidTank/Passes/OutputPass.cs Enables tone mapping and antialiasing.
sources/Experiments/FluidTank/Passes/GlassPass.cs Refactors glass rendering.
sources/Experiments/FluidTank/Models/SceneResources.cs Refactors scene ownership.
sources/Experiments/FluidTank/Models/PassArgs.cs Adds shared render arguments.
sources/Experiments/FluidTank/Models/ParticleData.cs Makes particle data immutable.
sources/Experiments/FluidTank/Models/FrameData.cs Removes obsolete frame data.
sources/Experiments/FluidTank/Models/FluidViewMode.cs Makes enum values explicit.
sources/Experiments/FluidTank/Models/FluidTankGeometry.cs Moves geometry into the models namespace.
sources/Experiments/FluidTank/Helpers/GraphicsHelper.cs Removes obsolete helpers.
sources/Experiments/FluidTank/Handlers/ImGuiHandler.cs Updates platform handling.
sources/Experiments/FluidTank/Assets/Shaders/Output.slang Outputs luminance metadata.
sources/Experiments/FluidTank/Assets/Shaders/FluidComposite.slang Adds coverage-aware compositing.
sources/Experiments/FluidTank/App.cs Updates UI and rendering integration.
sources/Experiments/CornellBox/Renderers/Renderer.cs Removes the old renderer base.
sources/Experiments/CornellBox/Renderers/RasterizationRenderer.cs Removes rasterization rendering.
sources/Experiments/CornellBox/Renderer.cs Adds the pipeline coordinator.
sources/Experiments/CornellBox/Properties/launchSettings.json Adjusts formatting.
sources/Experiments/CornellBox/Program.cs Updates entry-point formatting.
sources/Experiments/CornellBox/Passes/UpscalePass.cs Adds spatial and temporal upscaling.
sources/Experiments/CornellBox/Passes/TonemapPass.cs Adds compute tone mapping.
sources/Experiments/CornellBox/Passes/PathTracingPass.cs Adds path-tracing resources.
sources/Experiments/CornellBox/Passes/Pass.cs Adds shared pass lifecycle and sizing.
sources/Experiments/CornellBox/Passes/DenoisePass.cs Adds temporal and à-trous denoising.
sources/Experiments/CornellBox/Models/Vertex.cs Defines the scene vertex layout.
sources/Experiments/CornellBox/Models/UpscaleMode.cs Defines upscaling modes.
sources/Experiments/CornellBox/Models/PassArgs.cs Adds shared render arguments.
sources/Experiments/CornellBox/Models/Material.cs Defines the material layout.
sources/Experiments/CornellBox/Models/CornellBoxGeometry.cs Defines CornellBox geometry.
sources/Experiments/CornellBox/Handlers/ImGuiHandler.cs Refines input and platform bindings.
sources/Experiments/CornellBox/Handlers/CameraHandler.cs Clarifies input parameters.
sources/Experiments/CornellBox/CornellBox.csproj References the upscaling extension.
sources/Experiments/CornellBox/Assets/Shaders/Tonemap.slang Implements compute tone mapping.
sources/Experiments/CornellBox/Assets/Shaders/Rasterization.slang Removes the obsolete raster shader.
sources/Experiments/CornellBox/Assets/Shaders/PathTracing.slang Adds ray-traced outputs and guides.
sources/Experiments/CornellBox/Assets/Shaders/Denoise.slang Implements temporal and à-trous filtering.
sources/Experiments/CornellBox/App.cs Integrates the new renderer.
sources/Directory.Packages.props Updates ImageSharp to 4.1.2.
Review details

Suppressed comments (3)

sources/Experiments/CornellBox/Assets/Shaders/Denoise.slang:394

  • For background pixels this branch writes Output only when the step is 1. The step-2, step-4, and step-8 ping-pong iterations return without writing their output, so the step-16 resolve reads stale data from the previous frame instead of the current sky color. Copy Input to Output on every iteration, then keep the step-16 resolve.
    if (all(normal.xyz == 0.0))
    {
        // Temporal and the first iteration refresh both ping-pong pixels.
        if (atrous.StepResetCamera.x == 1)
        {

sources/Experiments/CornellBox/Assets/Shaders/PathTracing.slang:323

  • The primary ray query is also advanced only once. Since this query does not use an accept-first-hit flag, a single Proceed() cannot finish traversal and can leave CommittedStatus() unset or select an incomplete hit, breaking primary visibility and all subsequent path shading. Loop until traversal completes.
        query.Proceed();

sources/Experiments/CornellBox/Passes/Pass.cs:40

  • Renderer.Render calls Resize every frame, but this method always invokes ResizeImpl even when all dimensions are unchanged. That recreates the path-tracing, denoise, and upscaler targets on every frame, clearing temporal history and causing per-frame allocation; return early when the four dimensions already match.
    public void Resize(uint renderWidth, uint renderHeight, uint displayWidth, uint displayHeight)
    {
        RenderWidth = renderWidth;
        RenderHeight = renderHeight;
        DisplayWidth = displayWidth;
  • Files reviewed: 46/48 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sources/Experiments/CornellBox/Passes/Pass.cs
Comment thread sources/Experiments/FluidTank/Passes/Pass.cs
Comment thread sources/Experiments/CornellBox/Assets/Shaders/PathTracing.slang
Comment thread sources/Experiments/CornellBox/Renderer.cs Outdated
Comment thread sources/Experiments/FluidTank/Passes/SurfacePass.cs
Renderer.Resize is now called from the UI when the Render Precision slider changes, ensuring explicit resize control. Removed Resize call from Renderer.Render. The local upscaleMode variable in Renderer.Render was eliminated; UpscaleMode property is now used directly.
@qian-o
qian-o merged commit b0dc9a6 into master Sep 15, 2026
2 checks passed
@qian-o
qian-o deleted the exp/upscaling branch September 15, 2026 15:00
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.

2 participants