diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-01-29 03:01:11 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-01-29 03:02:14 +0300 |
commit | b0f6fb83699c92b290d75bbd97776fe4c5898b58 (patch) | |
tree | 1a32bafa0bc85a50222eeb340c0415acf8f8b431 /source/blender | |
parent | 3d73609832da4039ac0d4c4a3089ea180213fd1b (diff) |
EEVEE: Micro optimize disk light
Try to never do operation twice and try to use MADD operations. Even if this
is very unlikely to make any difference, it can help compilers do some
optimization. I did not measure any difference as probes have much higher
impact on render time because of texture lookups.
Note that disk light is currently the most expensive light type so it
does not hurt to micro optimize.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/ltc_lib.glsl | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl index 61d34e2afdc..dbfc7ad5a71 100644 --- a/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl @@ -47,9 +47,7 @@ vec3 solve_cubic(vec4 coefs) float D = coefs.x; /* Compute the Hessian and the discriminant */ - vec3 delta = vec3(-coefs.z * coefs.z + coefs.y, - -coefs.y * coefs.z + coefs.x, - dot(vec2(coefs.z, -coefs.y), coefs.xy)); + vec3 delta = vec3(-coefs.zy * coefs.zz + coefs.yx, dot(vec2(coefs.z, -coefs.y), coefs.xy)); /* Discriminant */ float discr = dot(vec2(4.0 * delta.x, -delta.y), delta.zy); @@ -68,8 +66,9 @@ vec3 solve_cubic(vec4 coefs) /* Take the cubic root of a normalized complex number */ float theta = atan(sqrt_discr, -D_a) / 3.0; - float x_1a = 2.0 * sqrt(-C_a) * cos(theta); - float x_3a = 2.0 * sqrt(-C_a) * cos(theta + (2.0 / 3.0) * M_PI); + float _2_sqrt_C_a = 2.0 * sqrt(-C_a); + float x_1a = _2_sqrt_C_a * cos(theta); + float x_3a = _2_sqrt_C_a * cos(theta + (2.0 / 3.0) * M_PI); float xl; if ((x_1a + x_3a) > 2.0 * B) { @@ -91,8 +90,9 @@ vec3 solve_cubic(vec4 coefs) /* Take the cubic root of a normalized complex number */ float theta = atan(D * sqrt_discr, -D_d) / 3.0; - float x_1d = 2.0 * sqrt(-C_d) * cos(theta); - float x_3d = 2.0 * sqrt(-C_d) * cos(theta + (2.0 / 3.0) * M_PI); + float _2_sqrt_C_d = 2.0 * sqrt(-C_d); + float x_1d = _2_sqrt_C_d * cos(theta); + float x_3d = _2_sqrt_C_d * cos(theta + (2.0 / 3.0) * M_PI); float xs; if (x_1d + x_3d < 2.0 * C) { @@ -272,15 +272,18 @@ float ltc_evaluate_disk(vec3 N, vec3 V, mat3 Minv, vec3 disk_points[3]) } float L = dot(V3, C); - float x0 = dot(V1, C) / L; - float y0 = dot(V2, C) / L; + float inv_L = 1.0 / L; + float x0 = dot(V1, C) * inv_L; + float y0 = dot(V2, C) * inv_L; - a *= L * L; - b *= L * L; + float L_sqr = L * L; + a *= L_sqr; + b *= L_sqr; + float t = 1.0 + x0 * x0; float c0 = a * b; - float c1 = a * b * (1.0 + x0 * x0 + y0 * y0) - a - b; - float c2 = 1.0 - a * (1.0 + x0 * x0) - b * (1.0 + y0 * y0); + float c1 = c0 * (t + y0 * y0) - a - b; + float c2 = (1.0 - a * t) - b * (1.0 + y0 * y0); float c3 = 1.0; vec3 roots = solve_cubic(vec4(c0, c1, c2, c3)); |