Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed recent DoF and tonemap bugs #61171

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions drivers/gles2/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ vec4 apply_glow(vec4 color, vec3 glow) { // apply glow using the selected blendi
#ifndef USE_GLOW_SOFTLIGHT // softlight has no effect on black color
// compute the alpha from glow
float a = max(max(glow.r, glow.g), glow.b);
color.a = a + color.a * (1 - a);
color.a = a + color.a * (1.0 - a);
if (color.a == 0.0) {
color.rgb = vec3(0.0);
} else if (color.a < 1.0) {
Expand Down Expand Up @@ -242,10 +242,10 @@ vec4 apply_fxaa(vec4 color, vec2 uv_interp, vec2 pixel_size) {
vec4 rgbSE = texture2DLod(source, uv_interp + vec2(1.0, 1.0) * pixel_size, 0.0);
vec3 rgbM = color.rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW.rgb, luma) - ((1 - rgbNW.a) / 8.0);
float lumaNE = dot(rgbNE.rgb, luma) - ((1 - rgbNE.a) / 8.0);
float lumaSW = dot(rgbSW.rgb, luma) - ((1 - rgbSW.a) / 8.0);
float lumaSE = dot(rgbSE.rgb, luma) - ((1 - rgbSE.a) / 8.0);
float lumaNW = dot(rgbNW.rgb, luma) - ((1.0 - rgbNW.a) / 8.0);
float lumaNE = dot(rgbNE.rgb, luma) - ((1.0 - rgbNE.a) / 8.0);
float lumaSW = dot(rgbSW.rgb, luma) - ((1.0 - rgbSW.a) / 8.0);
float lumaSE = dot(rgbSE.rgb, luma) - ((1.0 - rgbSE.a) / 8.0);
float lumaM = dot(rgbM, luma) - (color.a / 8.0);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
Expand All @@ -267,7 +267,7 @@ vec4 apply_fxaa(vec4 color, vec2 uv_interp, vec2 pixel_size) {
vec4 rgbA = 0.5 * (texture2DLod(source, uv_interp + dir * (1.0 / 3.0 - 0.5), 0.0) + texture2DLod(source, uv_interp + dir * (2.0 / 3.0 - 0.5), 0.0));
vec4 rgbB = rgbA * 0.5 + 0.25 * (texture2DLod(source, uv_interp + dir * -0.5, 0.0) + texture2DLod(source, uv_interp + dir * 0.5, 0.0));

float lumaB = dot(rgbB.rgb, luma) - ((1 - rgbB.a) / 8.0);
float lumaB = dot(rgbB.rgb, luma) - ((1.0 - rgbB.a) / 8.0);
vec4 color_output = ((lumaB < lumaMin) || (lumaB > lumaMax)) ? rgbA : rgbB;
if (color_output.a == 0.0) {
color_output.rgb = vec3(0.0);
Expand Down
3 changes: 2 additions & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,8 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
if (composite_from != storage->frame.current_rt->buffers.diffuse) {
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Alpha was used by the horizontal pass, it should not carry over.
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);

} else {
glActiveTexture(GL_TEXTURE2);
Expand Down
7 changes: 0 additions & 7 deletions drivers/gles3/shaders/effect_blur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ void main() {
vec4 color_accum = vec4(0.0);

float max_accum = 0.0;
float k_accum = 0.0;

for (int i = 0; i < dof_kernel_size; i++) {
int int_ofs = i - dof_kernel_from;
Expand All @@ -250,7 +249,6 @@ void main() {
float tap_k = dof_kernel[i];

vec4 tap_color = textureLod(source_color, tap_uv, 0.0);
float w = tap_color.a;

float tap_depth = texture(dof_source_depth, tap_uv, 0.0).r;
tap_depth = tap_depth * 2.0 - 1.0;
Expand All @@ -270,14 +268,9 @@ void main() {

max_accum = max(max_accum, tap_amount * ofs_influence);

k_accum += w;
tap_color.rgb *= w;
color_accum += tap_color * tap_k;
}

if (k_accum > 0.0) {
color_accum.rgb /= k_accum / dof_kernel_size;
}
color_accum.a = max(color_accum.a, sqrt(max_accum));

#ifdef DOF_NEAR_BLUR_MERGE
Expand Down
12 changes: 6 additions & 6 deletions drivers/gles3/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ vec4 apply_glow(vec4 color, vec3 glow) { // apply glow using the selected blendi
#ifndef USE_GLOW_SOFTLIGHT // softlight has no effect on black color
// compute the alpha from glow
float a = max(max(glow.r, glow.g), glow.b);
color.a = a + color.a * (1 - a);
color.a = a + color.a * (1.0 - a);
if (color.a == 0.0) {
color.rgb = vec3(0.0);
} else if (color.a < 1.0) {
Expand Down Expand Up @@ -330,10 +330,10 @@ vec4 apply_fxaa(vec4 color, float exposure, vec2 uv_interp, vec2 pixel_size) {
vec4 rgbSE = textureLod(source, uv_interp + vec2(1.0, 1.0) * pixel_size, 0.0);
vec3 rgbM = color.rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW.rgb * exposure, luma) - ((1 - rgbNW.a) / 8.0);
float lumaNE = dot(rgbNE.rgb * exposure, luma) - ((1 - rgbNE.a) / 8.0);
float lumaSW = dot(rgbSW.rgb * exposure, luma) - ((1 - rgbSW.a) / 8.0);
float lumaSE = dot(rgbSE.rgb * exposure, luma) - ((1 - rgbSE.a) / 8.0);
float lumaNW = dot(rgbNW.rgb * exposure, luma) - ((1.0 - rgbNW.a) / 8.0);
float lumaNE = dot(rgbNE.rgb * exposure, luma) - ((1.0 - rgbNE.a) / 8.0);
float lumaSW = dot(rgbSW.rgb * exposure, luma) - ((1.0 - rgbSW.a) / 8.0);
float lumaSE = dot(rgbSE.rgb * exposure, luma) - ((1.0 - rgbSE.a) / 8.0);
float lumaM = dot(rgbM * exposure, luma) - (color.a / 8.0);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
Expand All @@ -355,7 +355,7 @@ vec4 apply_fxaa(vec4 color, float exposure, vec2 uv_interp, vec2 pixel_size) {
vec4 rgbA = 0.5 * exposure * (textureLod(source, uv_interp + dir * (1.0 / 3.0 - 0.5), 0.0) + textureLod(source, uv_interp + dir * (2.0 / 3.0 - 0.5), 0.0));
vec4 rgbB = rgbA * 0.5 + 0.25 * exposure * (textureLod(source, uv_interp + dir * -0.5, 0.0) + textureLod(source, uv_interp + dir * 0.5, 0.0));

float lumaB = dot(rgbB.rgb, luma) - ((1 - rgbB.a) / 8.0);
float lumaB = dot(rgbB.rgb, luma) - ((1.0 - rgbB.a) / 8.0);
vec4 color_output = ((lumaB < lumaMin) || (lumaB > lumaMax)) ? rgbA : rgbB;
if (color_output.a == 0.0) {
color_output.rgb = vec3(0.0);
Expand Down