Last active
August 29, 2015 14:18
-
-
Save efruchter/46702470e01b6aea3a78 to your computer and use it in GitHub Desktop.
cuts two alpha holes in a texture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Expiremental/CircleCutout" | |
{ | |
Properties | |
{ | |
[PerRendererData] x1 ("1.x", Float) = 0 | |
[PerRendererData] y1 ("1.y", Float) = 0 | |
[PerRendererData] x2 ("2.x", Float) = 0 | |
[PerRendererData] y2 ("2.y", Float) = 0 | |
[PerRendererData] size1 ("Size1", float) = 2 | |
[PerRendererData] size2 ("Size2", float) = 2 | |
[PerRendererData] falloffMult ("Falloff", float) = 3 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 wpos : TEXCOORD1; | |
}; | |
v2f vert(appdata_t IN) | |
{ | |
v2f OUT; | |
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); | |
float3 worldPos = mul (_Object2World, IN.vertex).xyz; | |
OUT.wpos = worldPos; | |
return OUT; | |
} | |
float x1; | |
float x2; | |
float y1; | |
float y2; | |
float size1; | |
float size2; | |
float falloffMult; | |
fixed4 frag(v2f IN) : SV_Target | |
{ | |
fixed4 c = fixed4(0.0, 0.0, 0.0, 1.0); | |
c.a *= pow(min(size1, distance(IN.wpos.xy, fixed2(x1, y1))) / size1, falloffMult); | |
c.a *= pow(min(size2, distance(IN.wpos.xy, fixed2(x2, y2))) / size2, falloffMult); | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Expiremental/CircleCutout2/RGBA" | |
{ | |
Properties | |
{ | |
[PerRendererData] x1 ("1.x", Float) = 0 | |
[PerRendererData] y1 ("1.y", Float) = 0 | |
[PerRendererData] x2 ("2.x", Float) = 0 | |
[PerRendererData] y2 ("2.y", Float) = 0 | |
[PerRendererData] size1 ("Size1", float) = 2 | |
[PerRendererData] size2 ("Size2", float) = 2 | |
[PerRendererData] falloffMult ("Falloff", float) = 3 | |
_MainTex ("Base (RGBA)", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 wpos : TEXCOORD1; | |
half2 texcoord : TEXCOORD0; | |
}; | |
v2f vert(appdata_t IN) | |
{ | |
v2f OUT; | |
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); | |
OUT.wpos = mul (_Object2World, IN.vertex).xyz; | |
OUT.texcoord = IN.texcoord; | |
return OUT; | |
} | |
float x1; | |
float x2; | |
float y1; | |
float y2; | |
float size1; | |
float size2; | |
float falloffMult; | |
uniform sampler2D _MainTex; | |
fixed4 frag(v2f IN) : SV_Target | |
{ | |
fixed4 c = tex2D(_MainTex, IN.texcoord); | |
c.a *= pow(min(size1, distance(IN.wpos.xy, fixed2(x1, y1))) / size1, falloffMult); | |
c.a *= pow(min(size2, distance(IN.wpos.xy, fixed2(x2, y2))) / size2, falloffMult); | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment