From 074dc9b6755048d7b913ededd5f04d0af8075b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 10 Feb 2021 20:40:42 +0100 Subject: EEVEE: Lightcache: Change cubemap roughness mapping This changes the roughness mapping to better utilize the mip chain resolution. This improves glossy reflections with small roughness. Lightcache version bumped because old data does not have the same roughness mapping and cannot be used. --- source/blender/draw/engines/eevee/eevee_lightprobes.c | 6 ++++-- source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl | 8 +++++--- source/blender/makesdna/DNA_lightprobe_types.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index 3671bea9ac0..9e1544c6cd9 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -1040,8 +1040,10 @@ void EEVEE_lightbake_filter_glossy(EEVEE_ViewLayerData *sldata, pinfo->padding_size *= pinfo->texel_size; pinfo->layer = probe_idx * 6; pinfo->roughness = i / (float)maxlevel; - pinfo->roughness *= pinfo->roughness; /* Disney Roughness */ - pinfo->roughness *= pinfo->roughness; /* Distribute Roughness accros lod more evenly */ + /* Disney Roughness */ + pinfo->roughness = square_f(pinfo->roughness); + /* Distribute Roughness across lod more evenly */ + pinfo->roughness = square_f(square_f(pinfo->roughness)); CLAMP(pinfo->roughness, 1e-8f, 0.99999f); /* Avoid artifacts */ #if 1 /* Variable Sample count and bias (fast) */ diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl index fe4f3dcaa2f..5e78fae5b82 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl @@ -167,7 +167,7 @@ vec3 probe_evaluate_cube(int pd_id, vec3 W, vec3 R, float roughness) * http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf */ float original_roughness = roughness; - float linear_roughness = sqrt(roughness); + float linear_roughness = fast_sqrt(roughness); float distance_roughness = saturate(dist * linear_roughness / length(intersection)); linear_roughness = mix(distance_roughness, linear_roughness, linear_roughness); roughness = linear_roughness * linear_roughness; @@ -175,12 +175,14 @@ vec3 probe_evaluate_cube(int pd_id, vec3 W, vec3 R, float roughness) float fac = saturate(original_roughness * 2.0 - 1.0); R = mix(intersection, R, fac * fac); - return textureLod_cubemapArray(probeCubes, vec4(R, float(pd_id)), roughness * prbLodCubeMax).rgb; + float lod = linear_roughness * prbLodCubeMax; + return textureLod_cubemapArray(probeCubes, vec4(R, float(pd_id)), lod).rgb; } vec3 probe_evaluate_world_spec(vec3 R, float roughness) { - return textureLod_cubemapArray(probeCubes, vec4(R, 0.0), roughness * prbLodCubeMax).rgb; + float lod = fast_sqrt(roughness) * prbLodCubeMax; + return textureLod_cubemapArray(probeCubes, vec4(R, 0.0), lod).rgb; } vec3 probe_evaluate_planar(int id, PlanarData pd, vec3 W, vec3 N, vec3 V, float roughness) diff --git a/source/blender/makesdna/DNA_lightprobe_types.h b/source/blender/makesdna/DNA_lightprobe_types.h index 3830919bfd3..4fdce6d5f45 100644 --- a/source/blender/makesdna/DNA_lightprobe_types.h +++ b/source/blender/makesdna/DNA_lightprobe_types.h @@ -185,7 +185,7 @@ typedef struct LightCache { } LightCache; /* Bump the version number for lightcache data structure changes. */ -#define LIGHTCACHE_STATIC_VERSION 1 +#define LIGHTCACHE_STATIC_VERSION 2 /* LightCache->type */ enum { -- cgit v1.2.3