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

LandVertexShader.glsl 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 vec2 terrainTexCoord;
  21. layout(location = 2) in vec4 terrainInfo1;
  22. layout(location = 3) in vec4 terrainInfo2;
  23. layout(location = 4) in vec4 terrainInfo3;
  24. layout(location = 5) in vec4 terrainInfo4;
  25. layout(location = 6) in vec4 terrainInfo5;
  26. out FragmentData
  27. {
  28. vec3 position;
  29. vec2 normalTexCoord;
  30. vec2 terrainTexCoord;
  31. vec4 terrainInfo1;
  32. vec4 terrainInfo2;
  33. vec4 terrainInfo3;
  34. vec4 terrainInfo4;
  35. vec4 terrainInfo5;
  36. } fragData;
  37. #include "graphics/shaders/LandCommon.glsl"
  38. const float WORLD_RADIUS = 10000.0;
  39. void main()
  40. {
  41. vec4 modelPos = vec4(vertexPosition, 1.0);
  42. vec4 worldPos = worldMatrix * modelPos;
  43. float angle = atan(distance(worldPos.xy, cameraPosition.xy) / WORLD_RADIUS);
  44. worldPos.z = worldPos.z - WORLD_RADIUS * (1.0 - cos(angle));
  45. gl_Position = projectionMatrix * viewMatrix * worldPos;
  46. fragData.position = (viewMatrix * worldPos).xyz;
  47. fragData.normalTexCoord = modelPos.xy / 192.0;
  48. fragData.terrainTexCoord = terrainTexCoord;
  49. fragData.terrainInfo1 = terrainInfo1;
  50. fragData.terrainInfo2 = terrainInfo2;
  51. fragData.terrainInfo3 = terrainInfo3;
  52. fragData.terrainInfo4 = terrainInfo4;
  53. fragData.terrainInfo5 = terrainInfo5;
  54. }