Skip to content

Commit ef000ef

Browse files
author
devsh
committed
add a better RWMC=OFF mode, don't try to reuse RWMC code with 2 weird cascades
1 parent a1938f1 commit ef000ef

File tree

5 files changed

+68
-34
lines changed

5 files changed

+68
-34
lines changed

22.RaytracedAO/Renderer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,8 @@ void Renderer::initScreenSizedResources(
12401240
const float RGB19E7_MaxLuma = std::exp2(63.f);
12411241
if (cascadeCount<MinCascades) // rwmc OFF, store everything to cascade 0
12421242
{
1243-
cascadeCount = MinCascades;
1243+
// original idea was to create 2 cascades where the first starts so low that every sample gets added to it. But now we just do 1
1244+
cascadeCount = 0;
12441245
cascadeLuminanceBase = std::exp2(16.f); // just some constant to space the cascades apart
12451246
cascadeLuminanceStart = RGB19E7_MaxLuma;
12461247
std::cout << "Re-Weighting Monte Carlo = DISABLED" << std::endl;
@@ -1249,7 +1250,7 @@ void Renderer::initScreenSizedResources(
12491250
{
12501251
cascadeCount = core::min(cascadeCount,MaxCascades);
12511252
const float cascadeSegmentCount = cascadeCount-1;
1252-
1253+
// base is the power increment between each successive cascade, first cascade starts at Emin or 1/cascadeLuminanceBase^segmentCount scaled to max emitter radiance
12531254
const bool baseIsKnown = cascadeLuminanceBase>std::numeric_limits<float>::min();
12541255
if (core::isnan<float>(cascadeLuminanceStart))
12551256
cascadeLuminanceStart = baseIsKnown ? (maxEmitterRadianceLuma*std::pow(cascadeLuminanceBase,-cascadeSegmentCount)):Emin;

22.RaytracedAO/closestHit.comp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,25 @@ void main()
118118
contrib.color *= throughput;
119119
const vec3 aovThroughput = throughput*aovThroughputScale;
120120
//
121-
const bool pathToBeContinued = bool(rayMask);
122-
if (pathToBeContinued)
123-
addAccumulation(contrib.color,accumulationLocation);
124-
else
121+
if (isRWMCEnabled())
125122
{
126-
// need whole path throughput when splatting
127-
contrib.color += fetchAccumulation(accumulationLocation);
128-
const nbl_glsl_RWMC_SplattingParameters splat = nbl_glsl_RWMC_getCascade(staticViewData.cascadeParams,nbl_glsl_MC_colorToScalar(contrib.color)/pc.cummon.rcpFramesDispatched);
129-
for (uint j=0u; j<2u; j++)
130-
addAccumulationCascade(
131-
contrib.color*splat.cascadeWeights[j],accumulationLocation,
132-
samplesPerPixelPerDispatch,splat.lowerCascade+j
133-
);
123+
const bool pathToBeContinued = bool(rayMask);
124+
if (pathToBeContinued)
125+
addAccumulation(contrib.color,accumulationLocation);
126+
else
127+
{
128+
// need whole path throughput when splatting
129+
contrib.color += fetchAccumulation(accumulationLocation);
130+
const nbl_glsl_RWMC_SplattingParameters splat = nbl_glsl_RWMC_getCascade(staticViewData.cascadeParams,nbl_glsl_MC_colorToScalar(contrib.color)/pc.cummon.rcpFramesDispatched);
131+
for (uint j=0u; j<2u; j++)
132+
addAccumulationCascade(
133+
contrib.color*splat.cascadeWeights[j],accumulationLocation,
134+
samplesPerPixelPerDispatch,splat.lowerCascade+j
135+
);
136+
}
134137
}
138+
else
139+
addAccumulation(contrib.color,accumulationLocation);
135140
//
136141
addAlbedo(contrib.albedo*aovThroughput,accumulationLocation);
137142
addWorldspaceNormal(contrib.worldspaceNormal*nbl_glsl_MC_colorToScalar(aovThroughput),accumulationLocation);

22.RaytracedAO/raygen.comp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,52 @@ void main()
130130
{
131131
const uvec3 coord = uvec3(outPixelLocation,i);
132132

133-
nbl_glsl_RWMC_SplattingParameters splat = nbl_glsl_RWMC_getCascade(staticViewData.cascadeParams,luma);
134-
const bool pathToBeContinued = bool((rayMask>>i)&0x1u);
135-
if (pathToBeContinued)
133+
if (isRWMCEnabled())
136134
{
137-
storeAccumulation(contrib.color*pc.cummon.rcpFramesDispatched,coord);
138-
splat.cascadeWeights = vec2(0.f,0.f);
139-
}
140-
const uint higherCascade = splat.lowerCascade+1u;
141-
const uint cascadeCount = staticViewData.cascadeParams.penultimateCascadeIx+2u;
142-
for (uint cascadeIx=0u; cascadeIx<cascadeCount; cascadeIx++)
143-
{
144-
float weight = 0.f;
145-
if (cascadeIx==splat.lowerCascade)
146-
weight = splat.cascadeWeights[0];
147-
else if (cascadeIx==higherCascade)
148-
weight = splat.cascadeWeights[1];
149-
nextSampleAccumulationCascade(
150-
contrib.color*weight,coord,samplesPerPixelPerDispatch,
151-
cascadeIx,pc.cummon.rcpFramesDispatched
152-
);
135+
nbl_glsl_RWMC_SplattingParameters splat = nbl_glsl_RWMC_getCascade(staticViewData.cascadeParams,luma);
136+
137+
// ray out of ray-payload, using first layer of accumulation texture to store emissive along path so far
138+
const bool pathToBeContinued = bool((rayMask>>i)&0x1u);
139+
if (pathToBeContinued)
140+
{
141+
storeAccumulation(contrib.color*pc.cummon.rcpFramesDispatched,coord);
142+
splat.cascadeWeights = vec2(0.f,0.f);
143+
}
144+
145+
const uint higherCascade = splat.lowerCascade+1u;
146+
const uint cascadeCount = staticViewData.cascadeParams.penultimateCascadeIx+2u;
147+
for (uint cascadeIx=0u; cascadeIx<cascadeCount; cascadeIx++)
148+
{
149+
float weight = 0.f;
150+
if (cascadeIx==splat.lowerCascade)
151+
weight = splat.cascadeWeights[0];
152+
else if (cascadeIx==higherCascade)
153+
weight = splat.cascadeWeights[1];
154+
nextSampleAccumulationCascade(
155+
contrib.color*weight,coord,samplesPerPixelPerDispatch,
156+
cascadeIx,pc.cummon.rcpFramesDispatched
157+
);
158+
}
153159
}
154160

155161
const bool hideEnvmap = bool(staticViewData.sampleSequenceStride_hideEnvmap>>31);
156162
// clear accumulations totally if beginning a new frame
157163
if (firstFrame)
158164
{
165+
storeAccumulation(contrib.color,coord);
159166
storeAlbedo(contrib.albedo,coord);
160167
storeWorldspaceNormal(contrib.worldspaceNormal,coord);
161168
storeMask(hideEnvmap&&(!hit) ? 1.f:0.f,coord);
162169
}
163170
else
164171
{
172+
if (!isRWMCEnabled())
173+
{
174+
const vec3 prev = fetchAccumulation(coord);
175+
const vec3 delta = (contrib.color-prev)*pc.cummon.rcpFramesDispatched;
176+
if (any(greaterThan(delta,vec3(exp2(-19.f)))))
177+
storeAccumulation(prev+delta,coord);
178+
}
165179
addAlbedo(contrib.albedo,coord,pc.cummon.rcpFramesDispatched);
166180
addWorldspaceNormal(contrib.worldspaceNormal,coord,pc.cummon.rcpFramesDispatched);
167181
if (hideEnvmap)

22.RaytracedAO/raytraceCommon.glsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ uvec3 get_triangle_indices(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchI
7474
#include <nbl/builtin/glsl/format/decode.glsl>
7575
#include <nbl/builtin/glsl/format/encode.glsl>
7676

77+
bool isRWMCEnabled()
78+
{
79+
return staticViewData.cascadeParams.penultimateCascadeIx!=uint(-2);
80+
}
81+
7782
vec3 fetchAccumulation(in uvec3 coord)
7883
{
7984
const uvec2 data = imageLoad(accumulation,ivec3(coord)).rg;

22.RaytracedAO/resolve.comp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ vec3 nbl_glsl_RWMC_sampleCascadeTexel(ivec2 coord, in ivec2 offset, in uint casc
6161
return value/float(samplesPerPixelPerDispatch);
6262
}
6363

64+
bool isRWMCEnabled()
65+
{
66+
return staticViewData.cascadeParams.penultimateCascadeIx!=uint(-2);
67+
}
6468

6569
void main()
6670
{
@@ -69,7 +73,12 @@ void main()
6973
{
7074
samplesPerPixelPerDispatch = bitfieldExtract(staticViewData.maxPathDepth_noRussianRouletteDepth_samplesPerPixelPerDispatch,16,16);
7175

72-
vec3 acc = nbl_glsl_RWMC_reweight(pc.rwmcReweightingParams,pixelCoord);
76+
vec3 acc;
77+
if (isRWMCEnabled())
78+
acc = nbl_glsl_RWMC_reweight(pc.rwmcReweightingParams,pixelCoord);
79+
else // its a pretty ok function, reusing it
80+
acc = nbl_glsl_RWMC_sampleCascadeTexel(pixelCoord,ivec2(0,0),-1);
81+
7382
vec3 alb = texelFetch(albedoSamples,ivec3(pixelCoord,0),0).rgb;
7483
vec3 nml = nbl_glsl_decodeRGB10A2_SNORM(texelFetch(normalSamples,ivec3(pixelCoord,0),0).r).xyz;
7584
float msk = texelFetch(maskSamples,ivec3(pixelCoord,0),0).r;

0 commit comments

Comments
 (0)