Kaynağa Gözat

[libgdx] Ported new tint black shader. See #1003. @nathansweet please have a look.

badlogic 8 yıl önce
ebeveyn
işleme
2c45dd2f1e

+ 4 - 3
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java

@@ -240,6 +240,7 @@ public class SkeletonRenderer {
 		if (vertexEffect != null) vertexEffect.begin(skeleton);
 
 		boolean premultipliedAlpha = this.premultipliedAlpha;
+		int darkPremultipliedAlpha = (premultipliedAlpha ? 255 : 0) << 24;
 		BlendMode blendMode = null;
 		int verticesLength = 0;
 		float[] vertices = null, uvs = null;
@@ -293,9 +294,9 @@ public class SkeletonRenderer {
 					| (int)(r * lightColor.r * color.r * multiplier));
 				Color darkColor = slot.getDarkColor();
 				if (darkColor == null) darkColor = Color.BLACK;
-				float dark = NumberUtils.intToFloatColor( //
-					((int)(b * darkColor.b * color.b * multiplier) << 16) //
-						| ((int)(g * darkColor.g * color.g * multiplier) << 8) //
+				float dark = darkColor == null ? 0 : NumberUtils.intToFloatColor(darkPremultipliedAlpha // 
+						| (int)(b * darkColor.b * color.b * multiplier) << 16 //
+						| (int)(g * darkColor.g * color.g * multiplier) << 8 //
 						| (int)(r * darkColor.r * color.r * multiplier));
 
 				BlendMode slotBlendMode = slot.data.getBlendMode();

+ 1 - 1
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/TwoColorPolygonBatch.java

@@ -219,7 +219,7 @@ public class TwoColorPolygonBatch {
 			+ "{\n" //
 			+ "  vec4 texColor = texture2D(u_texture, v_texCoords);\n" //
 			+ "  gl_FragColor.a = texColor.a * v_light.a;\n" //
-			+ "  gl_FragColor.rgb = (1.0 - texColor.rgb) * v_dark * gl_FragColor.a + texColor.rgb * v_light.rgb;\n" //
+			+ "  gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;\n" //
 			+ "}";
 
 		ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);