From 4edbf5bd8e4e3f7269e29956098cf1fdf72dcfb3 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Wed, 7 Aug 2024 17:02:23 +0800 Subject: [PATCH] Opacity already includes the alpha value from the color. The batcher2d's walk function implements the calculation of opacity. (#17509) * Web's opacity already includes the alpha value from the color. The batcher2d's walk function implements the calculation of opacity. --- cocos/spine/assembler/simple.ts | 2 +- cocos/spine/skeleton.ts | 2 +- .../spine-creator-support/SkeletonCacheAnimation.cpp | 2 +- .../spine-creator-support/SkeletonRenderer.cpp | 2 +- platforms/native/engine/jsb-spine-skeleton.js | 5 ++++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index 3947922217..660ae7a5ca 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -284,7 +284,7 @@ function cacheTraverse (comp: Skeleton): void { _nodeR = nodeColor.r / 255; _nodeG = nodeColor.g / 255; _nodeB = nodeColor.b / 255; - _nodeA = nodeColor.a * opacity / 255; + _nodeA = opacity; for (let i = 0; i < vc; i++) { const index = i * _byteStrideTwoColor + 5 * Float32Array.BYTES_PER_ELEMENT; const R = vUint8Buf[index]; diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index a29a6b0564..27daeb4fd3 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1665,7 +1665,7 @@ export class Skeleton extends UIRenderer { const r = this._color.r / 255.0; const g = this._color.g / 255.0; const b = this._color.b / 255.0; - this._instance!.setColor(r, g, b, a * this._color.a / 255.0); + this._instance!.setColor(r, g, b, a); } /** diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp index 3e51527c10..a423e86bf8 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp @@ -238,7 +238,7 @@ void SkeletonCacheAnimation::render(float /*dt*/) { } auto handleColor = [&](SkeletonCache::ColorData *colorData) { - tempA = colorData->finalColor.a * _nodeColor.a * _entity->getOpacity(); + tempA = colorData->finalColor.a * _entity->getOpacity(); multiplier = _premultipliedAlpha ? tempA / 255 : 1; tempR = _nodeColor.r * multiplier; tempG = _nodeColor.g * multiplier; diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp index 07bd1f6655..6b7bf607ec 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp @@ -543,7 +543,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) { continue; } - color.a = _skeleton->getColor().a * slot->getColor().a * color.a * _nodeColor.a * _entity->getOpacity() * 255; + color.a = _skeleton->getColor().a * slot->getColor().a * color.a * _entity->getOpacity() * 255; // skip rendering if the color of this attachment is 0 if (color.a == 0) { _clipper->clipEnd(*slot); diff --git a/platforms/native/engine/jsb-spine-skeleton.js b/platforms/native/engine/jsb-spine-skeleton.js index bb72beae90..1f3ba21486 100644 --- a/platforms/native/engine/jsb-spine-skeleton.js +++ b/platforms/native/engine/jsb-spine-skeleton.js @@ -364,7 +364,10 @@ const cacheManager = require('./jsb-cache-manager'); skeleton._updateColor = function () { if (this._nativeSkeleton) { - const compColor = this.color; + const compColor = this._color; + this.setEntityColorDirty(true); + this.setEntityColor(compColor); + this.setEntityOpacity(this.node._uiProps.localOpacity); this._nativeSkeleton.setColor(compColor.r, compColor.g, compColor.b, compColor.a); this.markForUpdateRenderData(); }