法线贴图据说很常用,可以用来表现物体的凹凸感.使用时,需要有一张原图和用来记录法线的法线贴图.
贴图:
法线贴图:
效果对比(右边加了法线):
代码
Shader "Custom/11.26/3" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _NormalMap("Normal Map",2D)="white"{} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; sampler2D _NormalMap; struct Input { float2 uv_MainTex; float2 uv_NormalMap; }; void surf (Input IN, inout SurfaceOutput o) { float4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; o.Normal=UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap)); } ENDCG } FallBack "Diffuse" }
只比普通的多了一个法线的设置,法线是通过UnpackNormal函数来解析了传入的2D的法线贴图.
对了,制作法线贴图可以用工具:CrayBump