mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[cocos2dx] Tint black did not work, didn't multiple dark color with skeleton/attachment color. Closes #1158.
This commit is contained in:
parent
a578be88e0
commit
ce536558e5
@ -266,6 +266,11 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();
|
||||
bool isTwoColorTint = this->isTwoColorTint();
|
||||
|
||||
// Early exit if the skeleton is invisible
|
||||
if (getDisplayedOpacity() == 0 || _skeleton->color.a == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
if (_effect) _effect->begin(_effect, _skeleton);
|
||||
|
||||
Color4F nodeColor;
|
||||
@ -276,7 +281,6 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
|
||||
Color4F color;
|
||||
Color4F darkColor;
|
||||
float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0;
|
||||
AttachmentVertices* attachmentVertices = nullptr;
|
||||
TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
|
||||
bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true;
|
||||
@ -301,6 +305,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
continue;
|
||||
}
|
||||
|
||||
// Early exit if slot is invisible
|
||||
if (slot->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
cocos2d::TrianglesCommand::Triangles triangles;
|
||||
TwoColorTriangles trianglesTwoColor;
|
||||
|
||||
@ -309,6 +319,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
attachmentVertices = getAttachmentVertices(attachment);
|
||||
|
||||
// Early exit if attachment is invisible
|
||||
if (attachment->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isTwoColorTint) {
|
||||
triangles.indices = attachmentVertices->_triangles->indices;
|
||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||
@ -338,6 +354,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
|
||||
attachmentVertices = getAttachmentVertices(attachment);
|
||||
|
||||
// Early exit if attachment is invisible
|
||||
if (attachment->color.a == 0) {
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isTwoColorTint) {
|
||||
triangles.indices = attachmentVertices->_triangles->indices;
|
||||
triangles.indexCount = attachmentVertices->_triangles->indexCount;
|
||||
@ -375,27 +397,33 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
continue;
|
||||
}
|
||||
|
||||
float alpha = nodeColor.a * _skeleton->color.a * slot->color.a * color.a * 255;
|
||||
// skip rendering if the color of this attachment is 0
|
||||
if (alpha == 0){
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
float multiplier = _premultipliedAlpha ? alpha : 255;
|
||||
|
||||
float red = nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;
|
||||
float green = nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;
|
||||
float blue = nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;
|
||||
|
||||
color.r = red * color.r;
|
||||
color.g = green * color.g;
|
||||
color.b = blue * color.b;
|
||||
color.a = alpha;
|
||||
|
||||
if (slot->darkColor) {
|
||||
darkColor.r = slot->darkColor->r * 255;
|
||||
darkColor.g = slot->darkColor->g * 255;
|
||||
darkColor.b = slot->darkColor->b * 255;
|
||||
darkColor.r = red * slot->darkColor->r;
|
||||
darkColor.g = green * slot->darkColor->g;
|
||||
darkColor.b = blue * slot->darkColor->b;
|
||||
} else {
|
||||
darkColor.r = 0;
|
||||
darkColor.g = 0;
|
||||
darkColor.b = 0;
|
||||
}
|
||||
darkColor.a = darkPremultipliedAlpha;
|
||||
|
||||
color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255;
|
||||
// skip rendering if the color of this attachment is 0
|
||||
if (color.a == 0){
|
||||
spSkeletonClipping_clipEnd(_clipper, slot);
|
||||
continue;
|
||||
}
|
||||
float multiplier = _premultipliedAlpha ? color.a : 255;
|
||||
color.r *= nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;
|
||||
color.g *= nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;
|
||||
color.b *= nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;
|
||||
darkColor.a = _premultipliedAlpha ? 255 : 0;
|
||||
|
||||
BlendFunc blendFunc;
|
||||
switch (slot->data->blendMode) {
|
||||
@ -533,7 +561,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
dark.r = darkColor.r / 255.0f;
|
||||
dark.g = darkColor.g / 255.0f;
|
||||
dark.b = darkColor.b / 255.0f;
|
||||
dark.a = darkColor.a / 255.0f;
|
||||
// dark.a = darkColor.a / 255.0f;
|
||||
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
|
||||
V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;
|
||||
spColor lightCopy = light;
|
||||
@ -596,7 +624,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
|
||||
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
|
||||
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
|
||||
vertex->color2.a = (GLubyte)darkColor.a;
|
||||
// vertex->color2.a = (GLubyte)darkColor.a;
|
||||
}
|
||||
} else {
|
||||
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
|
||||
@ -894,3 +922,4 @@ bool SkeletonRenderer::isOpacityModifyRGB () const {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user