Additive blending for spine-csharp and spine-xna.

This commit is contained in:
NathanSweet 2013-09-20 14:03:52 +02:00
parent a511e267d2
commit 734505c91c
4 changed files with 16 additions and 6 deletions

View File

@ -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);
}

View File

@ -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 one or more lines are too long

View File

@ -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;