Skip to content

Commit 06129d2

Browse files
absolutely 100% no self intersections
TODO: why is stuff black in ditt.zip
1 parent ab189f2 commit 06129d2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
191191
return scramble_start_state;
192192
}
193193

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-
203194
vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth)
204195
{
205196
uvec3 seqVal = texelFetch(sampleSequence,int(_sample)+(depth-1)*MAX_ACCUMULATED_SAMPLES).xyz;
@@ -269,8 +260,13 @@ for (uint i=1u; i!=vertex_depth; i++)
269260
}
270261
// TODO: investigate workgroup reductions here
271262
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);
274270
// TODO: in the future run backward error analysis of
275271
// dot(mat3(WorldToObj)*(origin+offset*geomNormal/length(geomNormal))+(WorldToObj-vx_pos[1]),geomNormal)
276272
// where
@@ -281,15 +277,17 @@ for (uint i=1u; i!=vertex_depth; i++)
281277
//const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
282278
//float ray_offset = ?;
283279
//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};
286282
uint offset = 0u;
287283
for (uint i=0u; i<maxRaysToGen; i++)
288284
if (maxT[i]!=0.f)
289285
{
290286
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];
293291
newRay.maxT = maxT[i];
294292
newRay.direction = direction[i];
295293
newRay.time = packOutPixelLocation(outPixelLocation);

0 commit comments

Comments
 (0)