Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

ModelVertexShader.glsl 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #version 410 core
  19. layout(location = 0) in vec3 vertexPosition;
  20. layout(location = 1) in vec3 normal;
  21. layout(location = 2) in vec2 texCoord;
  22. out vec2 fragTexCoord;
  23. uniform vec4 cameraPosition;
  24. uniform mat4 worldMatrix;
  25. uniform mat4 projectionViewMatrix;
  26. const float WORLD_RADIUS = 10000.0;
  27. void main()
  28. {
  29. vec4 modelPos = vec4(vertexPosition, 1.0);
  30. vec4 worldPos = worldMatrix * modelPos;
  31. float angle = atan(distance(worldPos.xy, cameraPosition.xy) / WORLD_RADIUS);
  32. worldPos.z = worldPos.z - WORLD_RADIUS * (1.0 - cos(angle));
  33. gl_Position = projectionViewMatrix * worldPos;
  34. fragTexCoord = texCoord;
  35. }