Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions devices/rtx/device/frame/Frame.cu
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ void Frame::renderFrame()
1));
instrument::rangePop(); // optixLaunch()

// Increment frameID after rendering completes
if (checkerboarding())
hd.fb.frameID += int(hd.fb.checkerboardID == 3);
else
hd.fb.frameID += m_renderer->spp();

if (m_denoise)
m_denoiser.launch();

Expand Down Expand Up @@ -567,14 +573,13 @@ void *Frame::mapAlbedoBuffer(bool gpu)
void *Frame::mapNormalBuffer(bool gpu)
{
auto &state = *deviceState();
const float invFrameID = m_invFrameID;
auto begin = thrust::device_pointer_cast<vec3>((vec3 *)m_accumNormal.ptr());
auto end = begin + numPixels();
thrust::transform(thrust::cuda::par.on(state.stream),
begin,
end,
thrust::device_pointer_cast<vec3>(m_normalBuffer.dataDevice()),
[=] __device__(const vec3 &in) { return in * invFrameID; });
[=] __device__(const vec3 &in) { return normalize(in); });
if (gpu)
return m_normalBuffer.dataDevice();
else {
Expand Down Expand Up @@ -683,10 +688,6 @@ void Frame::newFrame()
vec3(0.0f));
}
} else {
if (checkerboarding())
hd.fb.frameID += int(hd.fb.checkerboardID == 3);
else
hd.fb.frameID += m_renderer->spp();
hd.fb.checkerboardID =
checkerboarding() ? ((hd.fb.checkerboardID + 1) & 0x3) : -1;
}
Expand Down
7 changes: 3 additions & 4 deletions devices/rtx/device/gpu/computeAO.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@

namespace visrtx {

template <typename T>
VISRTX_DEVICE float computeAO(ScreenSample &ss,
const Ray &primaryRay,
T rayType,
const Hit &currentHit,
float dist,
int numSamples)
int numSamples,
float (*surfaceAttenuation)(ScreenSample &, const Ray&))
{
float weights = 0.0f;
float hits = 0.0f;
Expand All @@ -55,7 +54,7 @@ VISRTX_DEVICE float computeAO(ScreenSample &ss,
float weight = max(0.f, dot(aoRay.dir, currentHit.Ns));
if (weight > 1e-8f) {
weights += weight;
hits += weight * surfaceAttenuation(ss, aoRay, rayType);
hits += weight * surfaceAttenuation(ss, aoRay);
}
}

Expand Down
74 changes: 48 additions & 26 deletions devices/rtx/device/gpu/gpu_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ VISRTX_DEVICE void accumulateValue(T &a, const T &b, float interp)
a += b * (1.f - interp);
}

template <typename T>
VISRTX_DEVICE void accumulateNormal(T &a, const T &b, float interp)
{
accumulateValue(a, b, interp);
}

