Specular lighting comming from ambient sphere map is now multiplied by PI to be at the same level as normal light specular

This commit is contained in:
Olivier Prat 2017-12-20 11:14:07 +01:00
parent 0e666ce671
commit e8b88cd3f8

View file

@ -22,8 +22,10 @@ vec4 evalSkyboxLight(vec3 direction, float lod) {
<@func declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)@>
vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float gloss) {
return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5.0);
vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float gloss) {
float f = pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5.0);
return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * f;
// return mix(fresnelColor, vec3(1.0), f);
}
<@if supportAmbientMap@>
@ -31,7 +33,7 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float
<@endif@>
vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 fragNormal, float roughness) {
vec3 direction = -reflect(fragEyeDir, fragNormal);
vec3 lightDir = -reflect(fragEyeDir, fragNormal);
vec3 specularLight;
<@if supportIfAmbientMapElseAmbientSphere@>
if (getLightHasAmbientMap(ambient))
@ -40,7 +42,13 @@ vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 f
{
float levels = getLightAmbientMapNumMips(ambient);
float lod = min(((roughness)* levels), levels);
specularLight = evalSkyboxLight(direction, lod).xyz;
specularLight = evalSkyboxLight(lightDir, lod).xyz;
// We multiply specular by Pi to match specular / diffuse normalization in
// LightingModel.slh where diffuse and specular arent divided by Pi (when they should, rigourously
// speaking, based on physical equations). The spherical harmonics evaluation, on
// the other hand, seems to be Pi times stronger than usual. So all in all, everything
// should be at the right level now.
specularLight *= 3.1415926;
}
<@endif@>
<@if supportIfAmbientMapElseAmbientSphere@>
@ -48,11 +56,11 @@ vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 f
<@endif@>
<@if supportAmbientSphere@>
{
specularLight = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), direction).xyz;
specularLight = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), lightDir).xyz;
}
<@endif@>
return specularLight;
return specularLight;
}
<@endfunc@>
@ -67,14 +75,14 @@ float curvatureAO(in float k) {
<@endif@>
void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambient, vec3 eyeDir, vec3 normal,
float roughness, float metallic, vec3 fresnel, vec3 albedo, float obscurance
float roughness, float metallic, vec3 fresnelF0, vec3 albedo, float obscurance
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
// Fresnel
vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, eyeDir, normal, 1.0 - roughness);
vec3 ambientFresnel = fresnelSchlickAmbient(fresnelF0, eyeDir, normal, 1.0 - roughness);
// Diffuse from ambient
diffuse = (1.0 - metallic) * (vec3(1.0) - ambientFresnel) * sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), normal).xyz;
@ -107,8 +115,9 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie
diffuse *= albedo;
}
diffuse *= lightEnergy * isDiffuseEnabled() * isAmbientEnabled();
specular *= lightEnergy * isSpecularEnabled() * isAmbientEnabled();
lightEnergy *= isAmbientEnabled();
diffuse *= lightEnergy * isDiffuseEnabled();
specular *= lightEnergy * isSpecularEnabled();
}
<@endfunc@>