ソースを参照

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

badlogic 8 年 前
コミット
3f242450cf

+ 1 - 1
spine-cocos2d-objc/src/spine/GLUtils.c

@@ -88,7 +88,7 @@ void main() {
    vec4 texColor = texture2D(texture, v_texCoord);
    vec4 texColor = texture2D(texture, 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;
 }
 }
 );
 );
 
 

+ 4 - 4
spine-cocos2d-objc/src/spine/SkeletonRenderer.m

@@ -192,7 +192,7 @@ static bool handlerQueued = false;
 	unsigned short* triangles = 0;
 	unsigned short* triangles = 0;
 	int trianglesCount = 0;
 	int trianglesCount = 0;
 	float r = 0, g = 0, b = 0, a = 0;
 	float r = 0, g = 0, b = 0, a = 0;
-	float dr = 0, dg = 0, db = 0;
+	float dr = 0, dg = 0, db = 0, da = _premultipliedAlpha ? 1 : 0;
 	for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
 	for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
 		spSlot* slot = _skeleton->drawOrder[i];
 		spSlot* slot = _skeleton->drawOrder[i];
 		if (!slot->attachment) continue;
 		if (!slot->attachment) continue;
@@ -336,7 +336,7 @@ static bool handlerQueued = false;
 							dark.r = dr;
 							dark.r = dr;
 							dark.g = dg;
 							dark.g = dg;
 							dark.b = db;
 							dark.b = db;
-							dark.a = 1;
+							dark.a = da;
 							for (int i = 0; i * 2 < verticesCount; i++, verts++) {
 							for (int i = 0; i * 2 < verticesCount; i++, verts++) {
 								spColor lightCopy = light;
 								spColor lightCopy = light;
 								spColor darkCopy = dark;
 								spColor darkCopy = dark;
@@ -353,7 +353,7 @@ static bool handlerQueued = false;
 								verts->z = vertex.position.z;
 								verts->z = vertex.position.z;
 								verts->w = vertex.position.w;
 								verts->w = vertex.position.w;
 								verts->color = ((unsigned short)(lightCopy.r * 255))| ((unsigned short)(lightCopy.g * 255)) << 8 | ((unsigned short)(lightCopy.b * 255)) <<16 | ((unsigned short)(lightCopy.a * 255)) << 24;
 								verts->color = ((unsigned short)(lightCopy.r * 255))| ((unsigned short)(lightCopy.g * 255)) << 8 | ((unsigned short)(lightCopy.b * 255)) <<16 | ((unsigned short)(lightCopy.a * 255)) << 24;
-								verts->color2 = ((unsigned short)(darkCopy.r * 255)) | ((unsigned short)(darkCopy.g * 255)) << 8 | ((unsigned short)(darkCopy.b * 255)) << 16 | ((unsigned short)(255)) << 24;
+								verts->color2 = ((unsigned short)(darkCopy.r * 255)) | ((unsigned short)(darkCopy.g * 255)) << 8 | ((unsigned short)(darkCopy.b * 255)) << 16 | ((unsigned short)(darkCopy.a * 255)) << 24;
 								
 								
 							}
 							}
 						} else {
 						} else {
@@ -366,7 +366,7 @@ static bool handlerQueued = false;
 								verts->z = vertex.position.z;
 								verts->z = vertex.position.z;
 								verts->w = vertex.position.w;
 								verts->w = vertex.position.w;
 								verts->color = ((unsigned short)(r * 255))| ((unsigned short)(g * 255)) << 8 | ((unsigned short)(b * 255)) <<16 | ((unsigned short)(a * 255)) << 24;
 								verts->color = ((unsigned short)(r * 255))| ((unsigned short)(g * 255)) << 8 | ((unsigned short)(b * 255)) <<16 | ((unsigned short)(a * 255)) << 24;
-								verts->color2 = ((unsigned short)(dr * 255)) | ((unsigned short)(dg * 255)) << 8 | ((unsigned short)(db * 255)) << 16 | ((unsigned short)(255)) << 24;
+								verts->color2 = ((unsigned short)(dr * 255)) | ((unsigned short)(dg * 255)) << 8 | ((unsigned short)(db * 255)) << 16 | ((unsigned short)(da * 255)) << 24;
 								verts->u = uvs[i * 2];
 								verts->u = uvs[i * 2];
 								verts->v = 1 - uvs[i * 2 + 1];
 								verts->v = 1 - uvs[i * 2 + 1];
 							}
 							}