Skip to content

Commit

Permalink
Improve effects shader when fog is enabled
Browse files Browse the repository at this point in the history
Fix visual artifacts with premultiplied effect textures and improve additive blending when fog is enabled.
  • Loading branch information
past-due committed Jul 22, 2024
1 parent 9bc3f31 commit 15d2519
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion data/base/shaders/nolight_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ void main()
}

// Return fragment color
fragColour = mix(fragColour, vec4(fogColor.xyz, fragColour.w), clamp(fogFactor, 0.0, 1.0));
vec3 fogPremultAlphaFactor = mix(vec3(fragColour.a), vec3(1.f,1.f,1.f), vec3(float(alphaTest)));
float fogFactorAdjust = mix(1.f, 0.f, float(alphaTest));
fragColour = vec4(mix(fragColour.rgb, fogColor.rgb * fogPremultAlphaFactor, clamp(fogFactor * fogFactorAdjust, 0.0, 1.0)), fragColour.a);
fragColour.a = fragColour.a * (1.0 - clamp(fogFactor, 0.0, 1.0));
}

#ifdef NEWGL
Expand Down
5 changes: 4 additions & 1 deletion data/base/shaders/vk/nolight_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ void main()
}

// Return fragment color
fragColour = mix(fragColour, vec4(fogColor.xyz, fragColour.w), clamp(fogFactor, 0.0, 1.0));
vec3 fogPremultAlphaFactor = mix(vec3(fragColour.a), vec3(1.f,1.f,1.f), vec3(float(alphaTest)));
float fogFactorAdjust = mix(1.f, 0.f, float(alphaTest));
fragColour = vec4(mix(fragColour.rgb, fogColor.rgb * fogPremultAlphaFactor, clamp(fogFactor * fogFactorAdjust, 0.0, 1.0)), fragColour.a);
fragColour.a = fragColour.a * (1.0 - clamp(fogFactor, 0.0, 1.0));
}

FragColor = fragColour;
Expand Down

0 comments on commit 15d2519

Please sign in to comment.