You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Blend Environment glow before tonemapping and change default blend mode to screen.
Additionally, change the minimum `tonemap_white` parameter to `1.0`; users can increase `tonemap_exposure` for a similar effect to decreasing `tonemap_white` below `1.0`. Co-authored-by: Hei <40064911+Lielay9@users.noreply.github.com> Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
@@ -45,6 +45,7 @@ uniform float luminance_multiplier;
|
||||
uniform sampler2D glow_color; // texunit:1
|
||||
uniform vec2 pixel_size;
|
||||
uniform float glow_intensity;
|
||||
uniform float srgb_white;
|
||||
|
||||
vec4 get_glow_color(vec2 uv) {
|
||||
vec2 half_pixel = pixel_size * 0.5;
|
||||
@@ -58,6 +59,10 @@ vec4 get_glow_color(vec2 uv) {
|
||||
color += textureLod(glow_color, uv + vec2(0.0, -half_pixel.y * 2.0), 0.0);
|
||||
color += textureLod(glow_color, uv + vec2(-half_pixel.x, -half_pixel.y), 0.0) * 2.0;
|
||||
|
||||
#ifdef USE_LUMINANCE_MULTIPLIER
|
||||
color = color / luminance_multiplier;
|
||||
#endif
|
||||
|
||||
return color / 12.0;
|
||||
}
|
||||
#endif // USE_GLOW
|
||||
@@ -102,18 +107,38 @@ void main() {
|
||||
vec4 color = texture(source_color, uv_interp);
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW
|
||||
vec4 glow = get_glow_color(uv_interp) * glow_intensity;
|
||||
|
||||
// Just use softlight...
|
||||
glow.rgb = clamp(glow.rgb, vec3(0.0f), vec3(1.0f));
|
||||
color.rgb = max((color.rgb + glow.rgb) - (color.rgb * glow.rgb), vec3(0.0));
|
||||
#endif // USE_GLOW
|
||||
|
||||
#ifdef USE_LUMINANCE_MULTIPLIER
|
||||
color = color / luminance_multiplier;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLOW
|
||||
// Glow blending is performed before srgb_to_linear because
|
||||
// the glow texture was created from a nonlinear sRGB-encoded
|
||||
// scene, so it only makes sense to add this glow to an equally
|
||||
// nonlinear sRGB-encoded scene.
|
||||
|
||||
vec4 glow = get_glow_color(uv_interp) * glow_intensity;
|
||||
|
||||
// Glow always uses the screen blend mode in the Compatibility renderer:
|
||||
|
||||
// Glow cannot be above 1.0 after normalizing and should be non-negative
|
||||
// to produce expected results. It is possible that glow can be negative
|
||||
// if negative lights were used in the scene.
|
||||
// We clamp to srgb_white because glow will be normalized to this range.
|
||||
// Note: srgb_white cannot be smaller than the maximum output value (1.0).
|
||||
glow.rgb = clamp(glow.rgb, 0.0, srgb_white);
|
||||
|
||||
// Normalize to srgb_white range.
|
||||
//glow.rgb /= srgb_white;
|
||||
//color.rgb /= srgb_white;
|
||||
//color.rgb = (color.rgb + glow.rgb) - (color.rgb * glow.rgb);
|
||||
// Expand back to original range.
|
||||
//color.rgb *= srgb_white;
|
||||
|
||||
// The following is a mathematically simplified version of the above.
|
||||
color.rgb = color.rgb + glow.rgb - (color.rgb * glow.rgb / srgb_white);
|
||||
#endif // USE_GLOW
|
||||
|
||||
color.rgb = srgb_to_linear(color.rgb);
|
||||
color.rgb = apply_tonemapping(color.rgb, white);
|
||||
color.rgb = linear_to_srgb(color.rgb);
|
||||
|
||||
Reference in New Issue
Block a user