Alright I’m trying to wrap my mind around this simple piece of code. But I’m really having a little hard time in understanding some specifics, while I totally understand what it does contextually.
First off the computation inv_screen. I dont understand 1.0f/make_float2(screen) how it works dividing 1.0f by a vec2 kinda format. Similarly computation of pixel. I am also not sure how the variables x,y,jitter,d, ray_direction fall in place with respect to one another.
size_t2 screen = output_buffer.size();
float2 inv_screen = 1.0f/make_float2(screen) * 2.f;
float2 pixel = (make_float2(launch_index)) * inv_screen - 1.f;
float2 jitter_scale = inv_screen / sqrt_num_samples;
unsigned int samples_per_pixel = sqrt_num_samples*sqrt_num_samples;
float3 result = make_float3(0.0f);
unsigned int seed = tea<16>(screen.x*launch_index.y+launch_index.x, frame_number);
do
{
//
// Sample pixel using jittering
//
unsigned int x = samples_per_pixel%sqrt_num_samples;
unsigned int y = samples_per_pixel/sqrt_num_samples;
float2 jitter = make_float2(x-rnd(seed), y-rnd(seed));
float2 d = pixel + jitter*jitter_scale;
float3 ray_origin = eye;
float3 ray_direction = normalize(d.x*U + d.y*V + W);