@@ -118,47 +118,34 @@ 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
-
144
121
#include < nbl/ builtin/ glsl/ barycentric/ utils.glsl>
145
122
mat2x3 dPdBary;
146
- vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
123
+ vec3 load_positions(out mat2x3 dPdBary_error, out vec3 lastVxPos_error, in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
147
124
{
148
125
mat3 positions = mat3 (
149
126
nbl_glsl_fetchVtxPos(indices[0 ],batchInstanceData),
150
127
nbl_glsl_fetchVtxPos(indices[1 ],batchInstanceData),
151
128
nbl_glsl_fetchVtxPos(indices[2 ],batchInstanceData)
152
129
);
153
130
const mat4x3 tform = batchInstanceData.tform;
154
- mat3 error ;
131
+ mat3 positions_error ;
155
132
// 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*/ );
133
+ const float quantizationError = exp2 ( - 16 .f); // nbl_glsl_numeric_limits_float_epsilon(1u);
134
+ positions = nbl_glsl_mul_with_bounds_wo_gamma(positions_error ,mat3 (tform),positions, quantizationError);
158
135
//
159
- dPdBary = mat2x3 (positions[0 ]- positions[2 ],positions[1 ]- positions[2 ]);
160
- return positions[2 ]+ tform[3 ];
136
+ const float accum_error_factor = nbl_glsl_ieee754_gamma(2u)+ nbl_glsl_ieee754_gamma(3u);
137
+ for (int i= 0 ; i< 2 ; i++ )
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;
142
+ }
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);
146
+ return lastVx;
161
147
}
148
+
162
149
#ifdef TEX_PREFETCH_STREAM
163
150
mat2x3 nbl_glsl_perturbNormal_dPdSomething()
164
151
{
@@ -173,31 +160,6 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
173
160
#define _NBL_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
174
161
#include < nbl/ builtin/ glsl/ material_compiler/ common.glsl>
175
162
176
-
177
- vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth)
178
- {
179
- uvec3 seqVal = texelFetch(sampleSequence,int (_sample)+ (depth- 1 )* MAX_ACCUMULATED_SAMPLES).xyz;
180
- seqVal ^= uvec3 (nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
181
- return vec3 (seqVal)* uintBitsToFloat(0x2f800004u);
182
- }
183
-
184
- void gen_sample_ray(
185
- out float maxT, out vec3 direction, out vec3 throughput,
186
- inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID, in uint depth,
187
- in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
188
- )
189
- {
190
- maxT = nbl_glsl_FLT_MAX;
191
-
192
- vec3 rand = rand3d(scramble_state,int (sampleID),int (depth));
193
-
194
- float pdf;
195
- nbl_glsl_LightSample s;
196
- throughput = nbl_glsl_MC_runGenerateAndRemainderStream(precomp,gcs,rnps,rand,pdf,s);
197
-
198
- direction = s.L;
199
- }
200
-
201
163
nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
202
164
in vec2 compactBary, in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
203
165
in nbl_glsl_MC_oriented_material_t material,
@@ -244,6 +206,56 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
244
206
return scramble_start_state;
245
207
}
246
208
209
+ // 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)
211
+ {
212
+ return triangleEdges* compactBary+ origin;
213
+ }
214
+ // robust ray origins
215
+ vec3 nbl_glsl_robust_ray_origin_fastest(in vec3 origin, in vec3 direction, float error, vec3 normal)
216
+ {
217
+ // 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);
231
+ }
232
+
233
+
234
+ vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth)
235
+ {
236
+ uvec3 seqVal = texelFetch(sampleSequence,int (_sample)+ (depth- 1 )* MAX_ACCUMULATED_SAMPLES).xyz;
237
+ seqVal ^= uvec3 (nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
238
+ return vec3 (seqVal)* uintBitsToFloat(0x2f800004u);
239
+ }
240
+
241
+ void gen_sample_ray(
242
+ out float maxT, out vec3 direction, out vec3 throughput,
243
+ inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID, in uint depth,
244
+ in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
245
+ )
246
+ {
247
+ maxT = nbl_glsl_FLT_MAX;
248
+
249
+ vec3 rand = rand3d(scramble_state,int (sampleID),int (depth));
250
+
251
+ float pdf;
252
+ nbl_glsl_LightSample s;
253
+ throughput = nbl_glsl_MC_runGenerateAndRemainderStream(precomp,gcs,rnps,rand,pdf,s);
254
+
255
+ direction = s.L;
256
+ }
257
+
258
+
247
259
void generate_next_rays(
248
260
in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth,
249
261
in nbl_glsl_xoroshiro64star_state_t scramble_start_state, in uint sampleID, in uvec2 outPixelLocation,
0 commit comments