namespace detail {

VISRTX_DEVICE void packPointer(void *ptr, uint32_t &i0, uint32_t &i1)
Expand Down Expand Up @@ -372,10 +378,8 @@ VISRTX_DEVICE uint32_t pixelIndex(
return pixel.x + pixel.y * fb.size.x;
}

VISRTX_DEVICE void writeOutputColor(const FramebufferGPUData &fb,
const vec4 &color,
const uint32_t idx,
const int frameIDOffset)
VISRTX_DEVICE void writeOutputColor(
const FramebufferGPUData &fb, const vec4 &color, const uint32_t idx)
{
if (fb.format == FrameFormat::SRGB) {
fb.buffers.outColorUint[idx] =
Expand All @@ -388,16 +392,45 @@ VISRTX_DEVICE void writeOutputColor(const FramebufferGPUData &fb,

} // namespace detail

VISRTX_DEVICE void setPixelIds(const FramebufferGPUData &fb,
const uvec2 &pixel,
uint32_t primID,
uint32_t objID,
uint32_t instID)
{
const uint32_t idx = detail::pixelIndex(fb, pixel);

if (fb.buffers.primID)
fb.buffers.primID[idx] = primID;
if (fb.buffers.objID)
fb.buffers.objID[idx] = objID;
if (fb.buffers.instID)
fb.buffers.instID[idx] = instID;
}

VISRTX_DEVICE void setPixelIds(const FramebufferGPUData &fb,
const uvec2 &pixel,
const float depth,
uint32_t primID,
uint32_t objID,
uint32_t instID)
{
const uint32_t idx = detail::pixelIndex(fb, pixel);
if (detail::accumDepth(fb.buffers.depth, idx, depth)) {
if (fb.buffers.primID)
fb.buffers.primID[idx] = primID;
if (fb.buffers.objID)
fb.buffers.objID[idx] = objID;
if (fb.buffers.instID)
fb.buffers.instID[idx] = instID;
}
}

VISRTX_DEVICE void accumResults(const FrameGPUData &frame,
VISRTX_DEVICE void accumPixelSample(const FrameGPUData &frame,
const uvec2 &pixel,
const vec4 &color,
float depth,
const vec3 &albedo,
const vec3 &normal,
uint32_t primID,
uint32_t objID,
uint32_t instID,
const int frameIDOffset = 0)
{
const auto &fb = frame.fb;
Expand All @@ -406,21 +439,13 @@ VISRTX_DEVICE void accumResults(const FrameGPUData &frame,

// Conditionally apply tonemapping during accumulation
if (frame.renderer.tonemap)
detail::accumValue(fb.buffers.colorAccumulation, idx, detail::tonemap(color));
detail::accumValue(
fb.buffers.colorAccumulation, idx, detail::tonemap(color));
else
detail::accumValue(fb.buffers.colorAccumulation, idx, color);
detail::accumValue(fb.buffers.albedo, idx, albedo);
detail::accumValue(fb.buffers.normal, idx, normal);

if (detail::accumDepth(fb.buffers.depth, idx, depth)) {
if (fb.buffers.primID)
fb.buffers.primID[idx] = primID;
if (fb.buffers.objID)
fb.buffers.objID[idx] = objID;
if (fb.buffers.instID)
fb.buffers.instID[idx] = instID;
}

const auto accumColor = fb.buffers.colorAccumulation[idx];
// Conditionally apply inverse tonemapping on output
const float frameDivisor = float(fb.frameID + frameIDOffset + 1);
Expand All @@ -429,25 +454,22 @@ VISRTX_DEVICE void accumResults(const FrameGPUData &frame,
? detail::inverseTonemap(normalizedColor)
: normalizedColor;

detail::writeOutputColor(fb, outputColor, idx, frameIDOffset);
detail::writeOutputColor(fb, outputColor, idx);

if (fb.checkerboardID == 0 && frameID == 0) {
auto adjPix = uvec2(pixel.x + 1, pixel.y + 0);
if (!pixelOutOfFrame(adjPix, fb)) {
detail::writeOutputColor(
fb, outputColor, detail::pixelIndex(fb, adjPix), frameIDOffset);
detail::writeOutputColor(fb, outputColor, detail::pixelIndex(fb, adjPix));
}

adjPix = uvec2(pixel.x + 0, pixel.y + 1);
if (!pixelOutOfFrame(adjPix, fb)) {
detail::writeOutputColor(
fb, outputColor, detail::pixelIndex(fb, adjPix), frameIDOffset);
detail::writeOutputColor(fb, outputColor, detail::pixelIndex(fb, adjPix));
}

adjPix = uvec2(pixel.x + 1, pixel.y + 1);
if (!pixelOutOfFrame(adjPix, fb)) {
detail::writeOutputColor(
fb, outputColor, detail::pixelIndex(fb, adjPix), frameIDOffset);
detail::writeOutputColor(fb, outputColor, detail::pixelIndex(fb, adjPix));
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions devices/rtx/device/gpu/intersectRay.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,4 @@ VISRTX_DEVICE void intersectVolume(ScreenSample &ss,
detail::launchRay(ss, r, rayType, false, dataPtr, optixFlags);
}

template <typename T>
VISRTX_DEVICE float surfaceAttenuation(ScreenSample &ss, Ray r, T rayType)
{
float a = 0.f;
intersectSurface(ss, r, rayType, &a, OPTIX_RAY_FLAG_DISABLE_CLOSESTHIT);
return a;
}

} // namespace visrtx
52 changes: 52 additions & 0 deletions devices/rtx/device/gpu/renderer/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

// Common constants and types used across multiple renderers

namespace visrtx {

// Threshold for considering a surface fully opaque
constexpr float OPACITY_THRESHOLD = 0.99f;

// Minimum contribution weight to continue tracing
constexpr float MIN_CONTRIBUTION_EPSILON = 1.0e-8f;

// Standard ray types used across all renderers
// All renderers should use these standard types for consistency
enum class RayType
{
PRIMARY = 0, // Primary/shading rays
SHADOW = 1, // Shadow/occlusion rays (used for light visibility, AO, etc.)
};

} // namespace visrtx
Loading