Skip to content

Commit

Permalink
Store 'is_odd_frame' and 'frame number' separately in rng_seed.
Browse files Browse the repository at this point in the history
Make room for that extra bit by using few less bits for the x/y values
crammed in there as well.
(And replace magic shift values with constants while we're at it.)
  • Loading branch information
res2k committed Jul 17, 2022
1 parent e1c4389 commit 3adad2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/refresh/vkpt/shader/path_tracer_rgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ uniform accelerationStructureEXT topLevelAS[TLAS_COUNT];

#define DESATURATE_ENVIRONMENT_MAP 1

/* RNG seeds contain 'X' and 'Y' values that are computed w/ a modulo BLUE_NOISE_RES,
* so the shift values can be chosen to fit BLUE_NOISE_RES - 1
* (see generate_rng_seed()) */
#define RNG_SEED_SHIFT_X 0u
#define RNG_SEED_SHIFT_Y 8u
#define RNG_SEED_SHIFT_ISODD 16u
#define RNG_SEED_SHIFT_FRAME 17u

#define RNG_PRIMARY_OFF_X 0
#define RNG_PRIMARY_OFF_Y 1
#define RNG_PRIMARY_APERTURE_X 2
Expand Down Expand Up @@ -171,7 +179,8 @@ get_hit_barycentric(RayPayloadGeometry rp)
float
get_rng(uint idx)
{
uvec3 p = uvec3(rng_seed, rng_seed >> 10, rng_seed >> 20);
uvec3 p = uvec3(rng_seed >> RNG_SEED_SHIFT_X, rng_seed >> RNG_SEED_SHIFT_Y, rng_seed >> RNG_SEED_SHIFT_ISODD);
p.z = (p.z >> 1) + (p.z & 1);
p.z = (p.z + idx);
p &= uvec3(BLUE_NOISE_RES - 1, BLUE_NOISE_RES - 1, NUM_BLUE_NOISE_TEX - 1);

Expand Down
7 changes: 4 additions & 3 deletions src/refresh/vkpt/shader/primary_rays.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ void generate_rng_seed(ivec2 ipos, bool is_odd_checkerboard)
uint frame_offset = frame_num / NUM_BLUE_NOISE_TEX;

rng_seed = 0;
rng_seed |= (uint(ipos.x + frame_offset) % BLUE_NOISE_RES) << 0u;
rng_seed |= (uint(ipos.y + (frame_offset << 4)) % BLUE_NOISE_RES) << 10u;
rng_seed |= uint(frame_num + uint(is_odd_checkerboard)) << 20;
rng_seed |= (uint(ipos.x + frame_offset) % BLUE_NOISE_RES) << RNG_SEED_SHIFT_X;
rng_seed |= (uint(ipos.y + (frame_offset << 4)) % BLUE_NOISE_RES) << RNG_SEED_SHIFT_Y;
rng_seed |= uint(is_odd_checkerboard) << RNG_SEED_SHIFT_ISODD;
rng_seed |= uint(frame_num) << RNG_SEED_SHIFT_FRAME;

imageStore(IMG_ASVGF_RNG_SEED_A, ipos, uvec4(rng_seed));
}
Expand Down

0 comments on commit 3adad2a

Please sign in to comment.