Browse Source

[xna] Added ZSpacing parameter at SkeletonRenderer.

Harald Csaszar 5 years ago
parent
commit
8558aa6258
1 changed files with 8 additions and 1 deletions
  1. 8 1
      spine-xna/src/SkeletonRenderer.cs

+ 8 - 1
spine-xna/src/SkeletonRenderer.cs

@@ -56,6 +56,12 @@ namespace Spine {
 		private bool premultipliedAlpha;
 		public bool PremultipliedAlpha { get { return premultipliedAlpha; } set { premultipliedAlpha = value; } }
 
+		/// <summary>Attachments are rendered back to front in the x/y plane by the SkeletonRenderer.
+		/// Each attachment is offset by a customizable z-spacing value on the z-axis to avoid z-fighting
+		/// in shaders with ZWrite enabled. Typical values lie in the range [-0.1, 0].</summary>
+		private float zSpacing = 0.0f;
+		public float ZSpacing { get { return zSpacing; } set { zSpacing = value; } }
+
 		public SkeletonRenderer (GraphicsDevice device) {
 			this.device = device;
 
@@ -100,6 +106,7 @@ namespace Spine {
 			for (int i = 0, n = drawOrder.Count; i < n; i++) {
 				Slot slot = drawOrderItems[i];
 				Attachment attachment = slot.Attachment;
+				float attachmentZOffset = zSpacing * i;
 
 				float attachmentColorR, attachmentColorG, attachmentColorB, attachmentColorA;
 				Texture2D texture = null;
@@ -199,7 +206,7 @@ namespace Spine {
 					itemVertices[ii].Color2 = darkColor;
 					itemVertices[ii].Position.X = vertices[v];
 					itemVertices[ii].Position.Y = vertices[v + 1];
-					itemVertices[ii].Position.Z = 0;
+					itemVertices[ii].Position.Z = attachmentZOffset;
 					itemVertices[ii].TextureCoordinate.X = uvs[v];
 					itemVertices[ii].TextureCoordinate.Y = uvs[v + 1];
 					if (VertexEffect != null) VertexEffect.Transform(ref itemVertices[ii]);