Skip to content

Refactor renderer implementations#210

Merged
jeffamstutz merged 5 commits intoNVIDIA:next_releasefrom
tarcila:renderer-factorization
Feb 3, 2026
Merged

Refactor renderer implementations#210
jeffamstutz merged 5 commits intoNVIDIA:next_releasefrom
tarcila:renderer-factorization

Conversation

@tarcila
Copy link
Collaborator

@tarcila tarcila commented Feb 2, 2026

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:

  • Extract shared rendering loop into template accepting ShadingPolicy
  • Standardize ray types across renderers (PRIMARY/SHADOW)
  • Separate buffer ID assignment (setPixelIds) from pixel accumulation (accumPixelSample)
  • Fix frameID sample count discrepancy by incrementing after render completes
  • Simplify DirectLight indirect lighting to single-bounce cosine-weighted diffuse
  • Add shared constants (OPACITY_THRESHOLD, MIN_CONTRIBUTION_EPSILON)
  • Add opacity pass-through check to material shaders (MDL, PhysicallyBased)

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.

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.
@tarcila tarcila requested a review from Copilot February 2, 2026 22:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ShadingPolicy parameter
  • 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tarcila tarcila requested a review from jeffamstutz February 2, 2026 23:21
@jeffamstutz
Copy link
Collaborator

LGTM, thanks!

@jeffamstutz jeffamstutz merged commit 2d07a64 into NVIDIA:next_release Feb 3, 2026
13 checks passed
@tarcila tarcila deleted the renderer-factorization branch February 3, 2026 00:27
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