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
7 changes: 3 additions & 4 deletions devices/rtx/device/frame/Frame.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion devices/rtx/device/gpu/gpu_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions devices/rtx/device/gpu/gpu_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion devices/rtx/device/gpu/populateHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions devices/rtx/device/gpu/sampleLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 θ|
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions devices/rtx/device/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ void Renderer::commitParameters()
m_cullTriangleBF = getParam<bool>("cullTriangleBackfaces", false);
m_volumeSamplingRate =
std::clamp(getParam<float>("volumeSamplingRate", 0.125f), 1e-3f, 10.f);
m_premultipliedAlpha = getParam<bool>(
"premultipliedAlpha", getParam<bool>("premultiplyBackground", false));
m_premultiplyBackground = getParam<bool>("premultiplyBackground", false);
m_cutPlane = getParam<vec4>("cutPlane", vec4(0.f));
if (m_checkerboard)
m_spp = 1;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion devices/rtx/device/renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
24 changes: 13 additions & 11 deletions devices/rtx/device/visrtx_renderer_fast.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -161,4 +163,4 @@
]
}
]
}
}
24 changes: 13 additions & 11 deletions devices/rtx/device/visrtx_renderer_interactive.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -163,4 +165,4 @@
]
}
]
}
}
24 changes: 13 additions & 11 deletions devices/rtx/device/visrtx_renderer_quality.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -120,4 +122,4 @@
]
}
]
}
}
Loading