ShadowMapping.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <GL/glew.h>
  3. #include <glm/glm.hpp>
  4. #include <memory>
  5. #include <vector>
  6. namespace WallpaperEngine::Render::Wallpapers {
  7. class CScene;
  8. }
  9. namespace WallpaperEngine::Render {
  10. class CFBO;
  11. // LightingV1 shadow maps (2.8.42 sub_140190C80 atlas and matrices, sub_140196530 casters): square tiles of one D32F
  12. // atlas in WE's reversed depth, exactly what its lit materials compare
  13. class ShadowMapping {
  14. public:
  15. struct Entry {
  16. /** Direct3D clip space of WE (depth 0..1, reversed), one per viewport */
  17. glm::mat4 viewProjection[6] = {};
  18. bool point = false;
  19. int size = 0;
  20. /** Where the tile ends up in the atlas, (x, y, size, size) / atlas size, what the lit materials read */
  21. glm::vec4* transform = nullptr;
  22. int x = 0;
  23. int y = 0;
  24. };
  25. explicit ShadowMapping (Wallpapers::CScene& scene, std::shared_ptr<const CFBO> atlas);
  26. ~ShadowMapping ();
  27. void render (std::vector<Entry>& entries);
  28. /** Size of one shadow tile for WE's shadow quality 1..4 (sub_14025D3E0) */
  29. [[nodiscard]] static int tileSize (int quality);
  30. /** Right handed PerspectiveFov with Direct3D's reversed depth, like WE's device (sub_14009A360) */
  31. [[nodiscard]] static glm::mat4 perspective (float fovRadians, float aspect, float near, float far);
  32. private:
  33. void setup ();
  34. /** The row packing of sub_140190C80, returns the space the tiles take */
  35. static glm::ivec2 pack (std::vector<Entry>& entries);
  36. /** viewProjection in GL clip space, direct3D the same one as WE has it (for its culling) */
  37. void drawCasters (const glm::mat4& viewProjection, const glm::mat4& direct3D) const;
  38. Wallpapers::CScene& m_scene;
  39. std::shared_ptr<const CFBO> m_atlas;
  40. GLuint m_program = GL_NONE;
  41. GLint m_modelViewProjection = -1;
  42. GLint m_alphaTest = -1;
  43. };
  44. }