Nenhuma descrição

gbuffer.frag 860B

1234567891011121314151617181920212223242526272829
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (location = 0) in vec3 inNormal;
  5. layout (location = 1) in vec2 inUV;
  6. layout (location = 2) in vec3 inColor;
  7. layout (location = 3) in vec3 inPos;
  8. layout (location = 0) out vec4 outPosition;
  9. layout (location = 1) out vec4 outNormal;
  10. layout (location = 2) out vec4 outAlbedo;
  11. const float NEAR_PLANE = 0.1f; //todo: specialization const
  12. const float FAR_PLANE = 64.0f; //todo: specialization const
  13. float linearDepth(float depth)
  14. {
  15. float z = depth * 2.0f - 1.0f;
  16. return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
  17. }
  18. void main()
  19. {
  20. outPosition = vec4(inPos, linearDepth(gl_FragCoord.z));
  21. outNormal = vec4(normalize(inNormal) * 0.5 + 0.5, 1.0);
  22. outAlbedo = vec4(inColor * 2.0, 1.0);
  23. }