`
CalcLightMVP(translate, scale) {
let lightMVP = mat4.create();
let modelMatrix = mat4.create();
let viewMatrix = mat4.create();
let projectionMatrix = mat4.create();
mat4.identity(modelMatrix);
mat4.identity(lightMVP);
mat4.identity(viewMatrix);
mat4.identity(projectionMatrix);
// Model transform
// dest mat, source mat, operation mat
mat4.translate(modelMatrix, modelMatrix, translate);
mat4.scale(modelMatrix, modelMatrix, scale);
// View transform
mat4.lookAt(viewMatrix, this.lightPos, this.focalPoint, this.lightUp);
// Projection transform
mat4.ortho(projectionMatrix, -100, 100, -100, 100, -100, 100);
mat4.multiply(lightMVP, projectionMatrix, viewMatrix);
mat4.multiply(lightMVP, lightMVP, modelMatrix);
return lightMVP;
}
}
float useShadowMap(sampler2D shadowMap, vec4 shadowCoord){
float shadowMapDepth = unpack(texture2D(shadowMap, shadowCoord.xy));
if(shadowCoord.z > shadowMapDepth){
return 0.0;
}
return 1.0;
}
void main(void) {
float visibility;
vec3 shadowCoord = vPositionFromLight.xyz / vPositionFromLight.w;
shadowCoord = shadowCoord.xyz * 0.5 + vec3(0.5, 0.5, 0.5);
visibility = useShadowMap(uShadowMap, vec4(shadowCoord, 1.0));
//visibility = PCF(uShadowMap, vec4(shadowCoord, 1.0));
//visibility = PCSS(uShadowMap, vec4(shadowCoord, 1.0));
vec3 phongColor = blinnPhong();
gl_FragColor = vec4(phongColor * visibility, 1.0);
// gl_FragColor = vec4(phongColor, 1.0);
}
`
Attachments:
You must be
logged in to view attached files.