skyBoxRenderer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #pragma once
  2. #include <glad/glad.h>
  3. #include "rendering/shader.h"
  4. #include <glm/vec3.hpp>
  5. #include "rendering/camera.h"
  6. #include <gl2d/gl2d.h>
  7. struct SkyBox
  8. {
  9. GLuint texture = 0; //environment cubemap
  10. GLuint convolutedTexture = 0; //convoluted environment (used for difuse iradiance)
  11. GLuint preFilteredMap = 0; //multiple mipmaps used for speclar
  12. glm::vec3 color = {1,1,1};
  13. void clearTextures();
  14. };
  15. struct SkyBoxLoaderAndDrawer
  16. {
  17. GLuint vertexArray = 0;
  18. GLuint vertexBuffer = 0;
  19. GLuint captureFBO;
  20. struct SkyConfigs
  21. {
  22. glm::vec3 a1 = glm::vec3{9, 47, 116} / 255.f;
  23. glm::vec3 a2 = glm::vec3{33,38,44} / 255.f;
  24. float g = 0.4;
  25. };
  26. SkyConfigs skyConfig;
  27. void createGpuData();
  28. struct
  29. {
  30. Shader shader;
  31. GLuint modelViewUniformLocation;
  32. GLuint u_sunPos;
  33. GLuint u_blend;
  34. GLuint u_rotation1;
  35. GLuint u_rotation2;
  36. }normalSkyBox;
  37. struct
  38. {
  39. Shader shader;
  40. GLuint u_lightPos;
  41. GLuint u_color1;
  42. GLuint u_color2;
  43. GLuint u_groundColor;
  44. GLuint u_g;
  45. GLuint u_useGround;
  46. GLuint u_viewProjection;
  47. GLuint u_noSun;
  48. }atmosphericScatteringShader;
  49. struct
  50. {
  51. Shader shader;
  52. GLuint u_equirectangularMap;
  53. GLuint modelViewUniformLocation;
  54. }hdrtoCubeMap;
  55. struct
  56. {
  57. Shader shader;
  58. GLuint u_environmentMap;
  59. GLuint u_sampleQuality;
  60. GLuint modelViewUniformLocation;
  61. }convolute;
  62. struct
  63. {
  64. Shader shader;
  65. GLuint u_environmentMap;
  66. GLuint u_roughness;
  67. GLuint u_sampleCount;
  68. GLuint modelViewUniformLocation;
  69. }preFilterSpecular;
  70. enum CrossskyBoxFormats
  71. {
  72. BottomOfTheCrossRight,
  73. BottomOfTheCrossDown,
  74. BottomOfTheCrossLeft,
  75. };
  76. void loadAllTextures(std::string path);
  77. void clearOnlyTextures();
  78. void loadTexture(const char *name, SkyBox &skyBox, int format = 0);
  79. void loadHDRtexture(const char *name, SkyBox &skyBox, GLuint frameBuffer);
  80. //, GLuint frameBuffer is the default fbo
  81. void createConvolutedAndPrefilteredTextureData(SkyBox &skyBox,
  82. float sampleQuality = 0.025, unsigned int specularSamples = 1024);
  83. SkyBox daySky;
  84. SkyBox nightSky;
  85. SkyBox twilightSky;
  86. gl2d::Texture sunTexture;
  87. gl2d::Texture moonTexture;
  88. void drawBefore(const glm::mat4 &viewProjMat,
  89. glm::vec3 sunPos, float timeOfDay);
  90. void clearOnlyGPUdata();
  91. void atmosphericScattering(glm::vec3 sunPos, glm::vec3 color1, glm::vec3 color2,
  92. glm::vec3 groundColor, bool useGroundColor, float g,
  93. SkyBox &skyBox, bool noSun);
  94. void createSkyTextures();
  95. };
  96. struct SunRenderer
  97. {
  98. GLuint vertexBuffer = 0;
  99. GLuint vao = 0;
  100. void create();
  101. Shader shader = {};
  102. GLuint u_modelViewProjectionMatrix = 0;
  103. GLuint u_sunset = 0;
  104. GLuint u_colorMultiplier = 0;
  105. void render(Camera camera, glm::vec3 sunPos,
  106. gl2d::Texture sunTexture, float twilight, float colorMultiplier, float scale);
  107. void clear();
  108. };
  109. glm::vec3 calculateSunPosition(float dayTime);
  110. /*
  111. "right.jpg",
  112. "left.jpg",
  113. "top.jpg",
  114. "bottom.jpg",
  115. "front.jpg",
  116. "back.jpg"
  117. */