From 02687d88ca2f03f2d97042492efcf5a1cb522557 Mon Sep 17 00:00:00 2001 From: Byeong Gwan Date: Tue, 22 Apr 2025 20:39:11 +0900 Subject: [PATCH] [iOS] fix additive, normal blending --- spine-ios/Sources/Spine/Metal/SpineRenderer.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spine-ios/Sources/Spine/Metal/SpineRenderer.swift b/spine-ios/Sources/Spine/Metal/SpineRenderer.swift index 1a89ae6047..17987184d2 100644 --- a/spine-ios/Sources/Spine/Metal/SpineRenderer.swift +++ b/spine-ios/Sources/Spine/Metal/SpineRenderer.swift @@ -294,7 +294,8 @@ fileprivate extension BlendMode { case SPINE_BLEND_MODE_NORMAL: return premultipliedAlpha ? .one : .sourceAlpha case SPINE_BLEND_MODE_ADDITIVE: - return .sourceAlpha + // additvie only needs sourceAlpha multiply if it is not pma + return premultipliedAlpha ? .one : .sourceAlpha case SPINE_BLEND_MODE_MULTIPLY: return .destinationColor case SPINE_BLEND_MODE_SCREEN: @@ -304,12 +305,13 @@ fileprivate extension BlendMode { } } - func sourceAlphaBlendFactor(premultipliedAlpha: Bool) -> MTLBlendFactor { + var sourceAlphaBlendFactor: MTLBlendFactor { + // pma and non-pma has no-relation ship with alpha blending switch self { case SPINE_BLEND_MODE_NORMAL: - return premultipliedAlpha ? .one : .sourceAlpha + return .one case SPINE_BLEND_MODE_ADDITIVE: - return .sourceAlpha + return .one case SPINE_BLEND_MODE_MULTIPLY: return .oneMinusSourceAlpha case SPINE_BLEND_MODE_SCREEN: @@ -355,7 +357,7 @@ fileprivate extension MTLRenderPipelineColorAttachmentDescriptor { func apply(blendMode: BlendMode, with premultipliedAlpha: Bool) { isBlendingEnabled = true sourceRGBBlendFactor = blendMode.sourceRGBBlendFactor(premultipliedAlpha: premultipliedAlpha) - sourceAlphaBlendFactor = blendMode.sourceAlphaBlendFactor(premultipliedAlpha: premultipliedAlpha) + sourceAlphaBlendFactor = blendMode.sourceAlphaBlendFactor destinationRGBBlendFactor = blendMode.destinationRGBBlendFactor destinationAlphaBlendFactor = blendMode.destinationAlphaBlendFactor }