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.
This commit is contained in:
Clément Foucault 2018-11-14 15:46:40 +01:00
parent cfb6f14616
commit f3074b96d6
3 changed files with 9 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;