Skip to content

Commit

Permalink
Improve color blending
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbjørn Thirslund committed Feb 14, 2015
1 parent 22e4d3e commit 974cb87
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 4,351 deletions.
232 changes: 116 additions & 116 deletions Assets/LayerTest.asset

Large diffs are not rendered by default.

3,115 changes: 0 additions & 3,115 deletions Assets/Pixel Image.asset

This file was deleted.

4 changes: 0 additions & 4 deletions Assets/Pixel Image.asset.meta

This file was deleted.

54 changes: 4 additions & 50 deletions Assets/TestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -74,56 +74,6 @@ NavMeshSettings:
widthInaccuracy: 16.666666
heightInaccuracy: 10
m_NavMesh: {fileID: 0}
--- !u!1 &1763870612
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1763870614}
- 212: {fileID: 1763870613}
m_Layer: 0
m_Name: Pixel Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &1763870613
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1763870612}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_LightmapIndex: 255
m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
m_Materials:
- {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 0
m_LightProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_SortingLayer: 0
m_SortingOrder: 0
m_SortingLayerID: 0
m_Sprite: {fileID: 21300000, guid: e5b83bcc7cf5d1b4a837c63f6def78fe, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
--- !u!4 &1763870614
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1763870612}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: .184287488, y: .393926561, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
--- !u!1 &2058043185
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -191,8 +141,11 @@ Camera:
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
--- !u!4 &2058043190
Transform:
m_ObjectHideFlags: 0
Expand All @@ -204,3 +157,4 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
14 changes: 7 additions & 7 deletions Assets/UPAToolkit/Editor/UPAImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ public Color GetBlendedPixel (int x, int y) {

Color pixel = layers[i].tex.GetPixel(x,y);

// APPLY THE NORMAL COLOR BLENDING ALGORITHM
// This is a blend between two methods of calculating color blending; Alpha blending and premultiplied alpha blending
// I have no clue why this actually works but it's very accurate :D
float newR = Mathf.Lerp (1f * pixel.r + (1f - pixel.a) * color.r, pixel.a * pixel.r + (1f - pixel.a) * color.r, color.a);
float newG = Mathf.Lerp (1f * pixel.g + (1f - pixel.a) * color.g, pixel.a * pixel.g + (1f - pixel.a) * color.g, color.a);
float newB = Mathf.Lerp (1f * pixel.b + (1f - pixel.a) * color.b, pixel.a * pixel.b + (1f - pixel.a) * color.b, color.a);

// float newR = c.a * c.r + (1 - c.a) * bgColor.r;
// c0 = Ca * Aa + Cb * Ab * (1 - Aa);

float newR = pixel.r + color.r * (1 - pixel.a);
float newG = pixel.g + color.g * (1 - pixel.a);
float newB = pixel.b + color.b * (1 - pixel.a);
float newA = pixel.a + color.a * (1 - pixel.a);

color = new Color (newR, newG, newB, newA);
Expand All @@ -132,6 +130,8 @@ public void ChangeLayerPosition (int from, int to) {
UPALayer layer = layers[from];
layers.RemoveAt(from);
layers.Insert(to, layer);

dirty = true;
}

// Get the rect of the image as displayed in the editor
Expand Down
Binary file modified Assets/UPAToolkit/README.pdf
Binary file not shown.
Loading

0 comments on commit 974cb87

Please sign in to comment.