1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Use correct lightmap coefficients to ensure that the directional lightmap mode looks correct

Also remove the metallic option from directional lightmap as it is guaranteed to return negative numbers in many cases
This commit is contained in:
clayjohn
2024-08-21 00:30:59 -07:00
parent da5f39889f
commit f4ccba7508
6 changed files with 48 additions and 44 deletions

View File

@@ -1450,16 +1450,10 @@ void fragment_shader(in SceneData scene_data) {
vec3 n = normalize(lightmaps.data[ofs].normal_xform * normal);
float en = lightmaps.data[ofs].exposure_normalization;
ambient_light += lm_light_l0 * 0.282095f * en;
ambient_light += lm_light_l1n1 * 0.32573 * n.y * en;
ambient_light += lm_light_l1_0 * 0.32573 * n.z * en;
ambient_light += lm_light_l1p1 * 0.32573 * n.x * en;
if (metallic > 0.01) { // since the more direct bounced light is lost, we can kind of fake it with this trick
vec3 r = reflect(normalize(-vertex), normal);
specular_light += lm_light_l1n1 * 0.32573 * r.y * en;
specular_light += lm_light_l1_0 * 0.32573 * r.z * en;
specular_light += lm_light_l1p1 * 0.32573 * r.x * en;
}
ambient_light += lm_light_l0 * en;
ambient_light += lm_light_l1n1 * n.y * en;
ambient_light += lm_light_l1_0 * n.z * en;
ambient_light += lm_light_l1p1 * n.x * en;
} else {
ambient_light += textureLod(sampler2DArray(lightmap_textures[ofs], SAMPLER_LINEAR_CLAMP), uvw, 0.0).rgb * lightmaps.data[ofs].exposure_normalization;