Refactor renderer implementations#210
Merged
jeffamstutz merged 5 commits intoNVIDIA:next_releasefrom Feb 3, 2026
Merged
Conversation
Helps splitting rendering in two steps: - Saving pixel metadata and center values - Accumulating pixel color, normal...
Refactors renderers (AmbientOcclusion, DirectLight, Raycast) to share a templated renderPixel() function. It handles ray traversal, transparency, and volume integration. Each renderer now implements a simple ShadingPolicy with a shadeSurface() method, eliminating duplicated traversal code. Also standardizes ray types and attenuation helpers in shared headers.
- Add early opacity check in MDL nextRay - Refactor PhysicallyBased shader - Add MDL material registry improvements
Move frameID increment from start of frame to after optixLaunch completes. This ensures numSamples query returns the correct accumulated sample count. Previously frameID was off-by-one: with pixelSamples=1, numSamples would return 0 after first frame instead of 1.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors renderer implementations by consolidating duplicated ray traversal logic into a templated rendering loop in raygen_helpers.h. Each renderer now implements a lightweight ShadingPolicy for surface shading while the common loop handles ray marching, transparency traversal, and volume integration.
Changes:
- Extracted shared rendering loop into template accepting
ShadingPolicyparameter - Standardized ray types across renderers (PRIMARY/SHADOW) and added shared constants
- Separated buffer ID assignment (
setPixelIds) from pixel accumulation (accumPixelSample) - Simplified DirectLight indirect lighting to single-bounce cosine-weighted diffuse
- Added opacity pass-through check to material shaders (MDL, PhysicallyBased)
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
devices/rtx/device/renderer/raygen_helpers.h |
New templated rendering loop with shared ray traversal logic |
devices/rtx/device/renderer/common.h |
New shared constants and standardized RayType enum |
devices/rtx/device/renderer/Raycast_ptx.cu |
Refactored to use templated rendering loop with RaycastShadingPolicy |
devices/rtx/device/renderer/AmbientOcclusion_ptx.cu |
Refactored to use templated rendering loop with AmbientOcclusionShadingPolicy |
devices/rtx/device/renderer/DirectLight_ptx.cu |
Refactored to use templated rendering loop with DirectLightShadingPolicy, simplified indirect lighting |
devices/rtx/device/renderer/Test_ptx.cu |
Updated to use separated setPixelIds and accumPixelSample functions |
devices/rtx/device/renderer/PathTracer_ptx.cu |
Updated to use separated setPixelIds and accumPixelSample functions |
devices/rtx/device/renderer/Debug_ptx.cu |
Updated to use separated setPixelIds and accumPixelSample functions |
devices/rtx/device/renderer/DirectLight.cpp |
Updated hitgroup and miss function names |
devices/rtx/device/renderer/AmbientOcclusion.cpp |
Updated hitgroup function names |
devices/rtx/device/gpu/gpu_util.h |
Split accumResults into setPixelIds and accumPixelSample, added accumulateNormal |
devices/rtx/device/gpu/computeAO.h |
Updated to use function pointer for surface attenuation |
devices/rtx/device/gpu/intersectRay.h |
Removed surfaceAttenuation function (moved to raygen_helpers.h) |
devices/rtx/device/gpu/volumeIntegration.h |
Adjusted depth recording logic for minimum opacity threshold |
devices/rtx/device/material/shaders/PhysicallyBasedShader_ptx.cu |
Added opacity pass-through check to nextRay function |
devices/rtx/device/material/shaders/MDLShader_ptx.cu |
Added opacity pass-through check to nextRay function |
devices/rtx/device/mdl/MaterialRegistry.cpp |
Added validation for PTX target code generation |
devices/rtx/device/frame/Frame.cu |
Moved frameID increment to after rendering completes, changed normal buffer to use normalize |
Comments suppressed due to low confidence (2)
devices/rtx/device/renderer/DirectLight_ptx.cu:1
- Inconsistent indentation in ternary operator. The false branch should align with the true branch for better readability.
/*
devices/rtx/device/renderer/DirectLight_ptx.cu:1
- Inconsistent indentation in ternary operator. The false branch should align with the true branch for better readability.
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
devices/rtx/device/material/shaders/PhysicallyBasedShader_ptx.cu
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
|
LGTM, thanks! |
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.
Consolidates duplicated ray traversal logic across renderers (Raycast, AmbientOcclusion, DirectLight) into a templated rendering loop in gpu/renderer/raygen_helpers.h.
Each renderer now provides a simple ShadingPolicy that implements surface shading, while the common loop handles ray marching, transparency traversal, and volume integration.
Key changes:
PT, Debug and Test renderers are purposefully excluded from this rework as they don't fit into the exposed paradigm.
A quick assessment shows that performances are on par with our previous implementation.