CScene.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #pragma once
  2. #include "WallpaperEngine/Data/JSON.h"
  3. #include "WallpaperEngine/Render/Camera.h"
  4. #include "WallpaperEngine/Render/ModelData.h"
  5. #include "WallpaperEngine/Render/CWallpaper.h"
  6. #include "WallpaperEngine/Render/ShadowMapping.h"
  7. #include "WallpaperEngine/Render/Volumetrics.h"
  8. #include "WallpaperEngine/Scripting/ScriptEngine.h"
  9. #include <set>
  10. #include <unordered_map>
  11. namespace WallpaperEngine::Render {
  12. class Camera;
  13. class CObject;
  14. namespace Objects {
  15. class CLight;
  16. }
  17. }
  18. namespace WallpaperEngine::Render::Wallpapers {
  19. using namespace WallpaperEngine::Data::Model;
  20. class CScene final : public CWallpaper {
  21. public:
  22. CScene (
  23. const Wallpaper& wallpaper, RenderContext& context, AudioContext& audioContext,
  24. const WallpaperState::TextureUVsScaling& scalingMode, const uint32_t& clampMode
  25. );
  26. ~CScene () override;
  27. /** The project's user properties (project.json "properties"), keyed by name */
  28. [[nodiscard]] const Data::Model::Properties& getUserProperties () const;
  29. [[nodiscard]] Scripting::ScriptEngine& getScriptEngine () const;
  30. [[nodiscard]] Camera& getCamera () const;
  31. [[nodiscard]] const Scene& getScene () const;
  32. /**
  33. * _rt_MipMappedFrameBuffer, created on the first material that samples it (sub_140181AF0, scene flag 0x800).
  34. * Holds the previous frame's scene with mips, what REFLECTION reads with a roughness based LOD
  35. */
  36. std::shared_ptr<const CFBO> requireMipMappedFrameBuffer ();
  37. /**
  38. * _rt_Reflection, the planar reflection: output sized with depth, created on the first material that samples it
  39. * (sub_140181AF0, scene flag 1)
  40. */
  41. std::shared_ptr<const CFBO> requireReflectionFrameBuffer ();
  42. /**
  43. * _rt_FullAlphaMask / _rt_FullAlphaMaskIntermediate, the puppet clipping masks: R8 at half the output size, made
  44. * by the first puppet that draws one (sub_140208670)
  45. */
  46. std::shared_ptr<const CFBO> requireAlphaMaskFrameBuffer (bool intermediate);
  47. /** An object whose program samples _rt_Reflection, it stays out of the reflection pass (object flag 8) */
  48. void addReflectionReceiver (int id);
  49. /** While the mirrored reflection pass draws, culling is inverted */
  50. [[nodiscard]] bool isRenderingReflection () const { return this->m_renderingReflection; }
  51. /** Keeps fbo at the output's size / divisor, like the buffers WE makes from the window client size */
  52. void followOutputSize (const std::shared_ptr<CFBO>& fbo, float divisor);
  53. [[nodiscard]] int getWidth () const override;
  54. [[nodiscard]] int getHeight () const override;
  55. [[nodiscard]] int getCanvasWidth () const override;
  56. [[nodiscard]] int getCanvasHeight () const override;
  57. // Used by CText/ScriptEngine; read from the same g_Time/g_TimeLast globals CParticle consumes via extern.
  58. [[nodiscard]] float getTime () const;
  59. [[nodiscard]] float getDeltaTime () const;
  60. [[nodiscard]] float getFps () const;
  61. /** Seconds since the scene was loaded, what wallpaper64.exe keeps in its renderer (+320) and resets past 432000 */
  62. [[nodiscard]] float getSceneClock () const;
  63. /** Frames rendered since the scene was loaded, the first one is 1 */
  64. [[nodiscard]] uint32_t getFrameCounter () const;
  65. /** g_PointerPosition: the cursor over the output (y from the top), not mirrored by a horizontal flip */
  66. const glm::vec2* getPointerPosition () const;
  67. const glm::vec2* getPointerPositionLast () const;
  68. const glm::vec2* getMousePositionNormalized () const;
  69. /** The cursor over the scene buffer (and the output), same orientation as getMousePositionNormalized */
  70. const glm::vec2* getCursorScreenPosition () const;
  71. /**
  72. * The cursor unprojected through the scene camera's view and projection: the layout space of 2D scenes, WE's world
  73. * in 3D ones (on the near plane there, like WE)
  74. */
  75. [[nodiscard]] glm::vec3 unprojectCursor () const;
  76. /** Script input.cursorWorldPosition: unprojectCursor in WE's world (y up from the bottom left, z 0 in 2D) */
  77. [[nodiscard]] glm::vec3 getCursorWorldPosition () const;
  78. /** Script input.cursorScreenPosition: output pixels from the top left, mirrored like the projection when flipped */
  79. [[nodiscard]] glm::vec2 getCursorPixelPosition () const;
  80. /** The part of the canvas the output shows as ustart, uend, vstart, vend (the whole canvas in 3D scenes) */
  81. [[nodiscard]] glm::vec4 getVisibleUVs () const;
  82. /** getVisibleUVs as the canvas units cut off each side: left, right, bottom, top (y up) */
  83. [[nodiscard]] glm::vec4 getVisibleMargins () const;
  84. /** The canvas part on screen in the centered y down layer space: x min, x max, y min, y max (letterbox bars left
  85. * out) */
  86. [[nodiscard]] glm::vec4 getVisibleCanvasRegion () const;
  87. [[nodiscard]] float getOutputAspect () const;
  88. [[nodiscard]] bool rendersAtOutputSize () const override { return true; }
  89. /** Pixel size of the output being drawn, what WE's window client area (and _rt_FullFrameBuffer) would be */
  90. [[nodiscard]] glm::ivec2 getOutputSize () const { return this->m_outputSize; }
  91. [[nodiscard]] bool isCursorLeftDown () const { return this->m_cursorLeftDown; }
  92. /** Position fed to shaders as g_ParallaxPosition: 0.5 +- the smoothed, influence-scaled mouse offset */
  93. const glm::vec2* getParallaxPosition () const;
  94. /**
  95. * Parallax translation of an object in scene units, in the y-down space CImage/CText/CParticle position
  96. * themselves in. Like the real engine, the whole parent chain shifts as one rigid group using the topmost
  97. * ancestor's origin and parallaxDepth, a child's own depth is ignored.
  98. */
  99. [[nodiscard]] glm::vec2 getParallaxOffset (const Data::Model::Object& object) const;
  100. /** T * Rz * Ry * Rx * S of the object alone, in WE's scene space */
  101. [[nodiscard]] static glm::mat4 objectLocalMatrix (const Data::Model::Object& object);
  102. /** T * Rz * Ry * Rx * S down the parent chain, WE's object world matrix (sub_1401850A0) */
  103. [[nodiscard]] glm::mat4 objectWorldMatrix (const Data::Model::Object& object) const;
  104. [[nodiscard]] const std::vector<CObject*>& getObjectsByRenderOrder () const;
  105. /** g_Fog* uniforms (sub_140186440). Height params come in two versions: WE's world (y up from the bottom) and
  106. * the space 2D objects are laid out in here (y down from the center), the same in 3D scenes */
  107. struct FogUniforms {
  108. glm::vec3 distanceColor { 0.0f };
  109. glm::vec4 distanceParams { 0.0f };
  110. glm::vec3 heightColor { 0.0f };
  111. glm::vec4 heightParamsWorld { 0.0f };
  112. glm::vec4 heightParamsLocal { 0.0f };
  113. /** g_EyePosition in WE's world, what the fog of passes drawing in world space measures from */
  114. glm::vec3 eyeWorld { 0.0f };
  115. /** The same eye in the space 2D objects are laid out in */
  116. glm::vec3 eyeLocal { 0.0f };
  117. };
  118. /** HDR scene rendering (WE's renderer flag 0x2000): float buffers, HDR define, object brightness, HDR bloom */
  119. [[nodiscard]] bool isHDR () const { return this->m_hdr; }
  120. [[nodiscard]] bool hasDistanceFog () const { return this->m_fogDistance; }
  121. [[nodiscard]] bool hasHeightFog () const { return this->m_fogHeight; }
  122. [[nodiscard]] const FogUniforms& getFog () const { return this->m_fog; }
  123. /** Size the whole scene would have at the output's scale, what WE's render targets are sized by */
  124. [[nodiscard]] glm::ivec2 getOutputResolution () const;
  125. /** WE's world (scene units, y up from the bottom left in 2D) to clip space of the scene buffer */
  126. [[nodiscard]] glm::mat4 getWorldViewProjection (bool perspectiveLayer = false) const;
  127. [[nodiscard]] const CObject* getObject (int id) const;
  128. [[nodiscard]] CObject* getObject (int id);
  129. /** Whether the quad (-half..half, z 0) drawn through mvp covers the clip space point ndc. A planar quad stays
  130. * convex under projection, so this is WE's ray test (sub_14019D5A0) done after projecting */
  131. [[nodiscard]] static bool quadContainsPoint (const glm::mat4& mvp, const glm::vec2& half, const glm::vec2& ndc);
  132. /** Where the line through the clip space point ndc meets the z = 0 plane drawn through mvp, in that plane's
  133. * coordinates. Nothing when the plane is seen edge on or the point lies behind the eye (sub_14019D5A0) */
  134. [[nodiscard]] static std::optional<glm::vec2> quadPlanePoint (const glm::mat4& mvp, const glm::vec2& ndc);
  135. /** A passthrough layer's buffer while it draws the objects under it (sub_1401ECB20), passes that would draw onto
  136. * the scene go there instead */
  137. struct LayerTarget {
  138. std::shared_ptr<const CFBO> fbo;
  139. /** The scene buffer's clip space to the layer buffer's */
  140. glm::mat4 transform;
  141. /** copybackground off: alpha blends with MAX (renderer state flag 0x10) */
  142. bool alphaMax;
  143. /** The renderer's view projection while the layer draws, what light volumes go through */
  144. glm::mat4 viewProjection;
  145. /** WE only recomputes the cached view projection lights read once something marks the renderer dirty (+458);
  146. * the layer doesn't, its first drawn child that isn't a light does */
  147. bool viewProjectionApplied = false;
  148. };
  149. [[nodiscard]] const LayerTarget* getLayerTarget () const;
  150. /**
  151. * While the objects draw multisampled (_rt_FullFrameBufferMultiSampled), the framebuffer that stands in for the
  152. * scene buffer, otherwise the scene buffer's own
  153. */
  154. [[nodiscard]] GLuint getSceneDrawFramebuffer () const;
  155. /** Resolves the multisampled objects into the scene buffer, for anything about to read it (WE sub_1400D3310) */
  156. void resolveMultisample () const;
  157. /** IEffect.executeMaterialFunction on whichever object owns the effect */
  158. void executeEffectFunction (const ImageEffect& effect, const std::string& name) const;
  159. /** Under a passthrough layer, which draws the object into its own buffer instead of the scene (object flag 2) */
  160. [[nodiscard]] bool isDrawnByPassthroughLayer (const CObject& object) const;
  161. /** Draws the objects under a passthrough layer into target, WE's order and visibility rules (sub_1401ECB20) */
  162. void renderPassthroughChildren (int layerId, const LayerTarget& target);
  163. /** A point light's volume into the light buffer, through viewProjection (the scene's, or a layer's) */
  164. void renderLightVolume (const Objects::CLight& light, const glm::mat4& viewProjection);
  165. /** True when any group above the object (through "parent") is hidden */
  166. [[nodiscard]] bool isHiddenByAncestor (const CObject& object) const;
  167. /** The four old-style light slots as genericimage2 wants them (g_LightsPosition, g_LightsColorPremultiplied) */
  168. [[nodiscard]] const glm::vec3* getLightsPosition () const { return this->m_lightsPosition; }
  169. [[nodiscard]] const glm::vec4* getLightsColorPremultiplied () const { return this->m_lightsColorPremultiplied; }
  170. /** The same four slots unscaled, (color * intensity, radius), as the 3D shaders read them (g_LightsColorRadius) */
  171. [[nodiscard]] const glm::vec4* getLightsColorRadius () const { return this->m_lightsColorRadius; }
  172. /**
  173. * LightingV1 uniforms (sub_140190C80): up to 15 lights per type in the order lit materials index them, and the
  174. * counts their LIGHTS_* defines get. The shadow counts stay 0 with shadows off (--shadows disabled)
  175. */
  176. struct LightingV1 {
  177. int points = 0;
  178. int spots = 0;
  179. int tubes = 0;
  180. int directionals = 0;
  181. int spotCookies = 0;
  182. int spotShadowCookies = 0;
  183. int spotShadows = 0;
  184. int directionalShadows = 0;
  185. int pointShadows = 0;
  186. glm::vec4 pointColor[15] = {};
  187. glm::vec4 pointOrigin[15] = {};
  188. glm::vec4 spotColor[15] = {};
  189. glm::vec4 spotOrigin[15] = {};
  190. glm::vec4 spotDirection[15] = {};
  191. glm::vec4 spotExponent[15] = {};
  192. glm::vec4 tubeColor[15] = {};
  193. glm::vec4 tubeOriginA[15] = {};
  194. glm::vec4 tubeOriginB[15] = {};
  195. glm::vec4 directionalColor[15] = {};
  196. glm::vec4 directionalDirection[15] = {};
  197. /** spot shadow+cookie, cookie, shadow, then three cascades per shadowed directional light */
  198. glm::mat4 featureProjection[18] = {};
  199. glm::vec4 featureProjectionTransform[18] = {};
  200. glm::vec4 pointShadowProjection[3] = {};
  201. glm::vec4 pointShadowProjectionTransform[3] = {};
  202. [[nodiscard]] int features () const {
  203. return spotShadowCookies + spotCookies + spotShadows + 3 * directionalShadows;
  204. }
  205. };
  206. [[nodiscard]] const LightingV1& getLightingV1 () const { return this->m_lightingV1; }
  207. /** WE's shadow setting (renderer +428): 0 off, 1 low .. 4 ultra, LIGHTS_SHADOW_MAPPING_QUALITY */
  208. [[nodiscard]] int getShadowQuality () const { return this->m_shadowQuality; }
  209. /** _rt_shadowAtlas, the depth atlas every shadow is drawn into */
  210. [[nodiscard]] const std::shared_ptr<const CFBO>& getShadowAtlas () const { return this->_rt_shadowAtlas; }
  211. /** Whether the shadow pass draws this object: visible, not under a hidden group or a passthrough layer */
  212. [[nodiscard]] bool isShadowCasterVisible (const CObject& object) const;
  213. /** The texture lit materials sample for cookie spots ("_alias_lightCookie"), null without a cookie spot */
  214. [[nodiscard]] std::shared_ptr<const TextureProvider> getLightCookie () const;
  215. /** The render order as scripts see it: without the synthesized bloom layer */
  216. [[nodiscard]] std::vector<CObject*> getLayers () const;
  217. [[nodiscard]] int getObjectIndex (const CObject* object) const;
  218. void setAudioPolicy (bool muted, std::optional<int> ambientVolume) override;
  219. /** Script play()/stop() request for a Sound object, remembered because scripts can ask before the CSound exists */
  220. void setSoundPlaying (int id, bool playing);
  221. [[nodiscard]] std::optional<bool> getSoundPlayRequest (int id) const;
  222. void pauseSound (int id);
  223. /** The sound's own answer once it exists, otherwise what the script asked for */
  224. [[nodiscard]] bool isSoundPlaying (int id, bool startSilent) const;
  225. /** Creates a new image layer from a model json at runtime, appended to the render order. Backs
  226. * the scripting API's thisScene.createLayer(). Returns nullptr if the model couldn't be set up. */
  227. Render::CObject* createLayer (const std::string& imagePath);
  228. /** thisScene.createLayer() with a configuration object, already stringified by WE's _Internal.stringifyConfig
  229. * into scene.json object form. */
  230. Render::CObject* createLayerFromConfig (Data::JSON::JSON config);
  231. /** Moves an existing layer to the given render-order slot. Backs thisScene.sortLayer(). */
  232. void sortLayer (CObject* object, int index);
  233. /**
  234. * WE's static scene camera (scene +280 eye, +292 center, +304 up, +316 zoom), what thisScene.getCameraTransforms /
  235. * setCameraTransforms (engine slots 13 / 14) read and write and the camera whenever no camera object or path drives
  236. * it (sub_1401891A0). It starts with the scene constructor's values; the loader (sub_140186C90) runs the objects'
  237. * init () first and only then sets eye, center and up from scene.json, or the reset camera in 2D scenes without
  238. * camera paths, so an init () sees the defaults and only its zoom survives
  239. */
  240. struct StaticCamera {
  241. glm::vec3 eye { 2.0f };
  242. glm::vec3 center { 0.0f };
  243. glm::vec3 up { 0.0f, 1.0f, 0.0f };
  244. float zoom = 1.0f;
  245. };
  246. StaticCamera& getStaticCamera () { return this->m_staticCamera; }
  247. /** thisScene.createModelData / IModelData.applyData / replaceData / destroyModelData (engine slots 10-12) */
  248. uint32_t createModelData (const ModelData::Config& config, ModelData::Error& error);
  249. void applyModelData (uint32_t token, const ModelData::Config& config, bool replace, ModelData::Error& error);
  250. void destroyModelData (uint32_t token);
  251. /** A model layer's reference (sub_14021AD10), released with releaseModelData */
  252. std::shared_ptr<ModelData::Model> acquireModelData (int token);
  253. void releaseModelData (uint32_t token);
  254. protected:
  255. void appendLayer (CObject* object);
  256. /** The program check of sub_14018C720 / sub_1401D6400: the material's first pass shader against a vertex format */
  257. ModelData::Error checkModelDataMaterial (const std::string& material, uint32_t format);
  258. /** The loader's part of the static camera, once the objects' init () ran */
  259. void loadStaticCamera ();
  260. void renderFrame (const glm::ivec4& viewport) override;
  261. void renderFrameSteps (const glm::ivec4& viewport);
  262. void updateMouse (const glm::ivec4& viewport);
  263. /** Hover/press tracking that turns pointer state into cursorEnter/cursorClick/... calls on scripted layers */
  264. void dispatchCursorEvents ();
  265. friend class CWallpaper;
  266. private:
  267. Render::CObject* buildLayer (Data::JSON::JSON layerJson);
  268. Render::CObject* createPlaceholderLayer ();
  269. /**
  270. * Grows the render canvas (symmetrically around the layout center, so object positions stay valid) until
  271. * every top-level image layer with a declared size fits, see --expand-canvas
  272. */
  273. void expandCanvasToContent (
  274. const Scene& scene, float width, float height, float& canvasWidth, float& canvasHeight
  275. ) const;
  276. /** Refreshes the light slots from the light objects after scripts ran, like sub_1401D5740 + the 0x5D uniform */
  277. void updateLights ();
  278. void updateLightingV1 ();
  279. [[nodiscard]] std::vector<const Light*> sortedLightingV1Lights () const;
  280. /** Camera object view, parallax camera and perspective layer camera for this frame (sub_1401891A0) */
  281. void updateCamera ();
  282. /** Scene camera paths without a camera object, advances them by dt and writes this frame's camera */
  283. void updateCameraPath (float dt, glm::vec3& eye, glm::vec3& center, glm::vec3& up, float& zoom);
  284. /** camerafade overlay over the finished scene */
  285. void renderCameraFade ();
  286. /** WE's HDR bloom (sub_140183610) and combine_hdr_upsample into the scene buffer */
  287. void renderHDRBloom ();
  288. void releaseHDRBloom ();
  289. /** Copies the finished scene into _rt_MipMappedFrameBuffer and rebuilds its mips, WE does it before bloom */
  290. void updateMipMappedFrameBuffer () const;
  291. /** The scene mirrored on the world's y = 0 plane into _rt_Reflection, before the main pass */
  292. void renderReflection ();
  293. /** Sizes _rt_FullFrameBufferMultiSampled like the scene buffer, false when the driver can't make it */
  294. bool prepareMultisample ();
  295. void releaseMultisample ();
  296. /** --corner-color over the parts of the output a letterboxing alignment leaves uncovered */
  297. void paintLetterbox () const;
  298. void updateFog (const glm::vec3& eye);
  299. /** Mouse parallax smoothing, after updateCamera () since a camera object moves the parallax camera too */
  300. void updateParallax ();
  301. [[nodiscard]] int nextFreeLightSlot () const;
  302. /** One object of the frame's draw loop, with the debug filters and visibility checks */
  303. void renderSceneObject (CObject* object);
  304. /** Draw call of an object under a passthrough layer, sub_1401ECA70 walks the rest of the subtree depth first */
  305. void renderPassthroughSubtree (int parentId, int depth);
  306. void renderPassthroughChild (CObject* object);
  307. [[nodiscard]] std::vector<CObject*> childrenOf (int id) const;
  308. /** Back to front along the camera's view direction, WE's transparent sort (sub_1401865C0) */
  309. [[nodiscard]] std::vector<CObject*> sortedByDepth (std::vector<CObject*> objects) const;
  310. /** transparentsorting list membership, decided when the object is created (object flag 0x100, sub_14018FF60) */
  311. [[nodiscard]] bool isTransparentSorted (const CObject& object);
  312. Render::CObject* createObject (const Object& object);
  313. void createObjectDependencies (const Object& object);
  314. Render::CObject* dispatchObjectType (const Object& object);
  315. void addObjectToRenderOrder (const Object& object);
  316. std::unique_ptr<Scripting::ScriptEngine> m_scriptEngine;
  317. std::unique_ptr<Camera> m_camera;
  318. ObjectUniquePtr m_bloomObjectData;
  319. CObject* m_bloomObject = nullptr;
  320. std::map<int, CObject*> m_objects = {};
  321. std::set<int> m_objectsInCreation = {};
  322. std::set<int> m_objectsInRenderOrderWalk = {};
  323. std::map<int, bool> m_soundPlayRequests = {};
  324. ModelData::Store m_modelData;
  325. StaticCamera m_staticCamera;
  326. bool m_staticCameraLoaded = false;
  327. /** checkModelDataMaterial results, compiling the material's shader every time would be slow */
  328. std::map<std::pair<std::string, uint32_t>, ModelData::Error> m_modelDataMaterialChecks = {};
  329. std::vector<CObject*> m_objectsByRenderOrder = {};
  330. /** Camera objects in creation order, the last visible one wins */
  331. std::vector<CObject*> m_sceneCameras = {};
  332. /** Where the active camera object puts the eye, WE world units (y up), zero without one */
  333. glm::vec2 m_cameraEye = {};
  334. int m_pathIndex = 0;
  335. int m_pathKey = 0;
  336. float m_pathTime = 0.0f;
  337. float m_cameraFade = 0.0f;
  338. FogUniforms m_fog;
  339. std::unique_ptr<Volumetrics> m_volumetrics;
  340. bool m_fogDistance = false;
  341. bool m_fogHeight = false;
  342. bool m_hdr = false;
  343. /** HDR bloom: mip chain at half the output resolution and down, see renderHDRBloom () */
  344. struct BloomLevel {
  345. GLuint texture = GL_NONE;
  346. GLuint framebuffer = GL_NONE;
  347. glm::ivec2 size {};
  348. };
  349. std::vector<BloomLevel> m_bloomLevels;
  350. BloomLevel m_hdrCopy;
  351. glm::ivec2 m_bloomResolution {};
  352. GLuint m_bloomDownsample = GL_NONE;
  353. GLuint m_bloomDownsampleThreshold = GL_NONE;
  354. GLuint m_bloomUpsample = GL_NONE;
  355. GLuint m_bloomUpsampleCubic = GL_NONE;
  356. /** "displayhdr" post processing: combine_dhdr_upsample */
  357. bool m_displayHDR = false;
  358. GLuint m_bloomCombine = GL_NONE;
  359. GLuint m_fadeProgram = GL_NONE;
  360. std::vector<DynamicValue*> m_scriptedValues = {};
  361. // owns the synthesized model data backing createLayer()'d objects; must outlive the CObject
  362. // built from it (same pattern as m_bloomObjectData)
  363. std::vector<ObjectUniquePtr> m_dynamicObjectData = {};
  364. int m_nextDynamicLayerId = 2000000000;
  365. std::map<std::string, std::string> m_createLayerAliases = {};
  366. glm::vec2 m_mousePosition = {};
  367. glm::vec2 m_pointerPosition = {};
  368. glm::vec2 m_pointerPositionLast = {};
  369. glm::vec2 m_mousePositionNormalized = {};
  370. glm::vec2 m_cursorScreen = {};
  371. /** Cursor in output pixels from the viewport's top left, unclamped and unflipped (WE's ScreenToClient point) */
  372. glm::vec2 m_mousePositionViewport = {};
  373. glm::ivec2 m_outputSize = {};
  374. /** Smoothed camera offset from the scene center as a fraction of the scene size, in mouse coordinates */
  375. glm::vec2 m_cameraParallax = {};
  376. glm::vec2 m_parallaxPosition = { 0.5f, 0.5f };
  377. /** Wallpaper position offset (WallpaperState) riding through the parallax path */
  378. glm::vec2 m_parallaxBias = {};
  379. bool m_cursorLeftDown = false;
  380. float m_startTime = 0.0f;
  381. uint32_t m_frameCounter { 0 };
  382. glm::vec3 m_lightsPosition[4] = {};
  383. glm::vec4 m_lightsColorPremultiplied[3] = {};
  384. glm::vec4 m_lightsColorRadius[4] = {};
  385. LightingV1 m_lightingV1;
  386. int m_shadowQuality = 0;
  387. std::vector<ShadowMapping::Entry> m_shadowEntries = {};
  388. /** this frame's shadow of every light that got one, for its volumetrics */
  389. std::unordered_map<const Data::Model::Light*, Volumetrics::Shadow> m_volumeShadows = {};
  390. std::unique_ptr<ShadowMapping> m_shadowMapping;
  391. glm::vec2 m_cursorLastScenePosition = {};
  392. // object ids the pointer is over / that the current press started on
  393. std::set<int> m_cursorInside = {};
  394. std::set<int> m_cursorPressed = {};
  395. std::vector<LayerTarget> m_layerTargets = {};
  396. std::map<const CObject*, bool> m_transparentSorted = {};
  397. std::shared_ptr<const CFBO> _rt_4FrameBuffer = nullptr;
  398. std::shared_ptr<const CFBO> _rt_8FrameBuffer = nullptr;
  399. std::shared_ptr<const CFBO> _rt_Bloom = nullptr;
  400. std::shared_ptr<const CFBO> _rt_shadowAtlas = nullptr;
  401. std::shared_ptr<const CFBO> _rt_MipMappedFrameBuffer = nullptr;
  402. std::shared_ptr<CFBO> _rt_Reflection = nullptr;
  403. std::shared_ptr<CFBO> _rt_FullAlphaMask = nullptr;
  404. std::shared_ptr<CFBO> _rt_FullAlphaMaskIntermediate = nullptr;
  405. std::set<int> m_reflectionReceivers = {};
  406. /** Sample count of _rt_FullFrameBufferMultiSampled, 0 without it */
  407. int m_msaaSamples = 0;
  408. bool m_msaaActive = false;
  409. GLuint m_msaaFramebuffer = GL_NONE;
  410. GLuint m_msaaColor = GL_NONE;
  411. GLuint m_msaaDepth = GL_NONE;
  412. glm::ivec2 m_msaaSize = {};
  413. bool m_renderingReflection = false;
  414. struct OutputSizedBuffer {
  415. std::weak_ptr<CFBO> fbo;
  416. float divisor;
  417. };
  418. std::vector<OutputSizedBuffer> m_outputSizedBuffers = {};
  419. glm::ivec2 m_outputBufferSize = {};
  420. void resizeOutputBuffers (glm::ivec2 size);
  421. };
  422. } // namespace WallpaperEngine::Render::Wallpaper