Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Hidden/SDF"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- }
- SubShader
- {
- // No culling or depth
- Cull Off ZWrite Off ZTest Always
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- sampler2D _MainTex;
- fixed4 frag (v2f i) : SV_Target
- {
- float4 col = 0;
- float2 coords = i.uv;
- float sign = tex2D(_MainTex, coords);
- //return sign*0.5+0.5;
- float distance = 10000;
- [unroll]
- for( int x = -10; x<=10; x++ ){
- [unroll]
- for( int y = -10; y<=10; y++ ){
- float value = tex2D(_MainTex, coords + float2(x*(_ScreenParams.z-1), y*(_ScreenParams.w-1))).r;
- //return value;
- if(sign < 0.5 && value > 0.5)
- distance = min(x*x + y*y, distance);
- if(sign > 0.5 && value < 0.5)
- distance = min(x*x + y*y, distance);
- }
- }
- if(sign < 0.5)
- col.r = 0.5-sqrt(distance)/20;
- else
- col.r = 0.5+sqrt(distance)/20;
- return col;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement