#pragma once #include #include #include #include namespace WallpaperEngine::Render::Wallpapers { class CScene; } namespace WallpaperEngine::Render { class CFBO; // LightingV1 shadow maps (2.8.42 sub_140190C80 atlas and matrices, sub_140196530 casters): square tiles of one D32F // atlas in WE's reversed depth, exactly what its lit materials compare class ShadowMapping { public: struct Entry { /** Direct3D clip space of WE (depth 0..1, reversed), one per viewport */ glm::mat4 viewProjection[6] = {}; bool point = false; int size = 0; /** Where the tile ends up in the atlas, (x, y, size, size) / atlas size, what the lit materials read */ glm::vec4* transform = nullptr; int x = 0; int y = 0; }; explicit ShadowMapping (Wallpapers::CScene& scene, std::shared_ptr atlas); ~ShadowMapping (); void render (std::vector& entries); /** Size of one shadow tile for WE's shadow quality 1..4 (sub_14025D3E0) */ [[nodiscard]] static int tileSize (int quality); /** Right handed PerspectiveFov with Direct3D's reversed depth, like WE's device (sub_14009A360) */ [[nodiscard]] static glm::mat4 perspective (float fovRadians, float aspect, float near, float far); private: void setup (); /** The row packing of sub_140190C80, returns the space the tiles take */ static glm::ivec2 pack (std::vector& entries); /** viewProjection in GL clip space, direct3D the same one as WE has it (for its culling) */ void drawCasters (const glm::mat4& viewProjection, const glm::mat4& direct3D) const; Wallpapers::CScene& m_scene; std::shared_ptr m_atlas; GLuint m_program = GL_NONE; GLint m_modelViewProjection = -1; GLint m_alphaTest = -1; }; }