diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-06-07 18:49:58 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-06-07 21:51:40 +0300 |
commit | fb03f50e069d66c99391e4796e1b9eaa2b4cc133 (patch) | |
tree | 10c761cf548c6d4aa9160eed7c2798a96b798ccb /source/blender/draw/modes/shaders/object_empty_image_frag.glsl | |
parent | d05f27c7b95371db9e7e4e34a919a3623682a114 (diff) |
Fix T64625: Eevee image textures with alpha have dark edges
Now texture storage of images is defined by the alpha mode of the image. The
downside of this is that there can be artifacts near alpha edges where pixels
with zero alpha bleed in. It also adds more code complexity since image textures
are no longer all stored the same way.
This changes allows us to keep using sRGB texture formats, which have edge
darkening when stored with premultiplied alpha. Game engines seems to generally
do the same thing, and we want to be compatible with them.
Diffstat (limited to 'source/blender/draw/modes/shaders/object_empty_image_frag.glsl')
-rw-r--r-- | source/blender/draw/modes/shaders/object_empty_image_frag.glsl | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/source/blender/draw/modes/shaders/object_empty_image_frag.glsl b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl index deb82a8904e..88220140aec 100644 --- a/source/blender/draw/modes/shaders/object_empty_image_frag.glsl +++ b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl @@ -9,6 +9,7 @@ out vec4 fragColor; #ifndef USE_WIRE uniform sampler2D image; +uniform bool imagePremultiplied; #endif uniform int depthMode; @@ -24,11 +25,15 @@ float linearrgb_to_srgb(float c) } } -vec4 texture_read_as_srgb(sampler2D tex, vec2 co) +vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co) { /* By convention image textures return scene linear colors, but * overlays still assume srgb. */ vec4 color = texture(tex, co); + /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */ + if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) { + color.rgb = color.rgb / color.a; + } color.r = linearrgb_to_srgb(color.r); color.g = linearrgb_to_srgb(color.g); color.b = linearrgb_to_srgb(color.b); @@ -40,7 +45,7 @@ void main() #ifdef USE_WIRE fragColor = finalColor; #else - vec4 tex_col = texture_read_as_srgb(image, texCoord_interp); + vec4 tex_col = texture_read_as_srgb(image, imagePremultiplied, texCoord_interp); fragColor = finalColor * tex_col; if (useAlphaTest) { |