[cocos2d-x] Ported new tint black shader. See #1003.

This commit is contained in:
badlogic 2017-09-30 09:43:19 +02:00
parent 2c45dd2f1e
commit f9245031a6
2 changed files with 8 additions and 6 deletions

View File

@ -227,6 +227,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
Color4F color; Color4F color;
Color4F darkColor; Color4F darkColor;
float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0;
AttachmentVertices* attachmentVertices = nullptr; AttachmentVertices* attachmentVertices = nullptr;
TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr; TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) { for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
@ -317,6 +318,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
darkColor.g = 0; darkColor.g = 0;
darkColor.b = 0; darkColor.b = 0;
} }
darkColor.a = darkPremultipliedAlpha;
color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255; color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255;
// skip rendering if the color of this attachment is 0 // skip rendering if the color of this attachment is 0
@ -482,7 +484,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
vertex->color2.r = (GLubyte)(darkCopy.r * 255); vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255); vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255); vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = 1; vertex->color2.a = (GLubyte)darkColor.a;
} }
} else { } else {
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) { for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {
@ -498,7 +500,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
vertex->color2.r = (GLubyte)darkColor.r; vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g; vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b; vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = 1; vertex->color2.a = (GLubyte)darkColor.a;
} }
} }
} else { } else {
@ -528,7 +530,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
vertex->color2.r = (GLubyte)(darkCopy.r * 255); vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255); vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255); vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = 1; vertex->color2.a = (GLubyte)darkColor.a;
} }
} else { } else {
for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) { for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {
@ -540,7 +542,7 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
vertex->color2.r = (GLubyte)darkColor.r; vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g; vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b; vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = 1; vertex->color2.a = (GLubyte)darkColor.a;
} }
} }
} }

View File

@ -143,8 +143,8 @@ varying vec2 v_texCoord;
void main() { void main() {
vec4 texColor = texture2D(CC_Texture0, v_texCoord); vec4 texColor = texture2D(CC_Texture0, v_texCoord);
float alpha = texColor.a * v_light.a; float alpha = texColor.a * v_light.a;
gl_FragColor.a = alpha; gl_FragColor.a = alpha;
gl_FragColor.rgb = (1.0 - texColor.rgb) * v_dark.rgb * alpha + texColor.rgb * v_light.rgb; gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
} }
); );