diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-11-15 20:13:07 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-11-15 20:16:30 +0300 |
commit | c2164e579c3dde8c0fbb42e0c146bfd5ad1b563b (patch) | |
tree | 631fedacdf5e4830acf2a54c6ab7bc4225e48f04 /source/blender/draw/engines | |
parent | 11b3954346b1e4ee2d70d8f4efa2e1a57c9fbef8 (diff) |
Eevee: Add irradiance smoothing
This is a parameter that will make the interpolation between irradiance
cells of a same Irradiance Volume smoother, reducing the weight of the
light leaking correction factors.
It is usefull in some cases to avoid harsh lighting transition that can
happen when a sample point it near a surface.
Diffstat (limited to 'source/blender/draw/engines')
5 files changed, 14 insertions, 5 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c index 36425e80094..873a63db355 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.c +++ b/source/blender/draw/engines/eevee/eevee_lightcache.c @@ -671,6 +671,7 @@ static void eevee_lightbake_cache_create(EEVEE_Data *vedata, EEVEE_LightBake *lb /* Disable all effects BUT high bitdepth shadows. */ scene_eval->eevee.flag &= SCE_EEVEE_SHADOW_HIGH_BITDEPTH; scene_eval->eevee.taa_samples = 1; + scene_eval->eevee.gi_irradiance_smoothing = 0.0f; stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__); stl->g_data->background_alpha = 1.0f; diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index 256425221f4..e4659306f5c 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -833,6 +833,8 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ved EEVEE_StorageList *stl = vedata->stl; LightCache *light_cache = stl->g_data->light_cache; EEVEE_LightProbesInfo *pinfo = sldata->probes; + const DRWContextState *draw_ctx = DRW_context_state_get(); + const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph); eevee_lightprobes_extract_from_cache(sldata->probes, light_cache); @@ -843,6 +845,7 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ved sldata->common_data.prb_lod_cube_max = (float)light_cache->mips_len - 1.0f; sldata->common_data.prb_lod_planar_max = (float)MAX_PLANAR_LOD_LEVEL; sldata->common_data.prb_irradiance_vis_size = light_cache->vis_res; + sldata->common_data.prb_irradiance_smooth = SQUARE(scene_eval->eevee.gi_irradiance_smoothing); sldata->common_data.prb_num_render_cube = max_ii(1, light_cache->cube_len); sldata->common_data.prb_num_render_grid = max_ii(1, light_cache->grid_len); sldata->common_data.prb_num_planar = pinfo->num_planar; @@ -859,7 +862,6 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ved if (!DRW_state_is_image_render() && !DRW_state_is_opengl_render() && (pinfo->do_grid_update || pinfo->do_cube_update)) { - const DRWContextState *draw_ctx = DRW_context_state_get(); BLI_assert(draw_ctx->evil_C); if (draw_ctx->scene->eevee.flag & SCE_EEVEE_GI_AUTOBAKE) { diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 7c431e6685c..09e444c40b2 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -653,6 +653,7 @@ typedef struct EEVEE_CommonUniformBuffer { int prb_num_render_cube; /* int */ int prb_num_render_grid; /* int */ int prb_irradiance_vis_size; /* int */ + float prb_irradiance_smooth; /* float */ float prb_lod_cube_max; /* float */ float prb_lod_planar_max; /* float */ /* Misc */ diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl index d26013ce132..9c5a212aead 100644 --- a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl @@ -34,6 +34,7 @@ layout(std140) uniform common_block { int prbNumRenderCube; int prbNumRenderGrid; int prbIrradianceVisSize; + float prbIrradianceSmooth; float prbLodCubeMax; float prbLodPlanarMax; /* Misc*/ diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl index e0cba826c76..a991e640a79 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl @@ -273,14 +273,18 @@ vec3 probe_evaluate_grid(GridData gd, vec3 W, vec3 N, vec3 localpos) float ws_dist_point_to_cell = length(ws_point_to_cell); vec3 ws_light = ws_point_to_cell / ws_dist_point_to_cell; - vec3 trilinear = mix(1 - trilinear_weight, trilinear_weight, offset); - float weight = trilinear.x * trilinear.y * trilinear.z; + /* Smooth backface test */ + float weight = saturate(dot(ws_light, N)); /* Precomputed visibility */ weight *= load_visibility_cell(cell, ws_light, ws_dist_point_to_cell, gd.g_vis_bias, gd.g_vis_bleed, gd.g_vis_range); - /* Smooth backface test */ - weight *= dot(ws_light, N); + /* Smoother transition */ + weight += prbIrradianceSmooth; + + /* Trilinear weights */ + vec3 trilinear = mix(1.0 - trilinear_weight, trilinear_weight, offset); + weight *= trilinear.x * trilinear.y * trilinear.z; /* Avoid zero weight */ weight = max(0.00001, weight); |