Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix reflection probe intensity not correctly changing specular and ambient contribution

Lander994f4ff35260
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 53314d080fe..5991d0398a8 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -2131,10 +2131,8 @@ void reflection_process(samplerCube reflection_map,
if (exterior) {
reflection.rgb = mix(skybox, reflection.rgb, blend);
}
- reflection.rgb *= intensity;
- reflection.a = blend;
- reflection.rgb *= blend;
-
+ reflection.a = blend * intensity;
+ reflection.rgb *= reflection.a;
reflection_accum += reflection;
#ifndef USE_LIGHTMAP
@@ -2147,8 +2145,8 @@ void reflection_process(samplerCube reflection_map,
ambient_out.rgb = mix(ambient, ambient_out.rgb, blend);
}
- ambient_out.a = blend;
- ambient_out.rgb *= blend;
+ ambient_out.a = blend * intensity;
+ ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
} else if (ref_ambient_mode == REFLECTION_AMBIENT_COLOR) {
vec4 ambient_out;
@@ -2157,8 +2155,8 @@ void reflection_process(samplerCube reflection_map,
ambient_out.rgb = mix(ambient, ambient_out.rgb, blend);
}
- ambient_out.a = blend;
- ambient_out.rgb *= blend;
+ ambient_out.a = blend * intensity;
+ ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
}
#endif // USE_LIGHTMAP
@@ -2589,7 +2587,7 @@ void main() {
#endif // SECOND_REFLECTION_PROBE
if (reflection_accum.a > 0.0) {
- specular_light = reflection_accum.rgb / reflection_accum.a;
+ specular_light = mix(specular_light, reflection_accum.rgb / reflection_accum.a, reflection_accum.a);
}
}
#endif // DISABLE_REFLECTION_PROBE
diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
index c4e5130f5ff..91ffd4ad8af 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
@@ -1358,9 +1358,8 @@ void reflection_process(uint ref_index, vec3 vertex, hvec3 ref_vec, hvec3 normal
vec2 reflection_uv = vec3_to_oct_with_border(local_ref_vec, border_size);
reflection.rgb = hvec3(textureLod(sampler2DArray(reflection_atlas, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec3(reflection_uv, reflections.data[ref_index].index), roughness_lod).rgb) * REFLECTION_MULTIPLIER;
reflection.rgb *= half(reflections.data[ref_index].exposure_normalization);
- reflection.a = reflection_blend;
+ reflection.a = reflection_blend * half(reflections.data[ref_index].intensity);
- reflection.rgb *= half(reflections.data[ref_index].intensity);
reflection.rgb *= reflection.a;
reflection_accum += reflection;
@@ -1390,9 +1389,8 @@ void reflection_process(uint ref_index, vec3 vertex, hvec3 ref_vec, hvec3 normal
vec2 cc_reflection_uv = vec3_to_oct_with_border(local_cc_ref_vec, border_size);
cc_reflection.rgb = hvec3(textureLod(sampler2DArray(reflection_atlas, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec3(cc_reflection_uv, reflections.data[ref_index].index), cc_roughness_lod).rgb) * REFLECTION_MULTIPLIER;
cc_reflection.rgb *= half(reflections.data[ref_index].exposure_normalization);
- cc_reflection.a = cc_reflection_blend;
+ cc_reflection.a = cc_reflection_blend * half(reflections.data[ref_index].intensity);
- cc_reflection.rgb *= half(reflections.data[ref_index].intensity);
cc_reflection.rgb *= cc_reflection.a;
cc_reflection_accum += cc_reflection;
@@ -1416,7 +1414,7 @@ void reflection_process(uint ref_index, vec3 vertex, hvec3 ref_vec, hvec3 normal
vec2 ambient_uv = vec3_to_oct_with_border(local_amb_vec, border_size);
ambient_out.rgb = hvec3(textureLod(sampler2DArray(reflection_atlas, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec3(ambient_uv, reflections.data[ref_index].index), roughness_lod).rgb);
ambient_out.rgb *= half(reflections.data[ref_index].exposure_normalization);
- ambient_out.a = ambient_blend;
+ ambient_out.a = ambient_blend * half(reflections.data[ref_index].intensity);
ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
} break;
@@ -1425,7 +1423,7 @@ void reflection_process(uint ref_index, vec3 vertex, hvec3 ref_vec, hvec3 normal
half ambient_blend = max(half(0.0), blend - ambient_accum.a);
ambient_out.rgb = hvec3(reflections.data[ref_index].ambient);
- ambient_out.a = ambient_blend;
+ ambient_out.a = ambient_blend * half(reflections.data[ref_index].intensity);
ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
} break;