diff --git a/spine-xna/src/SkeletonRenderer.cs b/spine-xna/src/SkeletonRenderer.cs index 5da513870..d24bd3a51 100644 --- a/spine-xna/src/SkeletonRenderer.cs +++ b/spine-xna/src/SkeletonRenderer.cs @@ -56,6 +56,12 @@ namespace Spine { private bool premultipliedAlpha; public bool PremultipliedAlpha { get { return premultipliedAlpha; } set { premultipliedAlpha = value; } } + /// 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]. + 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]);