본문 바로가기

unity3d

[Shader] Circle Transition

WPF 의 Shazzam shader editor 를 보고 포팅 하였다.



데모 (윈도우):  

build.zip







Surface 쉐이더 이용



 

Shader "Custom/Circle_Transition" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_SubTex("sub tex" , 2D) = "white"{}
		_Progress("progress" , float) = 0
		_FuzzyAmount("fuzzy" , float) = 0
		_CircleSize("circle size" , float) = 1
		_Center("center xy" , vector) = (1,1,1,1)
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;
		sampler2D _SubTex;
		float _Progress;
		float _FuzzyAmount;
		float _CircleSize;
		float4 _Center;
		
		struct Input {
			float2 uv_MainTex;
			float4 Color;
			float3 position;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			float radius = - _FuzzyAmount + _Progress + (_CircleSize + 2.0 + _FuzzyAmount);
			float fromCenter = distance(IN.uv_MainTex , _Center);
			float distFromCircle = fromCenter - radius;
			float4 c1 = tex2D(_MainTex , IN.uv_MainTex);
			float4 c2 = tex2D(_SubTex , IN.uv_MainTex);
			float p = saturate((distFromCircle +  _FuzzyAmount)/(2.0 + _FuzzyAmount));
			
			float4 result = lerp(c2 , c1 , p);
			
			half4 c = result;//(1,1,1,1);//tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}