No Description

scene.frag 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform samplerCube shadowCubeMap;
  5. layout (location = 0) in vec3 inNormal;
  6. layout (location = 1) in vec3 inColor;
  7. layout (location = 2) in vec3 inEyePos;
  8. layout (location = 3) in vec3 inLightVec;
  9. layout (location = 4) in vec3 inWorldPos;
  10. layout (location = 5) in vec3 inLightPos;
  11. layout (location = 0) out vec4 outFragColor;
  12. #define EPSILON 0.15
  13. #define SHADOW_OPACITY 0.5
  14. void main()
  15. {
  16. // Lighting
  17. vec3 N = normalize(inNormal);
  18. vec3 L = normalize(vec3(1.0));
  19. vec3 Eye = normalize(-inEyePos);
  20. vec3 Reflected = normalize(reflect(-inLightVec, inNormal));
  21. vec4 IAmbient = vec4(vec3(0.05), 1.0);
  22. vec4 IDiffuse = vec4(1.0) * max(dot(inNormal, inLightVec), 0.0);
  23. outFragColor = vec4(IAmbient + IDiffuse * vec4(inColor, 1.0));
  24. // Shadow
  25. vec3 lightVec = inWorldPos - inLightPos;
  26. float sampledDist = texture(shadowCubeMap, lightVec).r;
  27. float dist = length(lightVec);
  28. // Check if fragment is in shadow
  29. float shadow = (dist <= sampledDist + EPSILON) ? 1.0 : SHADOW_OPACITY;
  30. outFragColor.rgb *= shadow;
  31. }