表面着色器(alphatest)

作者:追风剑情 发布于:2018-12-29 11:36 分类:Shader

Shader "Custom/vertexTest"
{
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
		_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
		_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}

		_Cut("Cut", Range(0,1)) = 0.5
		_Amount ("Amount", Float) = 0
	}

	SubShader {
		Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
		LOD 300

		CGPROGRAM
		//https://docs.unity3d.com/Manual/SL-SurfaceShaders.html
		//Lambert、BlinnPhong
		//如果要处理alpha通道,需要加上alpha、alpha:auto、alpha:fade、alpha:premul、alphatest选项之一
		//这里用了AlphaTest,alpha大于_Cut值的像素才会显示出来
		//alpha:blend 透明度混合
		#pragma surface surf Lambert vertex:vert alphatest:_Cut 

		sampler2D _MainTex;
		fixed4 _Color;
		half _Shininess;
		half _Amount;

		struct Input {
			float2 uv_MainTex;
		};

		void vert (inout appdata_full v) 
		{
			//将顶点沿法线方向偏移
			v.vertex.xyz += v.normal * _Amount;
		}

		void surf (Input IN, inout SurfaceOutput o) {
			fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
			o.Albedo = tex.rgb * _Color.rgb;
			o.Gloss = tex.a;
			o.Alpha = tex.a * _Color.a;
			o.Specular = _Shininess;
		}
		ENDCG
	}

	Fallback "Legacy Shaders/Transparent/VertexLit"
}

标签: Shader

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号