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/lightprobe_filter_visibility_frag.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/lightprobe_filter_visibility_frag.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl88
1 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl
new file mode 100644
index 00000000000..0727e73f507
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl
@@ -0,0 +1,88 @@
+
+uniform samplerCube probeDepth;
+uniform int outputSize;
+uniform float lodFactor;
+uniform float storedTexelSize;
+uniform float lodMax;
+uniform float nearClip;
+uniform float farClip;
+uniform float visibilityRange;
+uniform float visibilityBlur;
+
+out vec4 FragColor;
+
+vec3 octahedral_to_cubemap_proj(vec2 co)
+{
+ co = co * 2.0 - 1.0;
+
+ vec2 abs_co = abs(co);
+ vec3 v = vec3(co, 1.0 - (abs_co.x + abs_co.y));
+
+ if ( abs_co.x + abs_co.y > 1.0 ) {
+ v.xy = (abs(co.yx) - 1.0) * -sign(co.xy);
+ }
+
+ return v;
+}
+
+float linear_depth(float z)
+{
+ return (nearClip * farClip) / (z * (nearClip - farClip) + farClip);
+}
+
+float get_world_distance(float depth, vec3 cos)
+{
+ float is_background = step(1.0, depth);
+ depth = linear_depth(depth);
+ depth += 1e1 * is_background;
+ cos = normalize(abs(cos));
+ float cos_vec = max(cos.x, max(cos.y, cos.z));
+ return depth / cos_vec;
+}
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy) % ivec2(outputSize);
+
+ vec3 cos;
+
+ cos.xy = (vec2(texel) + 0.5) * storedTexelSize;
+
+ /* add a 2 pixel border to ensure filtering is correct */
+ cos.xy *= 1.0 + storedTexelSize * 2.0;
+ cos.xy -= storedTexelSize;
+
+ float pattern = 1.0;
+
+ /* edge mirroring : only mirror if directly adjacent
+ * (not diagonally adjacent) */
+ vec2 m = abs(cos.xy - 0.5) + 0.5;
+ vec2 f = floor(m);
+ if (f.x - f.y != 0.0) {
+ cos.xy = 1.0 - cos.xy;
+ }
+
+ /* clamp to [0-1] */
+ cos.xy = fract(cos.xy);
+
+ /* get cubemap vector */
+ cos = normalize(octahedral_to_cubemap_proj(cos.xy));
+
+ vec3 T, B;
+ make_orthonormal_basis(cos, T, B); /* Generate tangent space */
+
+ vec2 accum = vec2(0.0);
+
+ for (float i = 0; i < sampleCount; i++) {
+ vec3 sample = sample_cone(i, M_PI_2 * visibilityBlur, cos, T, B);
+ float depth = texture(probeDepth, sample).r;
+ depth = get_world_distance(depth, sample);
+ accum += vec2(depth, depth * depth);
+ }
+
+ accum *= invSampleCount;
+ accum = abs(accum);
+
+ /* Encode to normalized RGBA 8 */
+ FragColor = visibility_encode(accum, visibilityRange);
+} \ No newline at end of file