Using advise from Matias, left the 0-1 range for lights, divisiom by PI, and multiplied lights by PI internally.

This commit is contained in:
Juan Linietsky 2017-10-01 20:33:38 -03:00
parent c9a925c4e0
commit c864b782c0
2 changed files with 14 additions and 16 deletions

View file

@ -2534,9 +2534,10 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform
float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
//compensate normalized diffuse range by multiplying by PI
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[3] = 0;
//omni, keep at 0
@ -2674,9 +2675,9 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c
float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[3] = 0;
Vector3 pos = p_camera_inverse_transform.xform(li->transform.origin);
@ -2760,9 +2761,9 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c
float sign = li->light_ptr->negative ? -1 : 1;
Color linear_col = li->light_ptr->color.to_linear();
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
ubo_data.light_color_energy[0] = linear_col.r * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[1] = linear_col.g * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[2] = linear_col.b * sign * li->light_ptr->param[VS::LIGHT_PARAM_ENERGY] * M_PI;
ubo_data.light_color_energy[3] = 0;
Vector3 pos = p_camera_inverse_transform.xform(li->transform.origin);

View file

@ -915,7 +915,7 @@ LIGHT_SHADER_CODE
#if defined(DIFFUSE_LAMBERT_WRAP)
//energy conserving lambert wrap shader
light_amount = max(0.0,(dot(N,L) + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
light_amount = max(0.0,(dot(N,L) + roughness) / ((1.0 + roughness) * (1.0 + roughness) * M_PI));
#elif defined(DIFFUSE_OREN_NAYAR)
@ -932,8 +932,7 @@ LIGHT_SHADER_CODE
vec3 A = 1.0 + sigma2 * (- 0.5 / (sigma2 + 0.33) + 0.17*diffuse_color / (sigma2 + 0.13) );
float B = 0.45 * sigma2 / (sigma2 + 0.09);
// light_amount = dotNL * (A + vec3(B) * s / t) / M_PI;
light_amount = dotNL * (A + vec3(B) * s / t);
light_amount = dotNL * (A + vec3(B) * s / t) / M_PI;
}
#elif defined(DIFFUSE_TOON)
@ -953,8 +952,7 @@ LIGHT_SHADER_CODE
float FD90 = 0.5 + 2.0 * LoH * LoH * roughness;
float FdV = 1.0 + (FD90 - 1.0) * SchlickFresnel(NoV);
float FdL = 1.0 + (FD90 - 1.0) * SchlickFresnel(NoL);
//light_amount = ( (1.0 / M_PI) * FdV * FdL ) * NoL;
light_amount = ( FdV * FdL ) * NoL;
light_amount = ( (1.0 / M_PI) * FdV * FdL ) * NoL;
/*
float energyBias = mix(roughness, 0.0, 0.5);
float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
@ -967,8 +965,7 @@ LIGHT_SHADER_CODE
}
#else
//lambert
// light_amount = dotNL / M_PI;
light_amount = dotNL;
light_amount = dotNL / M_PI;
#endif
#if defined(TRANSMISSION_USED)