No Description

mesh.frag 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #version 450
  2. layout (binding = 1) uniform sampler2D tex;
  3. layout (location = 0) in vec2 inUV;
  4. layout (location = 1) in vec3 inNormal;
  5. layout (location = 2) in vec3 inColor;
  6. layout (location = 3) in vec3 inEyePos;
  7. layout (location = 4) in vec3 inLightVec;
  8. layout (location = 0) out vec4 outFragColor;
  9. float specpart(vec3 L, vec3 N, vec3 H)
  10. {
  11. if (dot(N, L) > 0.0)
  12. {
  13. return pow(clamp(dot(H, N), 0.0, 1.0), 64.0);
  14. }
  15. return 0.0;
  16. }
  17. void main()
  18. {
  19. vec3 Eye = normalize(-inEyePos);
  20. vec3 Reflected = normalize(reflect(-inLightVec, inNormal));
  21. vec3 halfVec = normalize(inLightVec + inEyePos);
  22. float diff = clamp(dot(inLightVec, inNormal), 0.0, 1.0);
  23. float spec = specpart(inLightVec, inNormal, halfVec);
  24. float intensity = 0.1 + diff + spec;
  25. vec4 IAmbient = vec4(0.2, 0.2, 0.2, 1.0);
  26. vec4 IDiffuse = vec4(0.5, 0.5, 0.5, 0.5) * max(dot(inNormal, inLightVec), 0.0);
  27. float shininess = 0.75;
  28. vec4 ISpecular = vec4(0.5, 0.5, 0.5, 1.0) * pow(max(dot(Reflected, Eye), 0.0), 2.0) * shininess;
  29. outFragColor = vec4((IAmbient + IDiffuse) * vec4(inColor, 1.0) + ISpecular);
  30. // Some manual saturation
  31. if (intensity > 0.95)
  32. outFragColor *= 2.25;
  33. if (intensity < 0.15)
  34. outFragColor = vec4(0.1);
  35. }