소스 검색

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

badlogic 8 년 전
부모
커밋
f9245031a6
2개의 변경된 파일8개의 추가작업 그리고 6개의 파일을 삭제
  1. 6 4
      spine-cocos2dx/src/spine/SkeletonRenderer.cpp
  2. 2 2
      spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp

+ 6 - 4
spine-cocos2dx/src/spine/SkeletonRenderer.cpp

@@ -227,6 +227,7 @@ 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;
 	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.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
@@ -482,7 +484,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 = 1;
+						vertex->color2.a = (GLubyte)darkColor.a;
 					}
 				} else {
 					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.g = (GLubyte)darkColor.g;
 						vertex->color2.b = (GLubyte)darkColor.b;
-						vertex->color2.a = 1;
+						vertex->color2.a = (GLubyte)darkColor.a;
 					}
 				}
 			} else {
@@ -528,7 +530,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 = 1;
+						vertex->color2.a = (GLubyte)darkColor.a;
 					}
 				} else {
 					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.g = (GLubyte)darkColor.g;
 						vertex->color2.b = (GLubyte)darkColor.b;
-						vertex->color2.a = 1;
+						vertex->color2.a = (GLubyte)darkColor.a;
 					}
 				}
 			}

+ 2 - 2
spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp

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