Skip to content

Commit

Permalink
Sampling and BRDF improvements:
Browse files Browse the repository at this point in the history
- Random number generator now produces enough different sequences to cover 500 frames of reference mode accumulation;
- Hemisphere sampling for indirect diffuse tuned to make the results better match the cosine-weighted sampling in reference mode;
- Direct diffuse lighting is now correctly divided by PI and matches same lighting computed by random sampling of emissive surfaces;
- Spotlight term removed from sky polygons and added to other non-analytic emissive surfaces;
- Suspicious 0.5 term removed from sky polygons.
Also the `pt_direct_polygon_lights` cvar has a new meaning when set to -1: all polygon lights are sampled through the indirect lighting shader, for comparison purposes.
Inspired by #37
  • Loading branch information
apanteleev committed Jul 17, 2019
1 parent a010d6d commit b49be8f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/refresh/vkpt/shader/asvgf_seed_rng.comp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ main()

rng_seed |= (uint(ipos.x) % BLUE_NOISE_RES) << 0u;
rng_seed |= (uint(ipos.y) % BLUE_NOISE_RES) << 10u;
rng_seed |= checkerboard << 20;
rng_seed |= uint(frame_num) << 21;
rng_seed |= uint(frame_num + checkerboard) << 20;

imageStore(IMG_ASVGF_RNG_SEED_A, ipos, uvec4(rng_seed));
}
4 changes: 2 additions & 2 deletions src/refresh/vkpt/shader/direct_lighting.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ direct_lighting(ivec2 ipos, bool is_odd_checkerboard, out vec3 high_freq, out ve
spec_enable_caustics != 0,
primary_specular,
direct_specular_weight,
global_ubo.pt_direct_polygon_lights != 0,
global_ubo.pt_direct_sphere_lights != 0,
global_ubo.pt_direct_polygon_lights > 0,
global_ubo.pt_direct_sphere_lights > 0,
direct_diffuse,
direct_specular);

Expand Down
8 changes: 6 additions & 2 deletions src/refresh/vkpt/shader/indirect_lighting.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ trace_secondary_ray(

if(is_sky(ray_payload_brdf))
{
bool is_analytic_light = (triangle.material_id & MATERIAL_FLAG_LIGHT) != 0 && (spec_bounce_index == 0);
bool is_analytic_light = (triangle.material_id & MATERIAL_FLAG_LIGHT) != 0 && (spec_bounce_index == 0) && (global_ubo.pt_direct_polygon_lights >= 0);
if(!is_analytic_light || is_specular_ray)
{
vec3 env = env_map(bounce_direction, true);
Expand Down Expand Up @@ -226,7 +226,11 @@ trace_secondary_ray(
{
emissive *= bounce_throughput;

bool is_analytic_light = (bounce_material_id & MATERIAL_FLAG_LIGHT) != 0;
// spotlight term that matches the sample_light_lists() function in light_lists.h
float spotlight = sqrt(max(0, -dot(bounce_direction, bounce_normal)));
emissive *= spotlight;

bool is_analytic_light = (bounce_material_id & MATERIAL_FLAG_LIGHT) != 0 && (global_ubo.pt_direct_polygon_lights >= 0);

if(is_specular_ray)
{
Expand Down
4 changes: 2 additions & 2 deletions src/refresh/vkpt/shader/light_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ sample_light_list(

float light_lum = luminance(light.color);
if(light_lum < 0 && global_ubo.environment_type == ENVIRONMENT_DYNAMIC)
m *= sun_color_ubo.sky_luminance * 0.5;
m *= sun_color_ubo.sky_luminance;
else
m *= abs(light_lum); // abs because sky lights have negative color

Expand Down Expand Up @@ -181,7 +181,7 @@ sample_light_list(
if(light.color.r >= 0)
light_color = light.color * area * spotlight;
else
light_color = env_map(L, true) * area * spotlight * global_ubo.pt_env_scale * 0.5;
light_color = env_map(L, true) * area * global_ubo.pt_env_scale;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/refresh/vkpt/shader/path_tracer_rgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ float
get_rng(uint idx)
{
uvec3 p = uvec3(rng_seed, rng_seed >> 10, rng_seed >> 20);
p.z = (p.z * NUM_RNG_PER_FRAME + idx);
p.z = (p.z + idx);
p &= uvec3(BLUE_NOISE_RES - 1, BLUE_NOISE_RES - 1, NUM_BLUE_NOISE_TEX - 1);

return min(texelFetch(TEX_BLUE_NOISE, ivec3(p), 0).r, 0.9999999999999);
Expand Down Expand Up @@ -488,7 +488,7 @@ get_direct_illumination(

float NdotL = max(0, dot(normal, L));

diffuse *= NdotL;
diffuse *= NdotL / M_PI;
}

void
Expand Down Expand Up @@ -566,7 +566,7 @@ get_sunlight(
specular = diffuse * GGX(view_direction, global_ubo.sun_direction, normal, roughness, NoH_offset);
}

diffuse *= NdotL;
diffuse *= NdotL / M_PI;
}

vec3 clamp_output(vec3 c)
Expand Down
2 changes: 1 addition & 1 deletion src/refresh/vkpt/shader/utils.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ sample_cos_hemisphere(vec2 uv)
}

#define HEMISPHERE_COSINE 0.5
#define HEMISPHERE_UNIFORMISH 0.25
#define HEMISPHERE_UNIFORMISH 0.4

vec3
sample_cos_hemisphere_multi(
Expand Down

1 comment on commit b49be8f

@DU-jdto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the spotlight term also be applied to emissive surfaces sampled in direct_lighting.rgen?

Please sign in to comment.