From db3222aa51291395fa4e6cc2f53c8a28426c9661 Mon Sep 17 00:00:00 2001 From: Oliver Smith <991572+all-iver@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:12:21 -0700 Subject: [PATCH 1/2] Send linear colors to the material --- Assets/Shapes2D/Scripts/Shape.cs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Assets/Shapes2D/Scripts/Shape.cs b/Assets/Shapes2D/Scripts/Shape.cs index f6fcd29..1314072 100644 --- a/Assets/Shapes2D/Scripts/Shape.cs +++ b/Assets/Shapes2D/Scripts/Shape.cs @@ -826,13 +826,24 @@ void ApplyShaderPropertiesToMaterial(Material material, bool disableBlending = f material.SetFloat("_YScale", shaderSettings.yScale); material.SetFloat("_OutlineSize", shaderSettings.outlineSize); material.SetFloat("_Blur", shaderSettings.blur); - material.SetColor("_OutlineColor", shaderSettings.outlineColor); + // Colors from the inspector are in sRGB, but I found a unity forum post that says Unity is supposed to + // convert to linear when you call material.SetColor(). however, we're not getting correct colors in + // linear color space unless we convert to linear here, so I'm not sure where it's going wrong. + var outlineColor = shaderSettings.outlineColor; + var fillColor = shaderSettings.fillColor; + var fillColor2 = shaderSettings.fillColor2; + if (QualitySettings.activeColorSpace == ColorSpace.Linear) { + outlineColor = outlineColor.linear; + fillColor = fillColor.linear; + fillColor2 = fillColor2.linear; + } + material.SetColor("_OutlineColor", outlineColor); if (shaderSettings.fillType >= FillType.SolidColor && shaderSettings.fillType < FillType.Texture) - material.SetColor("_FillColor", shaderSettings.fillColor); + material.SetColor("_FillColor", fillColor); if (shaderSettings.fillType >= FillType.Gradient && shaderSettings.fillType < FillType.Texture) - material.SetColor("_FillColor2", shaderSettings.fillColor2); + material.SetColor("_FillColor2", fillColor2); if (shaderSettings.fillType > FillType.SolidColor) { material.SetFloat("_FillRotation", shaderSettings.fillRotation); material.SetFloat("_FillOffsetX", shaderSettings.fillOffset.x); @@ -923,8 +934,8 @@ public Vector2 GetScale() { bottomLeft = transform.InverseTransformPoint(bottomLeft); topRight = transform.InverseTransformPoint(topRight); bottomRight = transform.InverseTransformPoint(bottomRight); - size.x = Vector3.Distance(topLeft, topRight); - size.y = Vector3.Distance(topLeft, bottomLeft); + size.x = Vector2.Distance(topLeft, topRight); + size.y = Vector2.Distance(topLeft, bottomLeft); size /= image.canvas.scaleFactor; } else { return new Vector2(1, 1); @@ -957,8 +968,8 @@ public Vector2 GetSize() { var scaleFactor = image.canvas.scaleFactor; if (image.canvas.renderMode == RenderMode.ScreenSpaceCamera) scaleFactor = image.canvas.transform.lossyScale.x; - size.x = Vector3.Distance(topLeft, topRight) / scaleFactor; - size.y = Vector3.Distance(topLeft, bottomLeft) / scaleFactor; + size.x = Vector2.Distance(topLeft, topRight) / scaleFactor; + size.y = Vector2.Distance(topLeft, bottomLeft) / scaleFactor; } else { // get the size for normal Transform objects size.x = transform.lossyScale.x; @@ -1065,7 +1076,7 @@ void ComputeShaderProperties() { if (shaderSettings.usePolygonMap) { if (shaderSettings.polyMap == null) { shaderSettings.polyMap = new Texture2D(PolyMapResolution, - PolyMapResolution, TextureFormat.ARGB32, false, true); + PolyMapResolution, TextureFormat.ARGB32, false); shaderSettings.polyMap.filterMode = FilterMode.Point; shaderSettings.polyMap.wrapMode = TextureWrapMode.Clamp; } From 5cec2d3b9cf56d226f08dd955885840b82168249 Mon Sep 17 00:00:00 2001 From: Oliver Smith <991572+all-iver@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:25:55 -0700 Subject: [PATCH 2/2] Revert part of the last commit that accidentally contained old code --- Assets/Shapes2D/Scripts/Shape.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/Shapes2D/Scripts/Shape.cs b/Assets/Shapes2D/Scripts/Shape.cs index 1314072..5291ec2 100644 --- a/Assets/Shapes2D/Scripts/Shape.cs +++ b/Assets/Shapes2D/Scripts/Shape.cs @@ -934,8 +934,8 @@ public Vector2 GetScale() { bottomLeft = transform.InverseTransformPoint(bottomLeft); topRight = transform.InverseTransformPoint(topRight); bottomRight = transform.InverseTransformPoint(bottomRight); - size.x = Vector2.Distance(topLeft, topRight); - size.y = Vector2.Distance(topLeft, bottomLeft); + size.x = Vector3.Distance(topLeft, topRight); + size.y = Vector3.Distance(topLeft, bottomLeft); size /= image.canvas.scaleFactor; } else { return new Vector2(1, 1); @@ -968,8 +968,8 @@ public Vector2 GetSize() { var scaleFactor = image.canvas.scaleFactor; if (image.canvas.renderMode == RenderMode.ScreenSpaceCamera) scaleFactor = image.canvas.transform.lossyScale.x; - size.x = Vector2.Distance(topLeft, topRight) / scaleFactor; - size.y = Vector2.Distance(topLeft, bottomLeft) / scaleFactor; + size.x = Vector3.Distance(topLeft, topRight) / scaleFactor; + size.y = Vector3.Distance(topLeft, bottomLeft) / scaleFactor; } else { // get the size for normal Transform objects size.x = transform.lossyScale.x; @@ -1076,7 +1076,7 @@ void ComputeShaderProperties() { if (shaderSettings.usePolygonMap) { if (shaderSettings.polyMap == null) { shaderSettings.polyMap = new Texture2D(PolyMapResolution, - PolyMapResolution, TextureFormat.ARGB32, false); + PolyMapResolution, TextureFormat.ARGB32, false, true); shaderSettings.polyMap.filterMode = FilterMode.Point; shaderSettings.polyMap.wrapMode = TextureWrapMode.Clamp; }