@@ -191,15 +191,6 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
191
191
return scramble_start_state;
192
192
}
193
193
194
- // robust ray origins
195
- vec3 nbl_glsl_robust_ray_origin_impl(in vec3 origin, in vec3 direction, float offset, vec3 normal)
196
- {
197
- // flip it in the correct direction
198
- offset = uintBitsToFloat(floatBitsToUint(offset)^ (floatBitsToUint(dot (normal,direction))& 0x80000000u));
199
- return origin+ normal* offset;
200
- }
201
-
202
-
203
194
vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth)
204
195
{
205
196
uvec3 seqVal = texelFetch(sampleSequence,int (_sample)+ (depth- 1 )* MAX_ACCUMULATED_SAMPLES).xyz;
@@ -269,8 +260,13 @@ for (uint i=1u; i!=vertex_depth; i++)
269
260
}
270
261
// TODO: investigate workgroup reductions here
271
262
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
272
-
273
- float ray_offset = dot (abs (normalizedN),abs (origin))* nbl_glsl_numeric_limits_float_epsilon(9u)* 1 .03f+ nbl_glsl_numeric_limits_float_epsilon(20u); // I pulled the constants out of my @$$
263
+
264
+ // the 1.03125f adjusts for the fact that the normal might be too short (inversesqrt precision)
265
+ const float inversesqrt_precision = 1 .03125f;
266
+ // TODO: investigate why we can't use `normalizedN` here
267
+ const vec3 ray_offset_vector = normalize (cross (dPdBary[0 ],dPdBary[1 ]))* inversesqrt_precision;
268
+ float origin_offset = nbl_glsl_numeric_limits_float_epsilon(44u); // I pulled the constants out of my @$$
269
+ origin_offset += dot (abs (ray_offset_vector),abs (origin))* nbl_glsl_numeric_limits_float_epsilon(24u);
274
270
// TODO: in the future run backward error analysis of
275
271
// dot(mat3(WorldToObj)*(origin+offset*geomNormal/length(geomNormal))+(WorldToObj-vx_pos[1]),geomNormal)
276
272
// where
@@ -281,15 +277,17 @@ for (uint i=1u; i!=vertex_depth; i++)
281
277
// const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
282
278
// float ray_offset = ?;
283
279
// ray_offset = nbl_glsl_ieee754_next_ulp_away_from_zero(ray_offset);
284
- // adjust for the fact that the normal might be too short (inversesqrt precision)
285
- ray_offset *= 1 .03125f ;
280
+ const vec3 ray_offset = ray_offset_vector * origin_offset;
281
+ const vec3 ray_origin[ 2 ] = {origin + ray_offset,origin - ray_offset} ;
286
282
uint offset = 0u;
287
283
for (uint i= 0u; i< maxRaysToGen; i++ )
288
284
if (maxT[i]!= 0 .f)
289
285
{
290
286
nbl_glsl_ext_RadeonRays_ray newRay;
291
- newRay.origin = nbl_glsl_robust_ray_origin_impl(origin,direction[i],ray_offset,normalizedN);
292
- // newRay.origin = nbl_glsl_robust_ray_origin_impl(origin,direction[i],ray_offset,geomNormal);
287
+ if (dot (ray_offset_vector,direction[i])< 0 .f)
288
+ newRay.origin = ray_origin[1 ];
289
+ else
290
+ newRay.origin = ray_origin[0 ];
293
291
newRay.maxT = maxT[i];
294
292
newRay.direction = direction[i];
295
293
newRay.time = packOutPixelLocation(outPixelLocation);
0 commit comments