Skip to content

Commit ca34b54

Browse files
committed
Add 2D blend shaders for sprites
1 parent 3f60c3f commit ca34b54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2283
-192
lines changed
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shaders/2D/Add.shader

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Shader "Zigurous/Blending/2D/Add"
2+
{
3+
Properties
4+
{
5+
_Color ("Main Color", Color) = (1,1,1,1)
6+
_MainTex ("Main Texture", 2D) = "white" {}
7+
8+
_BlendColor ("Blend Color", Color) = (1,1,1,1)
9+
_BlendTex ("Blend Texture", 2D) = "white" {}
10+
}
11+
12+
SubShader
13+
{
14+
Tags
15+
{
16+
"RenderType"="Transparent"
17+
"Queue"="Transparent"
18+
}
19+
20+
Blend SrcAlpha OneMinusSrcAlpha
21+
ZWrite off
22+
Cull off
23+
24+
Pass
25+
{
26+
27+
CGPROGRAM
28+
29+
#include "UnityCG.cginc"
30+
#include "../Blending.cginc"
31+
32+
#pragma vertex vert
33+
#pragma fragment frag
34+
35+
sampler2D _MainTex;
36+
sampler2D _BlendTex;
37+
38+
float4 _MainTex_ST;
39+
float4 _BlendTex_ST;
40+
41+
fixed4 _Color;
42+
fixed4 _BlendColor;
43+
44+
struct appdata
45+
{
46+
float4 vertex : POSITION;
47+
float2 uv_MainTex : TEXCOORD0;
48+
float2 uv_BlendTex : TEXCOORD1;
49+
fixed4 color : COLOR;
50+
};
51+
52+
struct v2f
53+
{
54+
float4 position : SV_POSITION;
55+
float2 uv_MainTex : TEXCOORD0;
56+
float2 uv_BlendTex : TEXCOORD1;
57+
fixed4 color : COLOR;
58+
};
59+
60+
v2f vert(appdata v)
61+
{
62+
v2f o;
63+
o.position = UnityObjectToClipPos(v.vertex);
64+
o.uv_MainTex = TRANSFORM_TEX(v.uv_MainTex, _MainTex);
65+
o.uv_BlendTex = TRANSFORM_TEX(v.uv_BlendTex, _BlendTex);
66+
o.color = v.color;
67+
return o;
68+
}
69+
70+
fixed4 frag(v2f i) : SV_TARGET
71+
{
72+
fixed4 a = tex2D(_MainTex, i.uv_MainTex) * _Color;
73+
fixed4 b = tex2D(_BlendTex, i.uv_BlendTex) * _BlendColor;
74+
75+
return fixed4(lerp(a, add(a, b), _BlendColor.a), a.a) * i.color;
76+
}
77+
78+
ENDCG
79+
}
80+
81+
}
82+
83+
}

Shaders/2D/Add.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shaders/2D/Average.shader

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Shader "Zigurous/Blending/2D/Average"
2+
{
3+
Properties
4+
{
5+
_Color ("Main Color", Color) = (1,1,1,1)
6+
_MainTex ("Main Texture", 2D) = "white" {}
7+
8+
_BlendColor ("Blend Color", Color) = (1,1,1,1)
9+
_BlendTex ("Blend Texture", 2D) = "white" {}
10+
}
11+
12+
SubShader
13+
{
14+
Tags
15+
{
16+
"RenderType"="Transparent"
17+
"Queue"="Transparent"
18+
}
19+
20+
Blend SrcAlpha OneMinusSrcAlpha
21+
ZWrite off
22+
Cull off
23+
24+
Pass
25+
{
26+
27+
CGPROGRAM
28+
29+
#include "UnityCG.cginc"
30+
#include "../Blending.cginc"
31+
32+
#pragma vertex vert
33+
#pragma fragment frag
34+
35+
sampler2D _MainTex;
36+
sampler2D _BlendTex;
37+
38+
float4 _MainTex_ST;
39+
float4 _BlendTex_ST;
40+
41+
fixed4 _Color;
42+
fixed4 _BlendColor;
43+
44+
struct appdata
45+
{
46+
float4 vertex : POSITION;
47+
float2 uv_MainTex : TEXCOORD0;
48+
float2 uv_BlendTex : TEXCOORD1;
49+
fixed4 color : COLOR;
50+
};
51+
52+
struct v2f
53+
{
54+
float4 position : SV_POSITION;
55+
float2 uv_MainTex : TEXCOORD0;
56+
float2 uv_BlendTex : TEXCOORD1;
57+
fixed4 color : COLOR;
58+
};
59+
60+
v2f vert(appdata v)
61+
{
62+
v2f o;
63+
o.position = UnityObjectToClipPos(v.vertex);
64+
o.uv_MainTex = TRANSFORM_TEX(v.uv_MainTex, _MainTex);
65+
o.uv_BlendTex = TRANSFORM_TEX(v.uv_BlendTex, _BlendTex);
66+
o.color = v.color;
67+
return o;
68+
}
69+
70+
fixed4 frag(v2f i) : SV_TARGET
71+
{
72+
fixed4 a = tex2D(_MainTex, i.uv_MainTex) * _Color;
73+
fixed4 b = tex2D(_BlendTex, i.uv_BlendTex) * _BlendColor;
74+
75+
return fixed4(lerp(a, average(a, b), _BlendColor.a), a.a) * i.color;
76+
}
77+
78+
ENDCG
79+
}
80+
81+
}
82+
83+
}

