You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
829 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. uniform sampler2D U_ShadowMap;
  2. uniform sampler2D U_ProjectiveTexture;
  3. uniform sampler2D U_MainTexture;
  4. varying vec2 V_Texcoord;
  5. varying vec3 V_WorldPos;
  6. varying vec4 V_ProjectCoord;
  7. varying vec4 V_ProjectorSpaceFragPos;
  8. float CalculateShadow(){
  9. vec3 fragPos = V_ProjectorSpaceFragPos.xyz / V_ProjectorSpaceFragPos.w;
  10. fragPos = fragPos * 0.5 + vec3(0.5);
  11. float depthInShadowMap = texture2D(U_ShadowMap, fragPos.xy).r;
  12. float currentDepth = fragPos.z;
  13. float shadow = (currentDepth - 0.001) > depthInShadowMap ? 1.0 : 0.0;
  14. return shadow;
  15. }
  16. void main()
  17. {
  18. if(V_ProjectCoord.z > 0){
  19. float shadow = CalculateShadow();
  20. gl_FragColor = 0.5*texture2D(U_MainTexture, V_Texcoord) + textureProj(U_ProjectiveTexture, V_ProjectCoord) * 0.5 *vec4(1.0 - shadow);
  21. } else {
  22. gl_FragColor = texture2D(U_MainTexture, V_Texcoord);
  23. }
  24. }