Nenhuma descrição

gbuffer.vert 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 inPos;
  5. layout (location = 1) in vec3 inNormal;
  6. layout (constant_id = 0) const int type = 0;
  7. layout (binding = 0) uniform UBO {
  8. mat4 projection;
  9. mat4 modelview;
  10. } ubo;
  11. layout (location = 0) out vec3 outUVW;
  12. layout (location = 1) out vec3 outPos;
  13. layout (location = 2) out vec3 outNormal;
  14. layout (location = 3) out vec3 outViewVec;
  15. layout (location = 4) out vec3 outLightVec;
  16. layout (location = 5) out mat4 outInvModelView;
  17. out gl_PerVertex
  18. {
  19. vec4 gl_Position;
  20. };
  21. void main()
  22. {
  23. outUVW = inPos;
  24. switch(type) {
  25. case 0: // Skybox
  26. outPos = vec3(mat3(ubo.modelview) * inPos);
  27. gl_Position = vec4(ubo.projection * vec4(outPos, 1.0));
  28. break;
  29. case 1: // Object
  30. outPos = vec3(ubo.modelview * vec4(inPos, 1.0));
  31. gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz, 1.0);
  32. break;
  33. }
  34. outPos = vec3(ubo.modelview * vec4(inPos, 1.0));
  35. outNormal = mat3(ubo.modelview) * inNormal;
  36. outInvModelView = inverse(ubo.modelview);
  37. vec3 lightPos = vec3(0.0f, -5.0f, 5.0f);
  38. outLightVec = lightPos.xyz - outPos.xyz;
  39. outViewVec = -outPos.xyz;
  40. }