Skip to content

Commit

Permalink
Merge pull request #61109 from Chaosus/fix_tonemap
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored May 18, 2022
2 parents 2f3a8a3 + 5322b17 commit 4e6f5bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 deletions drivers/gles3/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ vec3 apply_fxaa(vec3 color, vec2 uv_interp, vec2 pixel_size) {
}

void main() {
vec3 color = textureLod(source, uv_interp, 0.0).rgb;
vec4 color = textureLod(source, uv_interp, 0.0);

#ifdef USE_FXAA
color = apply_fxaa(color, uv_interp, pixel_size);
color.rgb = apply_fxaa(color.rgb, uv_interp, pixel_size);
#endif

// Glow
Expand Down Expand Up @@ -296,18 +296,18 @@ void main() {
#endif //USE_MULTI_TEXTURE_GLOW

glow *= glow_intensity;
color = apply_glow(color, glow);
color.rgb = apply_glow(color.rgb, glow);
#endif

// Additional effects

#ifdef USE_BCS
color = apply_bcs(color, bcs);
color.rgb = apply_bcs(color.rgb, bcs);
#endif

#ifdef USE_COLOR_CORRECTION
color = apply_color_correction(color, color_correction);
color.rgb = apply_color_correction(color.rgb, color_correction);
#endif

frag_color = vec4(color, 1.0);
frag_color = color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
Vector<Color> c;
{
Color cc = clear_color.srgb_to_linear();
if (using_separate_specular) {
if (using_separate_specular || render_buffer) {
cc.a = 0; //subsurf scatter must be 0
}
c.push_back(cc);
Expand Down
25 changes: 13 additions & 12 deletions servers/rendering/renderer_rd/shaders/effects/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,13 @@ vec3 screen_space_dither(vec2 frag_coord) {
void main() {
#ifdef SUBPASS
// SUBPASS and MULTIVIEW can be combined but in that case we're already reading from the correct layer
vec3 color = subpassLoad(input_color).rgb * params.luminance_multiplier;
vec4 color = subpassLoad(input_color);
#elif defined(MULTIVIEW)
vec3 color = textureLod(source_color, vec3(uv_interp, ViewIndex), 0.0f).rgb * params.luminance_multiplier;
vec4 color = textureLod(source_color, vec3(uv_interp, ViewIndex), 0.0f);
#else
vec3 color = textureLod(source_color, uv_interp, 0.0f).rgb * params.luminance_multiplier;
vec4 color = textureLod(source_color, uv_interp, 0.0f);
#endif
color.rgb *= params.luminance_multiplier;

// Exposure

Expand All @@ -443,7 +444,7 @@ void main() {
}
#endif

color *= exposure;
color.rgb *= exposure;

// Early Tonemap & SRGB Conversion
#ifndef SUBPASS
Expand All @@ -456,19 +457,19 @@ void main() {
}

if (params.use_fxaa) {
color = do_fxaa(color, exposure, uv_interp);
color.rgb = do_fxaa(color.rgb, exposure, uv_interp);
}
#endif

if (params.use_debanding) {
// For best results, debanding should be done before tonemapping.
// Otherwise, we're adding noise to an already-quantized image.
color += screen_space_dither(gl_FragCoord.xy);
color.rgb += screen_space_dither(gl_FragCoord.xy);
}

color = apply_tonemapping(color, params.white);
color.rgb = apply_tonemapping(color.rgb, params.white);

color = linear_to_srgb(color); // regular linear -> SRGB conversion
color.rgb = linear_to_srgb(color.rgb); // regular linear -> SRGB conversion

#ifndef SUBPASS
// Glow
Expand All @@ -482,19 +483,19 @@ void main() {
glow = apply_tonemapping(glow, params.white);
glow = linear_to_srgb(glow);

color = apply_glow(color, glow);
color.rgb = apply_glow(color.rgb, glow);
}
#endif

// Additional effects

if (params.use_bcs) {
color = apply_bcs(color, params.bcs);
color.rgb = apply_bcs(color.rgb, params.bcs);
}

if (params.use_color_correction) {
color = apply_color_correction(color);
color.rgb = apply_color_correction(color.rgb);
}

frag_color = vec4(color, 1.0f);
frag_color = color;
}

0 comments on commit 4e6f5bf

Please sign in to comment.