Browse Source

Additive blending for spine-csharp and spine-xna.

NathanSweet 12 years ago
parent
commit
734505c91c

+ 4 - 1
spine-csharp/src/SkeletonJson.cs

@@ -127,7 +127,10 @@ namespace Spine {
 					}
 
 					if (slotMap.ContainsKey("attachment"))
-						slotData.AttachmentName = (String)slotMap["attachment"];
+						slotData.AttachmentName = (String)slotMap["attachment"];
+
+					if (slotMap.ContainsKey("additive"))
+						slotData.AdditiveBlending = (bool)slotMap["additive"];
 
 					skeletonData.AddSlot(slotData);
 				}

+ 1 - 0
spine-csharp/src/SlotData.cs

@@ -35,6 +35,7 @@ namespace Spine {
 		public float A { get; set; }
 		/** @param attachmentName May be null. */
 		public String AttachmentName { get; set; }
+		public bool AdditiveBlending { get; set; }
 
 		public SlotData (String name, BoneData boneData) {
 			if (name == null) throw new ArgumentNullException("name cannot be null.");

File diff suppressed because it is too large
+ 0 - 0
spine-xna/example/data/spineboy.json


+ 10 - 4
spine-xna/src/SkeletonRenderer.cs

@@ -34,7 +34,7 @@ namespace Spine {
 		SpriteBatcher batcher;
 		BasicEffect effect;
 		RasterizerState rasterizerState;
-		public BlendState BlendState { get; set; }
+		public bool PremultipliedAlpha { get; set; }
 		float[] vertices = new float[8];
 
 		public SkeletonRenderer (GraphicsDevice device) {
@@ -51,14 +51,12 @@ namespace Spine {
 			rasterizerState = new RasterizerState();
 			rasterizerState.CullMode = CullMode.None;
 
-			BlendState = BlendState.AlphaBlend;
-
 			Bone.yDown = true;
 		}
 
 		public void Begin () {
 			device.RasterizerState = rasterizerState;
-			device.BlendState = BlendState;
+			device.BlendState = BlendState.AlphaBlend;
 
 			effect.Projection = Matrix.CreateOrthographicOffCenter(0, device.Viewport.Width, device.Viewport.Height, 0, 1, 0);
 		}
@@ -71,11 +69,19 @@ namespace Spine {
 		}
 
 		public void Draw (Skeleton skeleton) {
+			Console.WriteLine();
+
 			List<Slot> drawOrder = skeleton.DrawOrder;
 			for (int i = 0, n = drawOrder.Count; i < n; i++) {
 				Slot slot = drawOrder[i];
 				RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
 				if (regionAttachment != null) {
+					BlendState blend = slot.Data.AdditiveBlending ? BlendState.Additive : BlendState.AlphaBlend;
+					if (device.BlendState != blend) {
+						End();
+						device.BlendState = blend;
+					}
+
 					SpriteBatchItem item = batcher.CreateBatchItem();
 					AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
 					item.Texture = (Texture2D)region.page.rendererObject;

Some files were not shown because too many files changed in this diff