第 1 课:Shadowmap - view
实现
attribute vec4 color;
varying vec3 vLightDir;
varying vec3 vNormal;
varying vec4 vColor;
void main() {
vec3 lightDir = normalize(vec3(-0.5, -0.8, 0.0));
vec3 lightPos = vec3(1.5, 2.4, 0.0);
vec3 vectorWorldUp = vec3(0.0, 1.0, 0.0);
vec3 vectorRight = normalize(cross(vectorWorldUp, -lightDir));
vec3 vectorUp = normalize(cross(-lightDir, vectorRight));
mat4 viewMatrix = transpose(mat4(
vec4(vectorRight, 0.0),
vec4(vectorUp, 0.0),
vec4(-lightDir, 0.0),
vec4(vec3(0.0), 1.0)
));
mat4 TranslationMatrix = transpose(mat4(
vec4(1.0, 0.0, 0.0, -lightPos.x),
vec4(0.0, 1.0, 0.0, -lightPos.y),
vec4(0.0, 0.0, 1.0, -lightPos.z),
vec4(vec3(0.0), 1.0)
));
mat4 lightView = viewMatrix * TranslationMatrix;
gl_Position = projectionMatrix * lightView * modelMatrix * vec4(position, 1.0);
vLightDir = lightDir;
vNormal = mat3(modelMatrix) * normal;
vColor = color;
}