From fe008592024c3081c5b43b82482d46e41262fdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 7 Feb 2021 18:03:58 +0100 Subject: EEVEE: Rewrite closure_lit_lib to reduce complexity This rewrite improves: - Code clarity: Less duplicated code and removes a few hacks. - Compile time performance: Shader code was divided by 3 in average. I did not profile the compilation time but it is faster. - Shading Perf: Noticed a 25% performance improvement on the shading pass with default dielectric principled bsdf. - Fix Principled Tint being white if color is black - It seems to have fixed issues on some drivers giving some incorect results. - Changes Principled BSDF support to be less hacky. --- source/blender/draw/intern/shaders/common_math_lib.glsl | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/blender/draw/intern') diff --git a/source/blender/draw/intern/shaders/common_math_lib.glsl b/source/blender/draw/intern/shaders/common_math_lib.glsl index a82e0b5a5e9..84d93cc3965 100644 --- a/source/blender/draw/intern/shaders/common_math_lib.glsl +++ b/source/blender/draw/intern/shaders/common_math_lib.glsl @@ -72,6 +72,9 @@ float sum(vec4 v) { return dot(vec4(1.0), v); } float avg(vec2 v) { return dot(vec2(1.0 / 2.0), v); } float avg(vec3 v) { return dot(vec3(1.0 / 3.0), v); } float avg(vec4 v) { return dot(vec4(1.0 / 4.0), v); } + +float sqr(float v) { return v * v; } + /* clang-format on */ #define saturate(a) clamp(a, 0.0, 1.0) @@ -93,6 +96,15 @@ float len_squared(vec3 a) return dot(a, a); } +vec3 safe_normalize(vec3 v) +{ + float len = length(v); + if (isnan(len) || len == 0.0) { + return vec3(1.0, 0.0, 0.0); + } + return v / len; +} + /** \} */ /* ---------------------------------------------------------------------- */ -- cgit v1.2.3