@@ -88,7 +88,7 @@ bool record_emission_common(out vec3 acc, in uvec3 accumulationLocation, vec3 em
88
88
emissive -= acc;
89
89
emissive *= pc.cummon.rcpFramesDispatched;
90
90
91
- const bool anyChange = any (greaterThan (abs (emissive),vec3 (FLT_MIN )));
91
+ const bool anyChange = any (greaterThan (abs (emissive),vec3 (nbl_glsl_FLT_MIN )));
92
92
acc += emissive;
93
93
return anyChange;
94
94
}
@@ -118,6 +118,29 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
118
118
return normalizedN;
119
119
}
120
120
121
+
122
+
123
+
124
+ vec3 nbl_glsl_robust_ray_origin_fastest(in vec3 origin, in vec3 direction, float error, vec3 normal)
125
+ {
126
+ // flip it in the correct direction
127
+ error = uintBitsToFloat(floatBitsToUint(error)^ (floatBitsToUint(dot (normal,direction))& 0x80000000u));
128
+ return origin+ normal* error;
129
+ }
130
+ vec3 nbl_glsl_robust_ray_origin_fast(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
131
+ {
132
+ // anticipate that the error could have increased from manipulation
133
+ return nbl_glsl_robust_ray_origin_fastest(origin,direction,error.x+ error.y+ error.z,normal);
134
+ }
135
+ vec3 nbl_glsl_robust_ray_origin(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
136
+ {
137
+ const float d = dot (abs (normal),error);
138
+ // anticipate that the error could have increased from manipulation
139
+ return nbl_glsl_robust_ray_origin_fastest(origin,direction,d,normal);
140
+ }
141
+
142
+
143
+
121
144
#include < nbl/ builtin/ glsl/ barycentric/ utils.glsl>
122
145
mat2x3 dPdBary;
123
146
vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
@@ -128,7 +151,11 @@ vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_da
128
151
nbl_glsl_fetchVtxPos(indices[2 ],batchInstanceData)
129
152
);
130
153
const mat4x3 tform = batchInstanceData.tform;
131
- positions = mat3 (tform)* positions;
154
+ mat3 error;
155
+ // for when we quantize positions to RGB21_UNORM
156
+ // const float quantizationError = nbl_glsl_numeric_limits_float_epsilon(1u);
157
+ positions = nbl_glsl_mul_with_bounds(error,mat3 (tform),positions/* ,positions*quantizationError*/ );
158
+ //
132
159
dPdBary = mat2x3 (positions[0 ]- positions[2 ],positions[1 ]- positions[2 ]);
133
160
return positions[2 ]+ tform[3 ];
134
161
}
@@ -160,7 +187,7 @@ void gen_sample_ray(
160
187
in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
161
188
)
162
189
{
163
- maxT = FLT_MAX ;
190
+ maxT = nbl_glsl_FLT_MAX ;
164
191
165
192
vec3 rand = rand3d(scramble_state,int (sampleID),int (depth));
166
193
@@ -254,24 +281,22 @@ for (uint i=1u; i!=vertex_depth; i++)
254
281
// if (i==0u)
255
282
// imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
256
283
nextThroughput[i] *= prevThroughput;
257
- if (any (greaterThan (nextThroughput[i],vec3 (FLT_MIN ))))
284
+ if (any (greaterThan (nextThroughput[i],vec3 (nbl_glsl_FLT_MIN ))))
258
285
raysToAllocate++ ;
259
286
else
260
287
maxT[i] = 0 .f;
261
288
}
262
289
// TODO: investigate workgroup reductions here
263
290
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
264
291
265
- // TODO: improve ray offset (maybe using smooth normal wouldn't be a sin)
266
- vec3 geomNormal = cross (dPdBary[0 ],dPdBary[1 ]);
267
- const vec3 absGeomNormal = abs (geomNormal);
268
- geomNormal /= max (max (absGeomNormal.x,absGeomNormal.y),max (absGeomNormal.z,0 .001f))* 64 .f;
292
+ // TODO: improve
293
+ const vec3 error = vec3 (0 .0001f);// abs(origin)* uintBitsToFloat(0x35480005);
269
294
uint offset = 0u;
270
295
for (uint i= 0u; i< maxRaysToGen; i++ )
271
296
if (maxT[i]!= 0 .f)
272
297
{
273
298
nbl_glsl_ext_RadeonRays_ray newRay;
274
- newRay.origin = origin+ uintBitsToFloat(floatBitsToUint(geomNormal) ^ floatBitsToUint( dot (geomNormal , direction[i])) & 0x80000000u );
299
+ newRay.origin = origin+ direction[i] * 0.002 ; // nbl_glsl_robust_ray_origin(origin , direction[i], error, normalizedN );
275
300
newRay.maxT = maxT[i];
276
301
newRay.direction = direction[i];
277
302
newRay.time = packOutPixelLocation(outPixelLocation);
0 commit comments