各向异性与均向相反,是指在不同方向具有不同行为的性质,特殊的晶体会导致各向异性,材质表面上存在有组织的细小凹凸槽也会导致各向异性,各向异性反射是指:各向异性表面反射光的一种现象。
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
} 渲染效果不是很好
改进后的效果如图: