diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs
index c4bcfe303..4861ac45c 100644
--- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs
+++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs
@@ -236,19 +236,25 @@ namespace Spine.Unity.AttachmentTools {
/// this array will be used as TextureFormat at the Texture at the respective property.
/// When additionalTextureFormats is null or when its array size is smaller,
/// textureFormat is used where there exists no corresponding array item.
+ /// When additionalTexturePropertyIDsToCopy is non-null,
+ /// this array will be used to determine whether linear or sRGB color space is used at the
+ /// Texture at the respective property. When additionalTextureIsLinear is null, linear color space
+ /// is assumed at every additional Texture element.
+ /// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
+ /// linear color space.
public static void GetRepackedAttachments (List sourceAttachments, List outputAttachments, Material materialPropertySource,
out Material outputMaterial, out Texture2D outputTexture,
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
string newAssetName = "Repacked Attachments", bool clearCache = false, bool useOriginalNonrenderables = true,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
- TextureFormat[] additionalTextureFormats = null) {
+ TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
Shader shader = materialPropertySource == null ? Shader.Find("Spine/Skeleton") : materialPropertySource.shader;
GetRepackedAttachments(sourceAttachments, outputAttachments, shader, out outputMaterial, out outputTexture,
maxAtlasSize, padding, textureFormat, mipmaps, newAssetName,
materialPropertySource, clearCache, useOriginalNonrenderables,
additionalTexturePropertyIDsToCopy, additionalOutputTextures,
- additionalTextureFormats);
+ additionalTextureFormats, additionalTextureIsLinear);
}
///
@@ -268,17 +274,29 @@ namespace Spine.Unity.AttachmentTools {
/// this array will be used as TextureFormat at the Texture at the respective property.
/// When additionalTextureFormats is null or when its array size is smaller,
/// textureFormat is used where there exists no corresponding array item.
+ /// When additionalTexturePropertyIDsToCopy is non-null,
+ /// this array will be used to determine whether linear or sRGB color space is used at the
+ /// Texture at the respective property. When additionalTextureIsLinear is null, linear color space
+ /// is assumed at every additional Texture element.
+ /// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
+ /// linear color space.
public static void GetRepackedAttachments (List sourceAttachments, List outputAttachments, Shader shader,
out Material outputMaterial, out Texture2D outputTexture,
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
string newAssetName = "Repacked Attachments",
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
- TextureFormat[] additionalTextureFormats = null) {
+ TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
if (sourceAttachments == null) throw new System.ArgumentNullException("sourceAttachments");
if (outputAttachments == null) throw new System.ArgumentNullException("outputAttachments");
outputTexture = null;
+ if (additionalTexturePropertyIDsToCopy != null && additionalTextureIsLinear == null) {
+ additionalTextureIsLinear = new bool[additionalTexturePropertyIDsToCopy.Length];
+ for (int i = 0; i < additionalTextureIsLinear.Length; ++i) {
+ additionalTextureIsLinear[i] = true;
+ }
+ }
// Use these to detect and use shared regions.
var existingRegions = new Dictionary();
@@ -317,7 +335,7 @@ namespace Spine.Unity.AttachmentTools {
region.ToTexture(textureFormat, mipmaps) :
region.ToTexture((additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
additionalTextureFormats[i - 1] : textureFormat,
- mipmaps, additionalTexturePropertyIDsToCopy[i - 1]));
+ mipmaps, additionalTexturePropertyIDsToCopy[i - 1], additionalTextureIsLinear[i - 1]));
texturesToPackAtParam[i].Add(regionTexture);
}
@@ -346,9 +364,10 @@ namespace Spine.Unity.AttachmentTools {
for (int i = 0; i < numTextureParamsToRepack; ++i) {
// Fill a new texture with the collected attachment textures.
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize,
- (additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
+ (i > 0 && additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
additionalTextureFormats[i - 1] : textureFormat,
- mipmaps);
+ mipmaps,
+ (i > 0) ? additionalTextureIsLinear[i - 1] : false);
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
var texturesToPack = texturesToPackAtParam[i];
@@ -407,16 +426,22 @@ namespace Spine.Unity.AttachmentTools {
/// this array will be used as TextureFormat at the Texture at the respective property.
/// When additionalTextureFormats is null or when its array size is smaller,
/// textureFormat is used where there exists no corresponding array item.
+ /// When additionalTexturePropertyIDsToCopy is non-null,
+ /// this array will be used to determine whether linear or sRGB color space is used at the
+ /// Texture at the respective property. When additionalTextureIsLinear is null, linear color space
+ /// is assumed at every additional Texture element.
+ /// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
+ /// linear color space.
public static Skin GetRepackedSkin (this Skin o, string newName, Material materialPropertySource, out Material outputMaterial, out Texture2D outputTexture,
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
bool useOriginalNonrenderables = true, bool clearCache = false,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
- TextureFormat[] additionalTextureFormats = null) {
+ TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
return GetRepackedSkin(o, newName, materialPropertySource.shader, out outputMaterial, out outputTexture,
maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource,
clearCache, useOriginalNonrenderables, additionalTexturePropertyIDsToCopy, additionalOutputTextures,
- additionalTextureFormats);
+ additionalTextureFormats, additionalTextureIsLinear);
}
///
@@ -428,7 +453,7 @@ namespace Spine.Unity.AttachmentTools {
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
- TextureFormat[] additionalTextureFormats = null) {
+ TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
outputTexture = null;
@@ -447,7 +472,7 @@ namespace Spine.Unity.AttachmentTools {
}
GetRepackedAttachments(inoutAttachments, inoutAttachments, materialPropertySource, out outputMaterial, out outputTexture,
maxAtlasSize, padding, textureFormat, mipmaps, newName, clearCache, useOriginalNonrenderables,
- additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats);
+ additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats, additionalTextureIsLinear);
int i = 0;
foreach (var originalSkinEntry in o.Attachments) {
var newAttachment = inoutAttachments[i++];
@@ -483,7 +508,7 @@ namespace Spine.Unity.AttachmentTools {
/// Creates a new Texture2D object based on an AtlasRegion.
/// If applyImmediately is true, Texture2D.Apply is called immediately after the Texture2D is filled with data.
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
- int texturePropertyId = 0) {
+ int texturePropertyId = 0, bool linear = false) {
Texture2D output;
@@ -494,7 +519,7 @@ namespace Spine.Unity.AttachmentTools {
Rect r = ar.GetUnityRect();
int width = (int)r.width;
int height = (int)r.height;
- output = new Texture2D(width, height, textureFormat, mipmaps) { name = ar.name };
+ output = new Texture2D(width, height, textureFormat, mipmaps, linear) { name = ar.name };
output.CopyTextureAttributesFrom(sourceTexture);
AtlasUtilities.CopyTexture(sourceTexture, r, output);
CachedRegionTextures.Add(cacheKey, output);
@@ -504,17 +529,21 @@ namespace Spine.Unity.AttachmentTools {
return output;
}
- static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
+ static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat,
+ bool mipmaps = UseMipMaps, bool linear = false) {
+
var spriteTexture = s.texture;
var r = s.textureRect;
- var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps);
+ var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps, linear);
newTexture.CopyTextureAttributesFrom(spriteTexture);
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
return newTexture;
}
- static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
- var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps);
+ static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat,
+ bool mipmaps = UseMipMaps, bool linear = false) {
+
+ var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps, linear);
newTexture.CopyTextureAttributesFrom(t);
AtlasUtilities.CopyTexture(t, new Rect(0, 0, t.width, t.height), newTexture);
return newTexture;