No Description

scene.frag 985B

12345678910111213141516171819202122232425262728293031323334
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (set = 1, binding = 0) uniform sampler2D samplerColorMap;
  5. layout (location = 0) in vec3 inNormal;
  6. layout (location = 1) in vec3 inColor;
  7. layout (location = 2) in vec2 inUV;
  8. layout (location = 3) in vec3 inViewVec;
  9. layout (location = 4) in vec3 inLightVec;
  10. layout(push_constant) uniform Material
  11. {
  12. vec4 ambient;
  13. vec4 diffuse;
  14. vec4 specular;
  15. float opacity;
  16. } material;
  17. layout (location = 0) out vec4 outFragColor;
  18. void main()
  19. {
  20. vec4 color = texture(samplerColorMap, inUV) * vec4(inColor, 1.0);
  21. vec3 N = normalize(inNormal);
  22. vec3 L = normalize(inLightVec);
  23. vec3 V = normalize(inViewVec);
  24. vec3 R = reflect(-L, N);
  25. vec3 diffuse = max(dot(N, L), 0.0) * material.diffuse.rgb;
  26. vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * material.specular.rgb;
  27. outFragColor = vec4((material.ambient.rgb + diffuse) * color.rgb + specular, 1.0-material.opacity);
  28. }