Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2017-12-02 16:28:29 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-12-04 12:10:27 +0300
commit5b6cfa705cb180d042f6f27e45331c12972be7ae (patch)
tree931f935dedd2bc3ce87066f09879b7cf10a32e8c /source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
parent847f568bf5f2aed8904066895e175da7118522e7 (diff)
Eevee: Irradiance Visibility: Initial Implementation
This augment the existing irradiance grid with a new visibility precomputation. We store a small shadowmap for each grid sample so that light does not leak through walls and such. The visibility parameter are similar to the one used by the Variance Shadow Map for point lights. Technical details: We store the visibility in the same texture (array) as the irradiance itself (in order to reduce the number of sampler). But the irradiance and the visibility are not the same data so we must encode them in order to use the same texture format. We use RGBA8 normalized texture and encode irradiance as RGBE (shared exponent). Using RGBE encoding instead of R11_G11_B10 may lead to some lighting changes, but quality seems to be nearly the same in my test cases. Using full RGBA16/32F maybe a future option but that will require much more memory and reduce the perf significantly. Visibility moments (VSM) are encoded as 16bits fixed point precision using a special range. This seems to retain enough precision for the needs. Also interpolation does not seems to be big problem (even though it's incorrect).
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl64
1 files changed, 50 insertions, 14 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
index 95e7af41398..2555d413da9 100644
--- a/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
@@ -1,5 +1,6 @@
-uniform sampler2D irradianceGrid;
+uniform sampler2DArray irradianceGrid;
+uniform int irradianceVisibilitySize;
#define IRRADIANCE_LIB
@@ -36,7 +37,7 @@ IrradianceData load_irradiance_cell(int cell, vec3 N)
uvs += vec2(cell_co) / vec2(textureSize(irradianceGrid, 0));
IrradianceData ir;
- ir.color = texture(irradianceGrid, uvs).rgb;
+ ir.color = texture(irradianceGrid, vec3(uvs, 0.0)).rgb;
#elif defined(IRRADIANCE_SH_L2)
@@ -48,15 +49,15 @@ IrradianceData load_irradiance_cell(int cell, vec3 N)
ivec3 ofs = ivec3(0, 1, 2);
IrradianceData ir;
- ir.shcoefs[0] = texelFetch(irradianceGrid, cell_co + ofs.xx, 0).rgb;
- ir.shcoefs[1] = texelFetch(irradianceGrid, cell_co + ofs.yx, 0).rgb;
- ir.shcoefs[2] = texelFetch(irradianceGrid, cell_co + ofs.zx, 0).rgb;
- ir.shcoefs[3] = texelFetch(irradianceGrid, cell_co + ofs.xy, 0).rgb;
- ir.shcoefs[4] = texelFetch(irradianceGrid, cell_co + ofs.yy, 0).rgb;
- ir.shcoefs[5] = texelFetch(irradianceGrid, cell_co + ofs.zy, 0).rgb;
- ir.shcoefs[6] = texelFetch(irradianceGrid, cell_co + ofs.xz, 0).rgb;
- ir.shcoefs[7] = texelFetch(irradianceGrid, cell_co + ofs.yz, 0).rgb;
- ir.shcoefs[8] = texelFetch(irradianceGrid, cell_co + ofs.zz, 0).rgb;
+ ir.shcoefs[0] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xx, 0), 0).rgb;
+ ir.shcoefs[1] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yx, 0), 0).rgb;
+ ir.shcoefs[2] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zx, 0), 0).rgb;
+ ir.shcoefs[3] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xy, 0), 0).rgb;
+ ir.shcoefs[4] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yy, 0), 0).rgb;
+ ir.shcoefs[5] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zy, 0), 0).rgb;
+ ir.shcoefs[6] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xz, 0), 0).rgb;
+ ir.shcoefs[7] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yz, 0), 0).rgb;
+ ir.shcoefs[8] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zz, 0), 0).rgb;
#else /* defined(IRRADIANCE_HL2) */
@@ -68,15 +69,50 @@ IrradianceData load_irradiance_cell(int cell, vec3 N)
ivec3 is_negative = ivec3(step(0.0, -N));
IrradianceData ir;
- ir.cubesides[0] = texelFetch(irradianceGrid, cell_co + ivec2(0, is_negative.x), 0).rgb;
- ir.cubesides[1] = texelFetch(irradianceGrid, cell_co + ivec2(1, is_negative.y), 0).rgb;
- ir.cubesides[2] = texelFetch(irradianceGrid, cell_co + ivec2(2, is_negative.z), 0).rgb;
+ ir.cubesides[0] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(0, is_negative.x), 0), 0));
+ ir.cubesides[1] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(1, is_negative.y), 0), 0));
+ ir.cubesides[2] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(2, is_negative.z), 0), 0));
#endif
return ir;
}
+float load_visibility_cell(int cell, vec3 L, float dist, float bias, float bleed_bias, float range)
+{
+ /* Keep in sync with diffuse_filter_probe() */
+ ivec2 cell_co = ivec2(irradianceVisibilitySize);
+ int cell_per_row = textureSize(irradianceGrid, 0).x / irradianceVisibilitySize;
+ cell_co.x *= (cell) % cell_per_row;
+ cell_co.y *= (cell) / cell_per_row;
+
+ vec2 texel_size = 1.0 / vec2(textureSize(irradianceGrid, 0).xy);
+ vec2 co = vec2(cell_co) * texel_size;
+
+ vec2 uv = mapping_octahedron(-L, vec2(1.0 / float(irradianceVisibilitySize)));
+ uv *= vec2(irradianceVisibilitySize) * texel_size;
+
+ vec4 data = texture(irradianceGrid, vec3(co + uv, 1.0));
+
+ /* Decoding compressed data */
+ vec2 moments = visibility_decode(data, range);
+
+ /* Doing chebishev test */
+ float variance = abs(moments.x * moments.x - moments.y);
+ variance = max(variance, bias / 10.0);
+
+ float d = dist - moments.x;
+ float p_max = variance / (variance + d * d);
+
+ /* Increase contrast in the weight by squaring it */
+ p_max *= p_max;
+
+ /* Now reduce light-bleeding by removing the [0, x] tail and linearly rescaling (x, 1] */
+ p_max = clamp((p_max - bleed_bias) / (1.0 - bleed_bias), 0.0, 1.0);
+
+ return (dist <= moments.x) ? 1.0 : p_max;
+}
+
/* http://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ */
vec3 spherical_harmonics_L1(vec3 N, vec3 shcoefs[4])
{