uniform sampler2D U_ShadowMap; uniform sampler2D U_ProjectiveTexture; uniform sampler2D U_MainTexture; varying vec2 V_Texcoord; varying vec3 V_WorldPos; varying vec4 V_ProjectCoord; varying vec4 V_ProjectorSpaceFragPos; float CalculateShadow(){ vec3 fragPos = V_ProjectorSpaceFragPos.xyz / V_ProjectorSpaceFragPos.w; fragPos = fragPos * 0.5 + vec3(0.5); float depthInShadowMap = texture2D(U_ShadowMap, fragPos.xy).r; float currentDepth = fragPos.z; float shadow = (currentDepth - 0.001) > depthInShadowMap ? 1.0 : 0.0; return shadow; } void main() { if(V_ProjectCoord.z > 0){ float shadow = CalculateShadow(); gl_FragColor = vec4(texture2D(U_MainTexture, V_Texcoord).rgb, textureProj(U_ProjectiveTexture, V_ProjectCoord).a); } else { gl_FragColor = texture2D(U_MainTexture, V_Texcoord); } }