1.正常贴图:RGBA 4通道 每个通道取值范围 0-255 贴图里面取值是 0-1
2.法线贴图:法线怎么存入正常贴图的过程
cs
每个通道里面存储的是一个向量(x,y,z,w) 通常我们会对应xyzw为rgba 存储值的范围也是0-1
向量的取值范围是 -1到1
法线怎么存入正常贴图的过程:法线中的向量取值范围怎么变换为0-1: (-1,1) *0.5 +0.5 ==(0,1)
正常贴图变成法线的过程:(0,1) -0.5 *2 == (-1,1)
3.法线贴图为蓝色:是因为法线经常是朝向Z轴的,法线倾向 Z值 ,Z值映射到贴图里面,对应的是RGBA中的B值,所以呈现蓝色
4.法线贴图从哪里来?
cs
1.美术制作
2.U3D里设置 图片类型为 Normal Map
5.法线贴图的作用?
cs
1.增加明暗对比度,让凸出的地方看起来更凸
法线计算:
cs
Shader "Custom/NormalMap"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NorTex ("NormalMap (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NorTex;
struct Input
{
float2 uv_MainTex;
float2 uv_NorTex;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Normal = UnpackNormal(tex2D (_NorTex, IN.uv_MainTex));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}