No Description

normalmap.frag 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2D sColorMap;
  5. layout (binding = 2) uniform sampler2D sNormalHeightMap;
  6. #define lightRadius 45.0
  7. layout (location = 0) in vec2 inUV;
  8. layout (location = 1) in vec3 inLightVec;
  9. layout (location = 2) in vec3 inLightVecB;
  10. layout (location = 3) in vec3 inLightDir;
  11. layout (location = 4) in vec3 inViewVec;
  12. layout (location = 0) out vec4 outFragColor;
  13. void main(void)
  14. {
  15. vec3 specularColor = vec3(0.85, 0.5, 0.0);
  16. float invRadius = 1.0/lightRadius;
  17. float ambient = 0.25;
  18. vec3 rgb, normal;
  19. rgb = texture(sColorMap, inUV).rgb;
  20. normal = normalize((texture(sNormalHeightMap, inUV).rgb - 0.5) * 2.0);
  21. float distSqr = dot(inLightVecB, inLightVecB);
  22. vec3 lVec = inLightVecB * inversesqrt(distSqr);
  23. float atten = max(clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0), ambient);
  24. float diffuse = clamp(dot(lVec, normal), 0.0, 1.0);
  25. vec3 light = normalize(-inLightVec);
  26. vec3 view = normalize(inViewVec);
  27. vec3 reflectDir = reflect(-light, normal);
  28. float specular = pow(max(dot(view, reflectDir), 0.0), 4.0);
  29. outFragColor = vec4((rgb * atten + (diffuse * rgb + 0.5 * specular * specularColor.rgb)) * atten, 1.0);
  30. }