@@ -146,22 +146,22 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
146
146
#include < nbl/ builtin/ glsl/ material_compiler/ common.glsl>
147
147
148
148
149
- vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint _sample)
149
+ vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth )
150
150
{
151
- uvec3 seqVal = texelFetch(sampleSequence,int (_sample)) .xyz; // TODO: add depth param!!!
151
+ uvec3 seqVal = texelFetch(sampleSequence,int (_sample)+ (depth - 1 ) * MAX_ACCUMULATED_SAMPLES) .xyz;
152
152
seqVal ^= uvec3 (nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
153
153
return vec3 (seqVal)* uintBitsToFloat(0x2f800004u);
154
154
}
155
155
156
156
void gen_sample_ray(
157
157
out float maxT, out vec3 direction, out vec3 throughput,
158
- inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID,
158
+ inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID, in uint depth,
159
159
in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
160
160
)
161
161
{
162
162
maxT = FLT_MAX;
163
163
164
- vec3 rand = rand3d(scramble_state,sampleID);
164
+ vec3 rand = rand3d(scramble_state,int ( sampleID), int (depth) );
165
165
166
166
float pdf;
167
167
nbl_glsl_LightSample s;
@@ -213,7 +213,7 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
213
213
}
214
214
215
215
void generate_next_rays(
216
- in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth_mod_2 ,
216
+ in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth ,
217
217
in nbl_glsl_xoroshiro64star_state_t scramble_start_state, in uint sampleID, in uvec2 outPixelLocation,
218
218
in vec3 origin, vec3 geomNormal, in vec3 prevThroughput)
219
219
{
@@ -228,7 +228,8 @@ void generate_next_rays(
228
228
const nbl_glsl_MC_instr_stream_t nps = nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material);
229
229
nbl_glsl_MC_runNormalPrecompStream(nps,precomputed);
230
230
#endif
231
-
231
+
232
+ const uint vertex_depth_mod_2 = vertex_depth& 0x1u;
232
233
const uint vertex_depth_mod_2_inv = vertex_depth_mod_2^ 0x1u;
233
234
// prepare rays
234
235
uint raysToAllocate = 0u;
@@ -237,9 +238,10 @@ void generate_next_rays(
237
238
{
238
239
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
239
240
// TODO: When generating NEE rays, advance the dimension, NOT the sampleID
240
- gen_sample_ray(maxT[i],direction[i],nextThroughput[i],scramble_state,sampleID+ i,precomputed,gcs,rnps);
241
- if (i== 0u)
242
- imageStore(scramblebuf,ivec3 (outPixelLocation,vertex_depth_mod_2_inv),uvec4 (scramble_state,0u,0u));
241
+ gen_sample_ray(maxT[i],direction[i],nextThroughput[i],scramble_state,sampleID+ i,vertex_depth,precomputed,gcs,rnps);
242
+ // TODO: bad idea, invent something else
243
+ // if (i==0u)
244
+ // imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
243
245
nextThroughput[i] *= prevThroughput;
244
246
if (any (greaterThan (nextThroughput[i],vec3 (FLT_MIN))))
245
247
raysToAllocate++ ;
@@ -256,8 +258,8 @@ void generate_next_rays(
256
258
{
257
259
nbl_glsl_ext_RadeonRays_ray newRay;
258
260
// TODO: improve ray offsets
259
- const float err = frontfacing ? ( 1.0 / 96 ) : ( - 1.0 / 96 ) ;
260
- newRay.origin = origin+ geomNormal* err;
261
+ const float err = 1 .f / 96 .f ;
262
+ newRay.origin = origin+/* geomNormal/max(max(geomNormal.x,geomNormal.y),geomNormal.z)*sign(dot(geomNormal,direction[i])) */ direction[i] * err;
261
263
newRay.maxT = maxT[i];
262
264
newRay.direction = direction[i];
263
265
newRay.time = packOutPixelLocation(outPixelLocation);
0 commit comments