平行光漫反射模型
即Lambert模型,更多关于Lambert的信息请google.
参考:http://www.lighthouse3d.com/tutorials/glsl-tutorial/directional-lights-i/
例子的源代码:http://download.csdn.net/detail/netrookie/4306606
glsl vertex shader:
struct MaterialParameters { vec4 emission; vec4 ambient; vec4 diffuse; vec4 specular; float shininess; }; struct LightSourceParameters { vec4 ambient; vec4 diffuse; vec4 specular; vec4 position; vec4 halfVector; vec3 spotDirection; float spotExponent; float spotCutoff; float spotCosCutoff; float constantAttenuation; float linearAttenuation; float quadraticAttenuation; }; uniform mat4 m_mvp_mat; uniform mat4 m_model_it; uniform MaterialParameters m_material_attr; uniform LightSourceParameters m_light_attr; attribute vec4 m_position; attribute vec3 m_normal; varying vec4 m_out_color; void main() { vec3 normal, light_dir; float indensity; vec4 diffuse; light_dir = normalize(vec3(m_light_attr.position)); normal = normalize(vec3(m_model_it * vec4(m_normal, 0.0))); indensity = max(dot(normal, light_dir), 0.0); diffuse = m_material_attr.diffuse * m_light_attr.diffuse; m_out_color = indensity * diffuse; gl_Position = m_mvp_mat * m_position; }
glsl frag shader src:
varying vec4 m_out_color; void main() { gl_FragColor = m_out_color; }
截图: