各向異性與均向相反,是指在不同方向具有不同行為的性質,特殊的晶體會導致各向異性,材質表面上存在有組織的細小凹凸槽也會導致各向異性,各向異性反射是指:各向異性表面反射光的一種現象。
1.線性各向異性
2.徑向各向異性
3.圓柱形各向異性
Bank BRDF屬于經驗模型,由于計算簡單,且效果良好,所以該模型在各向異性光照效果的模擬非常常用,其模型計算公式很多書上有介紹,注意計算切向量,在normal map里面也有介紹。
不帶紋理的光照效果>>不知道這個程序問題在哪
Vertex Shader:
1
uniform vec3 lightposition;//光源為位置
2
uniform vec3 eyeposition;//相機位置
3
varying float NdotL, NdotH, NdotV, VdotH, LdotT, VdotT;
4
void main(void)
{
5
6
vec3 objPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
7
vec3 Normal = normalize (gl_NormalMatrix * gl_Normal);
8
vec3 LightDir = normalize (lightposition - objPosition);
9
vec3 EyeDir = normalize (eyeposition - objPosition);
10
vec3 HalfVec = normalize (LightDir + EyeDir);
11
12
vec3 TangVec = normalize(cross(Normal, EyeDir));
13
14
NdotL = max(dot(Normal, LightDir), 0.0);
15
LdotT = max(dot(LightDir, TangVec), 0.0);
16
VdotT = max(dot(EyeDir, TangVec), 0.0);
17
gl_Position = ftransform();
18
} Frag Shader:
1
uniform vec4 ambient;
2
uniform vec4 DiffuseLightColor;
3
uniform vec4 SpecularLightColor;
4
uniform float shininess;
5
varying float NdotL, NdotH, NdotV, VdotH, LdotT, VdotT ;
6
float diff=0.1;
7
float spec=1.0;
8
void main(void)
{
9
float sqrt1 = sqrt(1.0 - pow(LdotT, 2.0));
10
float sqrt2 = sqrt(1.0 - pow(VdotT, 2.0));
11
float Rs=sqrt1*sqrt2 - LdotT*VdotT;
12
vec3 diffuse = diff * vec3(DiffuseLightColor) * NdotL;
13
float BRDF = spec * pow(Rs,shininess);
14
vec3 specular =BRDF *vec3(SpecularLightColor) * NdotL;
15
16
vec4 Color = vec4((diffuse + specular),1.0);
17
Color += ambient;
18
gl_FragColor = Color;
19
} 渲染效果不是很好
改進后的效果如圖: