[Bf-blender-cvs] [f3074b96d6f] blender2.8: Eevee: Make sun power match cycles better.

Clément Foucault noreply at git.blender.org
Thu Nov 15 18:17:28 CET 2018


Commit: f3074b96d6fe748900d062c7dc3f51f37f06fc5a
Author: Clément Foucault
Date:   Wed Nov 14 15:46:40 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBf3074b96d6fe748900d062c7dc3f51f37f06fc5a

Eevee: Make sun power match cycles better.

I made an empirical test with a 100% diffuse sphere and manually tweak the
lighting power of a sun lamp trying to fit cycles and eevee the best I can.

Then I plotted the result and found a rough fit to the equation and that
seems to work pretty well.

===================================================================

M	source/blender/draw/engines/eevee/eevee_lights.c
M	source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
M	source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index 02667bf7087..962cb7c2033 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -663,6 +663,9 @@ static void eevee_light_setup(Object *ob, EEVEE_Light *evli)
 	else {
 		power = 1.0f / (4.0f * evli->radius * evli->radius * M_PI * M_PI) * /* 1/(r²*Pi) */
 		        12.5f; /* XXX : Empirical, Fit cycles power */
+		/* Make illumation power closer to cycles for bigger radii. Cycles uses a cos^3 term that we cannot reproduce
+		 * so we account for that by scaling the light power. This function is the result of a rough manual fitting. */
+		power *= 1.0f + evli->radius * evli->radius * 0.5f;
 	}
 	mul_v3_fl(evli->color, power * la->energy);
 
diff --git a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
index a2a26c0fbf0..ecc1a817dae 100644
--- a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
@@ -411,7 +411,8 @@ vec3 light_translucent(LightData ld, vec3 W, vec3 N, vec4 l_vector, float scale)
 			falloff = dot(N, l_vector.xyz / l_vector.w);
 		}
 		else if (ld.l_type == SUN) {
-			vis *= (4.0f * ld.l_radius * ld.l_radius * M_2PI) * (1.0 / 12.5); /* Removing area light power*/
+			vis /= 1.0f + (ld.l_radius * ld.l_radius * 0.5f);
+			vis *= ld.l_radius * ld.l_radius * M_PI; /* Removing area light power*/
 			vis *= M_2PI * 0.78; /* Matching cycles with point light. */
 			vis *= 0.082; /* XXX ad hoc, empirical */
 			falloff = dot(N, -ld.l_forward);
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
index 36c4562e137..ae36252153f 100644
--- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
@@ -74,7 +74,8 @@ vec3 light_volume(LightData ld, vec4 l_vector)
 		power *= 20.0 * max(0.0, dot(-ld.l_forward, l_vector.xyz / l_vector.w)); /* XXX ad hoc, empirical */
 	}
 	else if (ld.l_type == SUN) {
-		power = (4.0f * ld.l_radius * ld.l_radius * M_2PI) * (1.0 / 12.5); /* Removing area light power*/
+		power = ld.l_radius * ld.l_radius * M_PI; /* Removing area light power*/
+		power /= 1.0f + (ld.l_radius * ld.l_radius * 0.5f);
 		power *= M_PI * 0.5; /* Matching cycles. */
 	}
 	else {
@@ -82,12 +83,12 @@ vec3 light_volume(LightData ld, vec4 l_vector)
 		power *= M_2PI; /* Matching cycles with point light. */
 	}
 
+	power /= (l_vector.w * l_vector.w);
+
 	/* OPTI: find a better way than calculating this on the fly */
 	float lum = dot(ld.l_color, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
 	vec3 tint = (lum > 0.0) ? ld.l_color / lum : vec3(1.0); /* normalize lum. to isolate hue+sat */
 
-	power /= (l_vector.w * l_vector.w);
-
 	lum = min(lum * power, volLightClamp);
 
 	return tint * lum;



More information about the Bf-blender-cvs mailing list