Shaders/2D/Average.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shaders/2D/ColorBurn.shader

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Shader "Zigurous/Blending/2D/Color Burn"
2+
{
3+
Properties
4+
{
5+
_Color ("Main Color", Color) = (1,1,1,1)
6+
_MainTex ("Main Texture", 2D) = "white" {}
7+
8+
_BlendColor ("Blend Color", Color) = (1,1,1,1)
9+
_BlendTex ("Blend Texture", 2D) = "white" {}
10+
}
11+
12+
SubShader
13+
{
14+
Tags
15+
{
16+
"RenderType"="Transparent"
17+
"Queue"="Transparent"
18+
}
19+
20+
Blend SrcAlpha OneMinusSrcAlpha
21+
ZWrite off
22+
Cull off
23+
24+
Pass
25+
{
26+
27+
CGPROGRAM
28+
29+
#include "UnityCG.cginc"
30+
#include "../Blending.cginc"
31+
32+
#pragma vertex vert
33+
#pragma fragment frag
34+
35+
sampler2D _MainTex;
36+
sampler2D _BlendTex;
37+
38+
float4 _MainTex_ST;
39+
float4 _BlendTex_ST;
40+
41+
fixed4 _Color;
42+
fixed4 _BlendColor;
43+
44+
struct appdata
45+
{
46+
float4 vertex : POSITION;
47+
float2 uv_MainTex : TEXCOORD0;
48+
float2 uv_BlendTex : TEXCOORD1;
49+
fixed4 color : COLOR;
50+
};
51+
52+
struct v2f
53+
{
54+
float4 position : SV_POSITION;
55+
float2 uv_MainTex : TEXCOORD0;
56+
float2 uv_BlendTex : TEXCOORD1;
57+
fixed4 color : COLOR;
58+
};
59+
60+
v2f vert(appdata v)
61+
{
62+
v2f o;
63+
o.position = UnityObjectToClipPos(v.vertex);
64+
o.uv_MainTex = TRANSFORM_TEX(v.uv_MainTex, _MainTex);
65+
o.uv_BlendTex = TRANSFORM_TEX(v.uv_BlendTex, _BlendTex);
66+
o.color = v.color;
67+
return o;
68+
}
69+
70+
fixed4 frag(v2f i) : SV_TARGET
71+
{
72+
fixed4 a = tex2D(_MainTex, i.uv_MainTex) * _Color;
73+
fixed4 b = tex2D(_BlendTex, i.uv_BlendTex) * _BlendColor;
74+
75+
return fixed4(lerp(a, colorBurn(a, b), _BlendColor.a), a.a) * i.color;
76+
}
77+
78+
ENDCG
79+
}
80+
81+
}
82+
83+
}

Shaders/2D/ColorBurn.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shaders/2D/ColorDodge.shader

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Shader "Zigurous/Blending/2D/Color Dodge"
2+
{
3+
Properties
4+
{
5+
_Color ("Main Color", Color) = (1,1,1,1)
6+
_MainTex ("Main Texture", 2D) = "white" {}
7+
8+
_BlendColor ("Blend Color", Color) = (1,1,1,1)
9+
_BlendTex ("Blend Texture", 2D) = "white" {}
10+
}
11+
12+
SubShader
13+
{
14+
Tags
15+
{
16+
"RenderType"="Transparent"
17+
"Queue"="Transparent"
18+
}
19+
20+
Blend SrcAlpha OneMinusSrcAlpha
21+
ZWrite off
22+
Cull off
23+
24+
Pass
25+
{
26+
27+
CGPROGRAM
28+
29+
#include "UnityCG.cginc"
30+
#include "../Blending.cginc"
31+
32+
#pragma vertex vert
33+
#pragma fragment frag
34+
35+
sampler2D _MainTex;
36+
sampler2D _BlendTex;
37+
38+
float4 _MainTex_ST;
39+
float4 _BlendTex_ST;
40+
41+
fixed4 _Color;
42+
fixed4 _BlendColor;
43+
44+
struct appdata
45+
{
46+
float4 vertex : POSITION;
47+
float2 uv_MainTex : TEXCOORD0;
48+
float2 uv_BlendTex : TEXCOORD1;
49+
fixed4 color : COLOR;
50+
};
51+
52+
struct v2f
53+
{
54+
float4 position : SV_POSITION;
55+
float2 uv_MainTex : TEXCOORD0;
56+
float2 uv_BlendTex : TEXCOORD1;
57+
fixed4 color : COLOR;
58+
};
59+
60+
v2f vert(appdata v)
61+
{
62+
v2f o;
63+
o.position = UnityObjectToClipPos(v.vertex);
64+
o.uv_MainTex = TRANSFORM_TEX(v.uv_MainTex, _MainTex);
65+
o.uv_BlendTex = TRANSFORM_TEX(v.uv_BlendTex, _BlendTex);
66+
o.color = v.color;
67+
return o;
68+
}
69+
70+
fixed4 frag(v2f i) : SV_TARGET
71+
{
72+
fixed4 a = tex2D(_MainTex, i.uv_MainTex) * _Color;
73+
fixed4 b = tex2D(_BlendTex, i.uv_BlendTex) * _BlendColor;
74+
75+
return fixed4(lerp(a, colorDodge(a, b), _BlendColor.a), a.a) * i.color;
76+
}
77+
78+
ENDCG
79+
}
80+
81+
}
82+
83+
}

Shaders/2D/ColorDodge.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)