@@ -79,8 +79,10 @@ void storeAccumulation(in vec3 color, in uvec3 coord)
7979}
8080void storeAccumulation(in vec3 prev, in vec3 delta, in uvec3 coord)
8181{
82- if (any (greaterThan (abs (delta),vec3 (nbl_glsl_FLT_MIN* 16 .f))))
83- storeAccumulation(prev+ delta,coord);
82+ const vec3 newVal = prev+ delta;
83+ const uvec3 diff = floatBitsToUint(newVal)^ floatBitsToUint(prev);
84+ if (bool ((diff.x| diff.y| diff.z)& 0x7ffffff0u))
85+ storeAccumulation(newVal,coord);
8486}
8587
8688vec3 fetchAlbedo(in uvec3 coord)
@@ -152,7 +154,7 @@ bool has_world_transform(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchIns
152154
153155#include < nbl/ builtin/ glsl/ barycentric/ utils.glsl>
154156mat2x3 dPdBary;
155- vec3 load_positions(out vec3 geomDenormal , in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uvec3 indices)
157+ vec3 load_positions(out vec3 geomNormal , in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uvec3 indices)
156158{
157159 mat3 positions = mat3 (
158160 nbl_glsl_fetchVtxPos(indices[0 ],batchInstanceData),
@@ -165,7 +167,7 @@ vec3 load_positions(out vec3 geomDenormal, in nbl_glsl_ext_Mitsuba_Loader_instan
165167 //
166168 for (int i= 0 ; i< 2 ; i++ )
167169 dPdBary[i] = positions[i]- positions[2 ];
168- geomDenormal = cross (dPdBary[0 ],dPdBary[1 ]);
170+ geomNormal = normalize ( cross (dPdBary[0 ],dPdBary[1 ]) );
169171 //
170172 if (tform)
171173 positions[2 ] += batchInstanceData.tform[3 ];
@@ -194,7 +196,7 @@ bool needs_texture_prefetch(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batch
194196
195197vec3 load_normal_and_prefetch_textures(
196198 in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
197- in uvec3 indices, in vec2 compactBary, in vec3 geomDenormal ,
199+ in uvec3 indices, in vec2 compactBary, in vec3 geomNormal ,
198200 in nbl_glsl_MC_oriented_material_t material
199201#ifdef TEX_PREFETCH_STREAM
200202 ,in mat2 dBarydScreen
@@ -222,7 +224,6 @@ vec3 load_normal_and_prefetch_textures(
222224 // the rest is always only needed for continuing rays
223225
224226
225- vec3 normal = geomDenormal;
226227 // while waiting for the scramble state
227228 // TODO: optimize, add loads more flags to control this
228229 const bool needsSmoothNormals = true;
@@ -235,18 +236,20 @@ vec3 load_normal_and_prefetch_textures(
235236 );
236237
237238 // not needed for NEE unless doing Area or Projected Solid Angle Sampling
238- const vec3 smoothNormal = normals* nbl_glsl_barycentric_expand(compactBary);
239- // TODO: first check wouldn't be needed if we had `needsSmoothNormals` implemented
240- if (! isnan(smoothNormal.x) && has_world_transform(batchInstanceData))
239+ vec3 smoothNormal = normals* nbl_glsl_barycentric_expand(compactBary);
240+ if (has_world_transform(batchInstanceData))
241241 {
242- normal = vec3 (
242+ smoothNormal = vec3 (
243243 dot (batchInstanceData.normalMatrixRow0,smoothNormal),
244244 dot (batchInstanceData.normalMatrixRow1,smoothNormal),
245245 dot (batchInstanceData.normalMatrixRow2,smoothNormal)
246246 );
247247 }
248+ // TODO: this check wouldn't be needed if we had `needsSmoothNormals` implemented
249+ if (! isnan(smoothNormal.x))
250+ return normalize (smoothNormal);
248251 }
249- return normalize (normal) ;
252+ return geomNormal ;
250253}
251254
252255#include < nbl/ builtin/ glsl/ sampling/ quantized_sequence.glsl>
@@ -324,8 +327,8 @@ void generate_next_rays(
324327 worldspaceNormal += result.aov.normal/ float (maxRaysToGen);
325328
326329 nextThroughput[i] = prevThroughput* result.quotient;
327- // do denormalized half floats flush to 0 ?
328- if (max (max (nextThroughput[i].x,nextThroughput[i].y),nextThroughput[i].z)>= exp2 (- 14 .f))
330+ // TODO: add some sort of factor to this inequality that could account for highest possible emission (direct or indirect) we could encounter
331+ if (max (max (nextThroughput[i].x,nextThroughput[i].y),nextThroughput[i].z)> exp2 (- 19 .f)) // match output mantissa (won't contribute anything afterwards )
329332 {
330333 maxT[i] = nbl_glsl_FLT_MAX;
331334 nextAoVThroughputScale[i] = prevAoVThroughputScale* result.aov.throughputFactor;
@@ -392,11 +395,11 @@ vec2 SampleSphericalMap(vec3 v)
392395 return uv;
393396}
394397
395- void Contribution_initMiss(out Contribution contrib)
398+ void Contribution_initMiss(out Contribution contrib, in float aovThroughputScale )
396399{
397400 vec2 uv = SampleSphericalMap(- normalizedV);
398401 // funny little trick borrowed from things like Progressive Photon Mapping
399- const float bias = 0.25 * sqrt ( pc.cummon.rcpFramesDispatched);
402+ const float bias = 0 .0625f * ( 1 .f - aovThroughputScale) * pow ( pc.cummon.rcpFramesDispatched, 0 .08f );
400403 contrib.albedo = contrib.color = textureGrad(envMap, uv, vec2 (bias* 0.5 ,0 .f), vec2 (0 .f,bias)).rgb;
401404 contrib.worldspaceNormal = normalizedV;
402405}
0 commit comments