@@ -129,20 +129,18 @@ vec3 load_positions(out mat2x3 dPdBary_error, out vec3 lastVxPos_error,in uvec3
129
129
);
130
130
const mat4x3 tform = batchInstanceData.tform;
131
131
mat3 positions_error;
132
- // for when we quantize positions to RGB21_UNORM
133
- const float quantizationError = exp2 ( - 16 .f); // nbl_glsl_numeric_limits_float_epsilon(1u);
132
+ // when we quantize positions to RGB21_UNORM, change to exp2(-22.f)
133
+ const float quantizationError = nbl_glsl_numeric_limits_float_epsilon(1u);
134
134
positions = nbl_glsl_mul_with_bounds_wo_gamma(positions_error,mat3 (tform),positions,quantizationError);
135
+ positions_error *= nbl_glsl_ieee754_gamma(2u);
135
136
//
136
- const float accum_error_factor = nbl_glsl_ieee754_gamma(2u)+ nbl_glsl_ieee754_gamma(3u);
137
137
for (int i= 0 ; i< 2 ; i++ )
138
138
{
139
- dPdBary[i] = positions[i]- positions[2 ];
140
- dPdBary_error[i] = abs (dPdBary[i])* nbl_glsl_ieee754_gamma(1u);
141
- dPdBary_error[i] += (positions_error[i]+ positions_error[2 ])* accum_error_factor;
139
+ dPdBary[i] = nbl_glsl_ieee754_sub_with_bounds_wo_gamma(dPdBary_error[i],positions[i],positions_error[i],positions[2 ],positions_error[2 ]);
140
+ dPdBary_error[i] *= nbl_glsl_ieee754_gamma(1u);
142
141
}
143
- const vec3 lastVx = positions[2 ]+ tform[3 ];
144
- lastVxPos_error = abs (positions[2 ])* quantizationError;
145
- lastVxPos_error += (abs (lastVx)+ lastVxPos_error[2 ])* nbl_glsl_ieee754_gamma(1u);
142
+ const vec3 lastVx = nbl_glsl_ieee754_add_with_bounds_wo_gamma(lastVxPos_error,positions[2 ],positions_error[2 ],tform[3 ],vec3 (0 .f));
143
+ lastVxPos_error *= nbl_glsl_ieee754_gamma(1u);
146
144
return lastVx;
147
145
}
148
146
@@ -207,27 +205,30 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
207
205
}
208
206
209
207
// TODO MOVE to some other header!
210
- vec3 nbl_glsl_interpolate_with_bounds(out vec3 error, in mat2x3 triangleEdges, in mat2x3 triangleEdges_error, in vec3 origin, in vec3 origin_error, in vec2 compactBary)
208
+ vec3 nbl_glsl_interpolate_with_bounds(out vec3 error, in mat2x3 triangleEdges, in mat2x3 triangleEdges_error,
209
+ in vec3 origin, in vec3 origin_error, in vec2 compactBary, in float compactBary_error
210
+ )
211
211
{
212
- return triangleEdges* compactBary+ origin;
212
+ vec3 error1;
213
+ const vec3 col1 = nbl_glsl_ieee754_mul_with_bounds_wo_gamma(error1,triangleEdges[0 ],triangleEdges_error[0 ],compactBary.x,compactBary_error);
214
+ error1 *= nbl_glsl_ieee754_gamma(1u);
215
+ vec3 error2;
216
+ const vec3 col2 = nbl_glsl_ieee754_mul_with_bounds_wo_gamma(error2,triangleEdges[1 ],triangleEdges_error[1 ],compactBary.y,compactBary_error);
217
+ error2 *= nbl_glsl_ieee754_gamma(1u);
218
+ vec3 error3;
219
+ vec3 retval = nbl_glsl_ieee754_add_with_bounds_wo_gamma(error3,col1,error1,col2,error2);
220
+ error3 *= nbl_glsl_ieee754_gamma(1u);
221
+ retval = nbl_glsl_ieee754_add_with_bounds_wo_gamma(error,retval,error3,origin,origin_error);
222
+ // error *= nbl_glsl_ieee754_gamma(1u);
223
+ error *= nbl_glsl_ieee754_gamma(8u); // cause PBRT says so
224
+ return retval;
213
225
}
214
226
// robust ray origins
215
- vec3 nbl_glsl_robust_ray_origin_fastest (in vec3 origin, in vec3 direction, float error , vec3 normal)
227
+ vec3 nbl_glsl_robust_ray_origin_impl (in vec3 origin, in vec3 direction, float offset , vec3 normal)
216
228
{
217
229
// flip it in the correct direction
218
- error = uintBitsToFloat(floatBitsToUint(error)^ (floatBitsToUint(dot (normal,direction))& 0x80000000u));
219
- return origin+ normal* error;
220
- }
221
- vec3 nbl_glsl_robust_ray_origin_fast(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
222
- {
223
- // anticipate that the error could have increased from manipulation
224
- return nbl_glsl_robust_ray_origin_fastest(origin,direction,error.x+ error.y+ error.z,normal);
225
- }
226
- vec3 nbl_glsl_robust_ray_origin(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
227
- {
228
- const float d = dot (abs (normal),error);
229
- // anticipate that the error could have increased from manipulation
230
- return nbl_glsl_robust_ray_origin_fastest(origin,direction,d,normal);
230
+ offset = uintBitsToFloat(floatBitsToUint(offset)^ (floatBitsToUint(dot (normal,direction))& 0x80000000u));
231
+ return origin+ normal* offset;
231
232
}
232
233
233
234
@@ -259,7 +260,7 @@ void gen_sample_ray(
259
260
void generate_next_rays(
260
261
in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth,
261
262
in nbl_glsl_xoroshiro64star_state_t scramble_start_state, in uint sampleID, in uvec2 outPixelLocation,
262
- in vec3 origin, in vec3 prevThroughput)
263
+ in vec3 origin, in vec3 origin_error, in vec3 prevThroughput)
263
264
{
264
265
// get material streams as well
265
266
const nbl_glsl_MC_instr_stream_t gcs = nbl_glsl_MC_oriented_material_t_getGenChoiceStream(material);
@@ -301,14 +302,14 @@ for (uint i=1u; i!=vertex_depth; i++)
301
302
// TODO: investigate workgroup reductions here
302
303
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
303
304
304
- // TODO: improve
305
- const vec3 error = vec3 ( 0 .01f); // abs(origin)* uintBitsToFloat(0x35480005) ;
305
+ // adjust for the fact that the normal might be too short (inversesqrt precision)
306
+ const float ray_offset = dot ( abs (normalizedN),origin_error) * 1 .03125f ;
306
307
uint offset = 0u;
307
308
for (uint i= 0u; i< maxRaysToGen; i++ )
308
309
if (maxT[i]!= 0 .f)
309
310
{
310
311
nbl_glsl_ext_RadeonRays_ray newRay;
311
- newRay.origin = nbl_glsl_robust_ray_origin (origin,direction[i],error ,normalizedN);
312
+ newRay.origin = nbl_glsl_robust_ray_origin_impl (origin,direction[i],ray_offset ,normalizedN);
312
313
newRay.maxT = maxT[i];
313
314
newRay.direction = direction[i];
314
315
newRay.time = packOutPixelLocation(outPixelLocation);
0 commit comments