RSL
What is a Surface Shader?
Surface Shader Algorithm(表面材质的算法)
写一个材质就像准备一餐饭. 而不同的食谱使用不同的成分. 运算法则是的规矩列表必须
遵循达到一定的效果. 一个表面材质的目的是:
计算外观面不透明度 计算表面的颜色
ie. the color of the light leaving an object,
渲染器使用透明度信息来混合前景和背景表面的颜色 ,这样场景中的背景物体将通过前
景物体的透明度来体现. 下面列出了算法的四个步骤的标准shader, plastic, 遵循合理
的设定不透明度和颜色,物体将被着色
1
Make a copy (n) of the surface normal (N) then, using the viewing
vector (I), ensure another copy (nf) faces the camera
2
设置物体的表面透明度 (Oi)
3
Find the colors of the light that is coming directly from the
light sources and set the 'response' of the surface to those
colors. An overall color is found by (generally) making three
(ambient, diffuse and specular) lighting calculations.
3.1
add the colors of all the light sources that contribute
ambient light,
3.2
add the colors of the light sources that contribute to the
diffuse appearance of the surface,
3.3
add the colors of the light sources that contribute to the
specular (shiny) highlights of the surface,
Before being added, the ambient, diffuse and specular components
are scaled by "Ka", "Kd" and "Ks". This enables an artist to
control how an object responds to the lights in a scene.
4
Set the apparent color (Ci) of the surface by combining the
light color found in step 3 and the opacity found in step 2.
The Geometry of Shading
Figure 1
The Components of Lighting
Figure 2
A sphere illuminated by a distant point light
Surface Shading & Global Variables(表面shading&全局变量)
下列表中列出所有一个表面材质的全局变量. 红色的为只读变量, 那些绿色的变量必须赋
值.
Global
Variable
Ci
Oi
Cs
Os
N
s, t
P
Ng
u,v
du, dv
dPdu,dPdv
L
Cl
l
E
Meaning
apparent color of the surface (output)表面显示颜色(输出)
apparent opacity the surface (output)表面显示透明度(输出)
true surface color (input)实际表面颜色(输入)
true surface opacity (input)实际表面透明度(输入)
surface shading normal表面法线
surface texture coordinates表面贴图坐标
surface position表面位置
surface geometric normal表面几何体法线
surface parameters表面参数
change in u, v across the surface
change in position with u and v
direction from surface to light source表面和光源的距离
light color灯光颜色
direction of a ray stricking a surface point
position of the camera摄影机位置