From c83f02023a4f6bf9224b131eb4ec60a113dab5c9 Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Wed, 13 May 2026 15:45:07 +0000 Subject: [PATCH 1/3] =?UTF-8?q?rtx:=20Drop=20duplicate=20cos=CE=B8=5Flight?= =?UTF-8?q?=20from=20rect/ring=20radiance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devices/rtx/device/gpu/sampleLight.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devices/rtx/device/gpu/sampleLight.h b/devices/rtx/device/gpu/sampleLight.h index 2fe5f501..9de503f0 100644 --- a/devices/rtx/device/gpu/sampleLight.h +++ b/devices/rtx/device/gpu/sampleLight.h @@ -189,8 +189,8 @@ VISRTX_DEVICE LightSample sampleRectLight( // Front only: use cosTheta as-is (positive for front face) if (cosTheta > 0.0f) { - // Lambertian emission: radiance scaled by cosine factor - ls.radiance = ld.color * ld.rect.intensity * cosTheta; + // Lambertian radiance. cosTheta is handled through pdf below. + ls.radiance = ld.color * ld.rect.intensity; // Convert area PDF to solid angle PDF for proper Monte Carlo integration // Area PDF = 1 / area, Solid angle PDF = area_pdf * distance² / |cos θ| @@ -257,8 +257,8 @@ VISRTX_DEVICE LightSample sampleRingLight( if (spot > 0.0f) { if (cosTheta > 0.0f) { - // Apply both spot attenuation and Lambert's cosine law - ls.radiance = ld.color * ld.ring.intensity * spot * cosTheta; + // Lambertian radiance. cosTheta is handled through pdf below. + ls.radiance = ld.color * ld.ring.intensity * spot; // Convert area PDF to solid angle PDF for proper Monte Carlo integration // Ring area = π(R² - r²), so area PDF = 1 / ring_area From 98a9d15dcd2fb0cafd35ea37c6222a96b6c897c8 Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Tue, 19 May 2026 19:31:53 +0000 Subject: [PATCH 2/3] Fix and clean polygon epsilon offsetting, both on shading and shadow Broken by 853b134bc3023c4c9200d89b380bad2b7c8e6a46. --- devices/rtx/device/gpu/gpu_util.h | 16 ++++++++++------ devices/rtx/device/gpu/populateHit.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/devices/rtx/device/gpu/gpu_util.h b/devices/rtx/device/gpu/gpu_util.h index e1b8523f..4ce83a86 100644 --- a/devices/rtx/device/gpu/gpu_util.h +++ b/devices/rtx/device/gpu/gpu_util.h @@ -247,11 +247,15 @@ VISRTX_DEVICE vec3 sampleUnitSphere(RandState &rs, const vec3 &normal) * vec3(sint * cosf(phi), sint * sinf(phi), -cost); } -#define ulpEpsilon 0x1.fp-21 - -VISRTX_DEVICE float epsilonFrom(const vec3 &P) +VISRTX_DEVICE float epsilonFrom(const vec3 &P, const vec3 &dir, float t) { - return glm::compMax(abs(P)) * ulpEpsilon; + constexpr float hitEpsilonScale = 0x1.fp-21f; + constexpr float minHitEpsilon = 1e-8f; + + const float pMag = glm::compMax(glm::abs(P)); + const float dMag = glm::compMax(glm::abs(dir)) * t; + + return fmaxf(glm::max(pMag, dMag) * hitEpsilonScale, minHitEpsilon); } // Hanika's shadow-terminator fix (Ray Tracing Gems II, ch. 4): lifts a @@ -293,8 +297,8 @@ VISRTX_DEVICE vec3 shadingHitpoint(const SurfaceHit &hit) if (tri.vertexNormalsFV == nullptr && tri.vertexNormals == nullptr) return hit.hitpoint; - const uvec3 idx = tri.indices ? tri.indices[hit.primID] - : uvec3(0, 1, 2) + hit.primID * 3; + const uvec3 idx = + tri.indices ? tri.indices[hit.primID] : uvec3(0, 1, 2) + hit.primID * 3; const vec3 v0 = tri.vertices[idx.x]; const vec3 v1 = tri.vertices[idx.y]; const vec3 v2 = tri.vertices[idx.z]; diff --git a/devices/rtx/device/gpu/populateHit.h b/devices/rtx/device/gpu/populateHit.h index c5c649f5..08b4e7d2 100644 --- a/devices/rtx/device/gpu/populateHit.h +++ b/devices/rtx/device/gpu/populateHit.h @@ -401,7 +401,7 @@ VISRTX_DEVICE void populateSurfaceHit(SurfaceHit &hit) hit.primID = ray::primID(); hit.objID = sd.id; hit.instID = isd.id; - hit.epsilon = epsilonFrom(hit.hitpoint); + hit.epsilon = epsilonFrom(ray::hitpoint(), ray::direction(), ray::t()); ray::computeTangentSpace(gd, ray::primID(), hit); const auto &handle = optixGetTransformListHandle(0); From 6720060fdc08acc9850c0827a65f1006c4ab3542 Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Wed, 20 May 2026 13:58:46 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"rtx:=20Rename=20premultiplyBackgr?= =?UTF-8?q?ound=20=E2=86=92=20premultipliedAlpha=20and=20clarify=20semanti?= =?UTF-8?q?cs"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54ce728d44e559342f5283fa320d0444dc56b778. --- devices/rtx/device/frame/Frame.cu | 7 +++--- devices/rtx/device/gpu/gpu_objects.h | 2 +- devices/rtx/device/renderer/Renderer.cpp | 5 ++-- devices/rtx/device/renderer/Renderer.h | 2 +- devices/rtx/device/visrtx_renderer_fast.json | 24 ++++++++++--------- .../device/visrtx_renderer_interactive.json | 24 ++++++++++--------- .../rtx/device/visrtx_renderer_quality.json | 24 ++++++++++--------- 7 files changed, 46 insertions(+), 42 deletions(-) diff --git a/devices/rtx/device/frame/Frame.cu b/devices/rtx/device/frame/Frame.cu index b89db407..8c5ac374 100644 --- a/devices/rtx/device/frame/Frame.cu +++ b/devices/rtx/device/frame/Frame.cu @@ -192,11 +192,10 @@ __global__ void compositeBackground(vec4 *__restrict__ accumColor, vec3 rgb = vec3(rendered); float alpha = rendered.a; - accumulateValue(rgb, vec3(bg) * bg.a, alpha); - accumulateValue(alpha, bg.a, alpha); - if (!renderer.premultipliedAlpha && alpha > 0.0f) - rgb *= 1.0f / alpha; + const bool premultiplyBg = renderer.premultiplyBackground; + accumulateValue(rgb, premultiplyBg ? vec3(bg) * bg.a : vec3(bg), alpha); + accumulateValue(alpha, bg.a, alpha); vec4 rgba = vec4(rgb, alpha); if (format == FrameFormat::SRGB) { diff --git a/devices/rtx/device/gpu/gpu_objects.h b/devices/rtx/device/gpu/gpu_objects.h index 90db9aec..b245b263 100644 --- a/devices/rtx/device/gpu/gpu_objects.h +++ b/devices/rtx/device/gpu/gpu_objects.h @@ -732,7 +732,7 @@ struct RendererGPUData float inverseVolumeSamplingRate; float occlusionDistance; bool cullTriangleBF; - bool premultipliedAlpha; + bool premultiplyBackground; bool fireflyFilter; // enable internal tonemapping during sample accumulation glm::vec4 cutPlane; // cutting plane (nx,ny,nz,d); disabled when all zero (GPU // default) diff --git a/devices/rtx/device/renderer/Renderer.cpp b/devices/rtx/device/renderer/Renderer.cpp index 6e7bba2c..7b87c161 100644 --- a/devices/rtx/device/renderer/Renderer.cpp +++ b/devices/rtx/device/renderer/Renderer.cpp @@ -170,8 +170,7 @@ void Renderer::commitParameters() m_cullTriangleBF = getParam("cullTriangleBackfaces", false); m_volumeSamplingRate = std::clamp(getParam("volumeSamplingRate", 0.125f), 1e-3f, 10.f); - m_premultipliedAlpha = getParam( - "premultipliedAlpha", getParam("premultiplyBackground", false)); + m_premultiplyBackground = getParam("premultiplyBackground", false); m_cutPlane = getParam("cutPlane", vec4(0.f)); if (m_checkerboard) m_spp = 1; @@ -212,7 +211,7 @@ void Renderer::populateFrameData(FrameGPUData &fd) const fd.renderer.fireflyFilter = m_fireflyFilter; fd.renderer.inverseVolumeSamplingRate = 1.f / m_volumeSamplingRate; fd.renderer.numIterations = std::max(m_spp, 1); - fd.renderer.premultipliedAlpha = m_premultipliedAlpha; + fd.renderer.premultiplyBackground = m_premultiplyBackground; fd.renderer.cutPlane = m_cutPlane; } diff --git a/devices/rtx/device/renderer/Renderer.h b/devices/rtx/device/renderer/Renderer.h index 219c2ab4..07ea5188 100644 --- a/devices/rtx/device/renderer/Renderer.h +++ b/devices/rtx/device/renderer/Renderer.h @@ -94,7 +94,7 @@ struct Renderer : public Object true}; // enable internal tonemapping during sample accumulation int m_sampleLimit{0}; bool m_cullTriangleBF{false}; - bool m_premultipliedAlpha{false}; + bool m_premultiplyBackground{false}; float m_volumeSamplingRate{1.f}; vec4 m_cutPlane{0.f}; diff --git a/devices/rtx/device/visrtx_renderer_fast.json b/devices/rtx/device/visrtx_renderer_fast.json index 458942e6..d93c6595 100644 --- a/devices/rtx/device/visrtx_renderer_fast.json +++ b/devices/rtx/device/visrtx_renderer_fast.json @@ -1,18 +1,20 @@ { - "info" : { - "name" : "VISRTX_RENDERER_FAST", - "type" : "extension", - "dependencies" : ["anari_core_1_0"], - "implements" : [ + "info": { + "name": "VISRTX_RENDERER_FAST", + "type": "extension", + "dependencies": [ + "anari_core_1_0" + ], + "implements": [ "khr_renderer_background_color", "khr_renderer_background_image", "khr_renderer_ambient_light" ] }, - "objects" : [ + "objects": [ { - "type" : "ANARI_RENDERER", - "name" : "fast", + "type": "ANARI_RENDERER", + "name": "fast", "parameters": [ { "name": "sampleLimit", @@ -66,13 +68,13 @@ "description": "suppress fireflies via reversible tonemapping before accumulation" }, { - "name": "premultipliedAlpha", + "name": "premultiplyBackground", "types": [ "ANARI_BOOL" ], "tags": [], "default": false, - "description": "pre-multiply RGB by alpha in the composited output pixel" + "description": "pre-multiply alpha channel with background color" }, { "name": "cullTriangleBackfaces", @@ -161,4 +163,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/devices/rtx/device/visrtx_renderer_interactive.json b/devices/rtx/device/visrtx_renderer_interactive.json index e6c53462..8da77121 100644 --- a/devices/rtx/device/visrtx_renderer_interactive.json +++ b/devices/rtx/device/visrtx_renderer_interactive.json @@ -1,18 +1,20 @@ { - "info" : { - "name" : "VISRTX_RENDERER_INTERACTIVE", - "type" : "extension", - "dependencies" : ["anari_core_1_0"], - "implements" : [ + "info": { + "name": "VISRTX_RENDERER_INTERACTIVE", + "type": "extension", + "dependencies": [ + "anari_core_1_0" + ], + "implements": [ "khr_renderer_background_color", "khr_renderer_background_image", "khr_renderer_ambient_light" ] }, - "objects" : [ + "objects": [ { - "type" : "ANARI_RENDERER", - "name" : "interactive", + "type": "ANARI_RENDERER", + "name": "interactive", "parameters": [ { "name": "sampleLimit", @@ -57,13 +59,13 @@ "description": "suppress fireflies via reversible tonemapping before accumulation" }, { - "name": "premultipliedAlpha", + "name": "premultiplyBackground", "types": [ "ANARI_BOOL" ], "tags": [], "default": false, - "description": "pre-multiply RGB by alpha in the composited output pixel" + "description": "pre-multiply alpha channel with background color" }, { "name": "cullTriangleBackfaces", @@ -163,4 +165,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/devices/rtx/device/visrtx_renderer_quality.json b/devices/rtx/device/visrtx_renderer_quality.json index 0d5f27ba..e9db7b26 100644 --- a/devices/rtx/device/visrtx_renderer_quality.json +++ b/devices/rtx/device/visrtx_renderer_quality.json @@ -1,18 +1,20 @@ { - "info" : { - "name" : "VISRTX_RENDERER_QUALITY", - "type" : "extension", - "dependencies" : ["anari_core_1_0"], - "implements" : [ + "info": { + "name": "VISRTX_RENDERER_QUALITY", + "type": "extension", + "dependencies": [ + "anari_core_1_0" + ], + "implements": [ "khr_renderer_background_color", "khr_renderer_background_image", "khr_renderer_ambient_light" ] }, - "objects" : [ + "objects": [ { - "type" : "ANARI_RENDERER", - "name" : "quality", + "type": "ANARI_RENDERER", + "name": "quality", "parameters": [ { "name": "sampleLimit", @@ -57,13 +59,13 @@ "description": "suppress fireflies via reversible tonemapping before accumulation" }, { - "name": "premultipliedAlpha", + "name": "premultiplyBackground", "types": [ "ANARI_BOOL" ], "tags": [], "default": false, - "description": "pre-multiply RGB by alpha in the composited output pixel" + "description": "pre-multiply alpha channel with background color" }, { "name": "cullTriangleBackfaces", @@ -120,4 +122,4 @@ ] } ] -} +} \ No newline at end of file