Add CornellBox denoising and upscaling and refactor rendering passes - #35
Merged
Merged
Conversation
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.
…ight and variance calculations
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.
…eter management and clarity
…improved texture management
…roved flexibility and consistency
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.
…disposal methods for consistency
…implify shader handling
…rity and remove unused properties
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.
Contributor
There was a problem hiding this comment.
🟡 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
Outputonly 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. CopyInputtoOutputon 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 leaveCommittedStatus()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.RendercallsResizeevery frame, but this method always invokesResizeImpleven 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.
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.
…ve unused properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.