1. 程式人生 > >Shader2.0-簡單的邊框的實現

Shader2.0-簡單的邊框的實現

Shader "Hidden/TestStruct"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_Width("Width",float)=1.2
		_Color("Color",Color)=(1,0,0,1)
	}
	SubShader
	{

		Pass
		{
			CGPROGRAM  
			#pragma vertex vert  
			#pragma fragment frag	
			
			#include "UnityCG.cginc"	
			sampler2D _MainTex;
			float _Width;
			float4 _Color;
			struct appdata
			{
				float4 vertex : POSITION;	
				float2 uv : TEXCOORD0;	
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;	
			};

			
			v2f vert (appdata v)
			{
				v2f o;
				v.vertex *= _Width;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target	
			{
				return _Color;
			}
			ENDCG
		}

		Pass
		{
			ZTest Always
			CGPROGRAM
			#pragma vertex vert  
			#pragma fragment frag	

			#include "UnityCG.cginc"	
			
			sampler2D _MainTex;
			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;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				return tex2D(_MainTex, i.uv);
			}
			ENDCG
		}
	}
}