From ef07638eef4ce0d7410b19965bc6725d897a1ef2 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 30 Aug 2023 08:43:36 -0700 Subject: [PATCH] Properly apply emissive to masked materials (#7122) * Properly apply emissive to masked materials The emissive property should not be multiplied by the color alpha in masked materials. The alpha is treated as a coverage value in that case, not an opacity value. * Update release notes --- NEW_RELEASE_NOTES.md | 2 ++ shaders/src/shading_lit.fs | 5 ++++- shaders/src/shading_unlit.fs | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEW_RELEASE_NOTES.md b/NEW_RELEASE_NOTES.md index df4c465690..c3eca02fda 100644 --- a/NEW_RELEASE_NOTES.md +++ b/NEW_RELEASE_NOTES.md @@ -9,3 +9,5 @@ appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md). ## Release notes for next branch cut - `setFrameCompletedCallback` now takes a `backend::CallbackHandler`. +- The `emissive` property was not applied properly to `MASKED` materials, and could cause + dark fringes to appear diff --git a/shaders/src/shading_lit.fs b/shaders/src/shading_lit.fs index 7a1d4e7b67..72b2b9ec33 100644 --- a/shaders/src/shading_lit.fs +++ b/shaders/src/shading_lit.fs @@ -299,7 +299,10 @@ void addEmissive(const MaterialInputs material, inout vec4 color) { #if defined(MATERIAL_HAS_EMISSIVE) highp vec4 emissive = material.emissive; highp float attenuation = mix(1.0, getExposure(), emissive.w); - color.rgb += emissive.rgb * (attenuation * color.a); +#if defined(BLEND_MODE_TRANSPARENT) || defined(BLEND_MODE_FADE) + attenuation *= color.a; +#endif + color.rgb += emissive.rgb * attenuation; #endif } diff --git a/shaders/src/shading_unlit.fs b/shaders/src/shading_unlit.fs index af30ddd7db..a98cf60203 100644 --- a/shaders/src/shading_unlit.fs +++ b/shaders/src/shading_unlit.fs @@ -2,7 +2,10 @@ void addEmissive(const MaterialInputs material, inout vec4 color) { #if defined(MATERIAL_HAS_EMISSIVE) highp vec4 emissive = material.emissive; highp float attenuation = mix(1.0, getExposure(), emissive.w); - color.rgb += emissive.rgb * (attenuation * color.a); +#if defined(BLEND_MODE_TRANSPARENT) || defined(BLEND_MODE_FADE) + attenuation *= color.a; +#endif + color.rgb += emissive.rgb * attenuation; #endif }