unityshader实现物体边缘发光

白光效果:
unityshader实现物体边缘发光_第1张图片
代码展示:

Shader "Custom/EmissionOutline" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		//贴图
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		//法线贴图
		_NormalTex("Normalmap",2D)="white"{}
		//可调亮度
		_Emission("Emission",float)=2
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200

		CGPROGRAM
		#pragma surface surf Lambert 
		#pragma target 3.0
		float _Emission;
		sampler2D _MainTex;
		sampler2D _NormalTex;
		struct Input {
			float2 uv_MainTex;
			float2 uv_NormalTex;
			float3 viewDir;
		};
		fixed4 _Color;
		void surf (Input IN, inout SurfaceOutput o) {
			fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			fixed3 tmpNormal=UnpackNormal(tex2D (_NormalTex, IN.uv_NormalTex) );
			o.Normal=tmpNormal;
		    float tmpFloat=1-clamp(dot(IN.viewDir,tmpNormal),0,1);
			o.Emission=tmpFloat*_Color*_Emission;
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}

你可能感兴趣的:(Unity,Shader)