Renderer.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. /// \file
  4. #pragma once
  5. #include "../Container/HashSet.h"
  6. #include "../Core/Mutex.h"
  7. #include "../Graphics/Batch.h"
  8. #include "../Graphics/Drawable.h"
  9. #include "../Graphics/Viewport.h"
  10. #include "../Math/Color.h"
  11. namespace Urho3D
  12. {
  13. class Geometry;
  14. class Drawable;
  15. class Light;
  16. class Material;
  17. class Pass;
  18. class Technique;
  19. class Octree;
  20. class Graphics;
  21. class RenderPath;
  22. class RenderSurface;
  23. class ResourceCache;
  24. class Scene;
  25. class Skeleton;
  26. class OcclusionBuffer;
  27. class Technique;
  28. class Texture;
  29. class Texture2D;
  30. class TextureCube;
  31. class View;
  32. class Zone;
  33. struct BatchQueue;
  34. static const int SHADOW_MIN_PIXELS = 64;
  35. static const int INSTANCING_BUFFER_DEFAULT_SIZE = 1024;
  36. /// Light vertex shader variations.
  37. enum LightVSVariation
  38. {
  39. LVS_DIR = 0,
  40. LVS_SPOT,
  41. LVS_POINT,
  42. LVS_SHADOW,
  43. LVS_SPOTSHADOW,
  44. LVS_POINTSHADOW,
  45. LVS_SHADOWNORMALOFFSET,
  46. LVS_SPOTSHADOWNORMALOFFSET,
  47. LVS_POINTSHADOWNORMALOFFSET,
  48. MAX_LIGHT_VS_VARIATIONS
  49. };
  50. /// Per-vertex light vertex shader variations.
  51. enum VertexLightVSVariation
  52. {
  53. VLVS_NOLIGHTS = 0,
  54. VLVS_1LIGHT,
  55. VLVS_2LIGHTS,
  56. VLVS_3LIGHTS,
  57. VLVS_4LIGHTS,
  58. MAX_VERTEXLIGHT_VS_VARIATIONS
  59. };
  60. /// Light pixel shader variations.
  61. enum LightPSVariation
  62. {
  63. LPS_NONE = 0,
  64. LPS_SPOT,
  65. LPS_POINT,
  66. LPS_POINTMASK,
  67. LPS_SPEC,
  68. LPS_SPOTSPEC,
  69. LPS_POINTSPEC,
  70. LPS_POINTMASKSPEC,
  71. LPS_SHADOW,
  72. LPS_SPOTSHADOW,
  73. LPS_POINTSHADOW,
  74. LPS_POINTMASKSHADOW,
  75. LPS_SHADOWSPEC,
  76. LPS_SPOTSHADOWSPEC,
  77. LPS_POINTSHADOWSPEC,
  78. LPS_POINTMASKSHADOWSPEC,
  79. MAX_LIGHT_PS_VARIATIONS
  80. };
  81. /// Deferred light volume vertex shader variations.
  82. enum DeferredLightVSVariation
  83. {
  84. DLVS_NONE = 0,
  85. DLVS_DIR,
  86. DLVS_ORTHO,
  87. DLVS_ORTHODIR,
  88. MAX_DEFERRED_LIGHT_VS_VARIATIONS
  89. };
  90. /// Deferred light volume pixels shader variations.
  91. enum DeferredLightPSVariation
  92. {
  93. DLPS_NONE = 0,
  94. DLPS_SPOT,
  95. DLPS_POINT,
  96. DLPS_POINTMASK,
  97. DLPS_SPEC,
  98. DLPS_SPOTSPEC,
  99. DLPS_POINTSPEC,
  100. DLPS_POINTMASKSPEC,
  101. DLPS_SHADOW,
  102. DLPS_SPOTSHADOW,
  103. DLPS_POINTSHADOW,
  104. DLPS_POINTMASKSHADOW,
  105. DLPS_SHADOWSPEC,
  106. DLPS_SPOTSHADOWSPEC,
  107. DLPS_POINTSHADOWSPEC,
  108. DLPS_POINTMASKSHADOWSPEC,
  109. DLPS_SHADOWNORMALOFFSET,
  110. DLPS_SPOTSHADOWNORMALOFFSET,
  111. DLPS_POINTSHADOWNORMALOFFSET,
  112. DLPS_POINTMASKSHADOWNORMALOFFSET,
  113. DLPS_SHADOWSPECNORMALOFFSET,
  114. DLPS_SPOTSHADOWSPECNORMALOFFSET,
  115. DLPS_POINTSHADOWSPECNORMALOFFSET,
  116. DLPS_POINTMASKSHADOWSPECNORMALOFFSET,
  117. DLPS_ORTHO,
  118. DLPS_ORTHOSPOT,
  119. DLPS_ORTHOPOINT,
  120. DLPS_ORTHOPOINTMASK,
  121. DLPS_ORTHOSPEC,
  122. DLPS_ORTHOSPOTSPEC,
  123. DLPS_ORTHOPOINTSPEC,
  124. DLPS_ORTHOPOINTMASKSPEC,
  125. DLPS_ORTHOSHADOW,
  126. DLPS_ORTHOSPOTSHADOW,
  127. DLPS_ORTHOPOINTSHADOW,
  128. DLPS_ORTHOPOINTMASKSHADOW,
  129. DLPS_ORTHOSHADOWSPEC,
  130. DLPS_ORTHOSPOTSHADOWSPEC,
  131. DLPS_ORTHOPOINTSHADOWSPEC,
  132. DLPS_ORTHOPOINTMASKSHADOWSPEC,
  133. DLPS_ORTHOSHADOWNORMALOFFSET,
  134. DLPS_ORTHOSPOTSHADOWNORMALOFFSET,
  135. DLPS_ORTHOPOINTSHADOWNORMALOFFSET,
  136. DLPS_ORTHOPOINTMASKSHADOWNORMALOFFSET,
  137. DLPS_ORTHOSHADOWSPECNORMALOFFSET,
  138. DLPS_ORTHOSPOTSHADOWSPECNORMALOFFSET,
  139. DLPS_ORTHOPOINTSHADOWSPECNORMALOFFSET,
  140. DLPS_ORTHOPOINTMASKSHADOWSPECNORMALOFFSET,
  141. MAX_DEFERRED_LIGHT_PS_VARIATIONS
  142. };
  143. /// High-level rendering subsystem. Manages drawing of 3D views.
  144. class URHO3D_API Renderer : public Object
  145. {
  146. URHO3D_OBJECT(Renderer, Object);
  147. public:
  148. using ShadowMapFilter = void(Object::*)(View* view, Texture2D* shadowMap, float blurScale);
  149. /// Construct.
  150. explicit Renderer(Context* context);
  151. /// Destruct.
  152. ~Renderer() override;
  153. /// Set number of backbuffer viewports to render.
  154. /// @property
  155. void SetNumViewports(i32 num);
  156. /// Set a backbuffer viewport.
  157. /// @property{set_viewports}
  158. void SetViewport(i32 index, Viewport* viewport);
  159. /// Set default renderpath.
  160. /// @property
  161. void SetDefaultRenderPath(RenderPath* renderPath);
  162. /// Set default renderpath from an XML file.
  163. void SetDefaultRenderPath(XMLFile* xmlFile);
  164. /// Set default non-textured material technique.
  165. /// @property
  166. void SetDefaultTechnique(Technique* technique);
  167. /// Set HDR rendering on/off.
  168. /// @property{set_hdrRendering}
  169. void SetHDRRendering(bool enable);
  170. /// Set specular lighting on/off.
  171. /// @property
  172. void SetSpecularLighting(bool enable);
  173. /// Set default texture max anisotropy level.
  174. /// @property
  175. void SetTextureAnisotropy(int level);
  176. /// Set default texture filtering.
  177. /// @property
  178. void SetTextureFilterMode(TextureFilterMode mode);
  179. /// Set texture quality level. See the QUALITY constants in GraphicsDefs.h.
  180. /// @property
  181. void SetTextureQuality(MaterialQuality quality);
  182. /// Set material quality level. See the QUALITY constants in GraphicsDefs.h.
  183. /// @property
  184. void SetMaterialQuality(MaterialQuality quality);
  185. /// Set shadows on/off.
  186. /// @property
  187. void SetDrawShadows(bool enable);
  188. /// Set shadow map resolution.
  189. /// @property
  190. void SetShadowMapSize(int size);
  191. /// Set shadow quality mode. See the SHADOWQUALITY enum in GraphicsDefs.h.
  192. /// @property
  193. void SetShadowQuality(ShadowQuality quality);
  194. /// Set shadow softness, only works when SHADOWQUALITY_BLUR_VSM is used.
  195. /// @property
  196. void SetShadowSoftness(float shadowSoftness);
  197. /// Set shadow parameters when VSM is used, they help to reduce light bleeding. LightBleeding must be in [0, 1].
  198. void SetVSMShadowParameters(float minVariance, float lightBleedingReduction);
  199. /// Set VSM shadow map multisampling level. Default 1 (no multisampling).
  200. /// @property{set_vsmMultiSample}
  201. void SetVSMMultiSample(int multiSample);
  202. /// Set post processing filter to the shadow map.
  203. /// @nobind
  204. void SetShadowMapFilter(Object* instance, ShadowMapFilter functionPtr);
  205. /// Set reuse of shadow maps. Default is true. If disabled, also transparent geometry can be shadowed.
  206. /// @property
  207. void SetReuseShadowMaps(bool enable);
  208. /// Set maximum number of shadow maps created for one resolution. Only has effect if reuse of shadow maps is disabled.
  209. /// @property
  210. void SetMaxShadowMaps(int shadowMaps);
  211. /// Set dynamic instancing on/off. When on (default), drawables using the same static-type geometry and material will be automatically combined to an instanced draw call.
  212. /// @property
  213. void SetDynamicInstancing(bool enable);
  214. /// Set number of extra instancing buffer elements. Default is 0. Extra 4-vectors are available through TEXCOORD7 and further.
  215. /// @property
  216. void SetNumExtraInstancingBufferElements(int elements);
  217. /// Set minimum number of instances required in a batch group to render as instanced.
  218. /// @property
  219. void SetMinInstances(int instances);
  220. /// Set maximum number of sorted instances per batch group. If exceeded, instances are rendered unsorted.
  221. /// @property
  222. void SetMaxSortedInstances(int instances);
  223. /// Set maximum number of occluder triangles.
  224. /// @property
  225. void SetMaxOccluderTriangles(int triangles);
  226. /// Set occluder buffer width.
  227. /// @property
  228. void SetOcclusionBufferSize(int size);
  229. /// Set required screen size (1.0 = full screen) for occluders.
  230. /// @property
  231. void SetOccluderSizeThreshold(float screenSize);
  232. /// Set whether to thread occluder rendering. Default false.
  233. /// @property
  234. void SetThreadedOcclusion(bool enable);
  235. /// Set shadow depth bias multiplier for mobile platforms to counteract possible worse shadow map precision. Default 1.0 (no effect).
  236. /// @property
  237. void SetMobileShadowBiasMul(float mul);
  238. /// Set shadow depth bias addition for mobile platforms to counteract possible worse shadow map precision. Default 0.0 (no effect).
  239. /// @property
  240. void SetMobileShadowBiasAdd(float add);
  241. /// Set shadow normal offset multiplier for mobile platforms to counteract possible worse shadow map precision. Default 1.0 (no effect).
  242. /// @property
  243. void SetMobileNormalOffsetMul(float mul);
  244. /// Force reload of shaders.
  245. void ReloadShaders();
  246. /// Apply post processing filter to the shadow map. Called by View.
  247. void ApplyShadowMapFilter(View* view, Texture2D* shadowMap, float blurScale);
  248. /// Return number of backbuffer viewports.
  249. /// @property
  250. i32 GetNumViewports() const { return viewports_.Size(); }
  251. /// Return backbuffer viewport by index.
  252. /// @property{get_viewports}
  253. Viewport* GetViewport(i32 index) const;
  254. /// Return nth backbuffer viewport associated to a scene. Index 0 returns the first.
  255. Viewport* GetViewportForScene(Scene* scene, i32 index) const;
  256. /// Return default renderpath.
  257. /// @property
  258. RenderPath* GetDefaultRenderPath() const;
  259. /// Return default non-textured material technique.
  260. /// @property
  261. Technique* GetDefaultTechnique() const;
  262. /// Return whether HDR rendering is enabled.
  263. /// @property{get_hdrRendering}
  264. bool GetHDRRendering() const { return hdrRendering_; }
  265. /// Return whether specular lighting is enabled.
  266. /// @property
  267. bool GetSpecularLighting() const { return specularLighting_; }
  268. /// Return whether drawing shadows is enabled.
  269. /// @property
  270. bool GetDrawShadows() const { return drawShadows_; }
  271. /// Return default texture max. anisotropy level.
  272. /// @property
  273. int GetTextureAnisotropy() const { return textureAnisotropy_; }
  274. /// Return default texture filtering mode.
  275. /// @property
  276. TextureFilterMode GetTextureFilterMode() const { return textureFilterMode_; }
  277. /// Return texture quality level.
  278. /// @property
  279. MaterialQuality GetTextureQuality() const { return textureQuality_; }
  280. /// Return material quality level.
  281. /// @property
  282. MaterialQuality GetMaterialQuality() const { return materialQuality_; }
  283. /// Return shadow map resolution.
  284. /// @property
  285. int GetShadowMapSize() const { return shadowMapSize_; }
  286. /// Return shadow quality.
  287. /// @property
  288. ShadowQuality GetShadowQuality() const { return shadowQuality_; }
  289. /// Return shadow softness.
  290. /// @property
  291. float GetShadowSoftness() const { return shadowSoftness_; }
  292. /// Return VSM shadow parameters.
  293. /// @property{get_vsmShadowParameters}
  294. Vector2 GetVSMShadowParameters() const { return vsmShadowParams_; };
  295. /// Return VSM shadow multisample level.
  296. /// @property{get_vsmMultiSample}
  297. int GetVSMMultiSample() const { return vsmMultiSample_; }
  298. /// Return whether shadow maps are reused.
  299. /// @property
  300. bool GetReuseShadowMaps() const { return reuseShadowMaps_; }
  301. /// Return maximum number of shadow maps per resolution.
  302. /// @property
  303. int GetMaxShadowMaps() const { return maxShadowMaps_; }
  304. /// Return whether dynamic instancing is in use.
  305. /// @property
  306. bool GetDynamicInstancing() const { return dynamicInstancing_; }
  307. /// Return number of extra instancing buffer elements.
  308. /// @property
  309. int GetNumExtraInstancingBufferElements() const { return numExtraInstancingBufferElements_; };
  310. /// Return minimum number of instances required in a batch group to render as instanced.
  311. /// @property
  312. int GetMinInstances() const { return minInstances_; }
  313. /// Return maximum number of sorted instances per batch group.
  314. /// @property
  315. int GetMaxSortedInstances() const { return maxSortedInstances_; }
  316. /// Return maximum number of occluder triangles.
  317. /// @property
  318. int GetMaxOccluderTriangles() const { return maxOccluderTriangles_; }
  319. /// Return occlusion buffer width.
  320. /// @property
  321. int GetOcclusionBufferSize() const { return occlusionBufferSize_; }
  322. /// Return occluder screen size threshold.
  323. /// @property
  324. float GetOccluderSizeThreshold() const { return occluderSizeThreshold_; }
  325. /// Return whether occlusion rendering is threaded.
  326. /// @property
  327. bool GetThreadedOcclusion() const { return threadedOcclusion_; }
  328. /// Return shadow depth bias multiplier for mobile platforms.
  329. /// @property
  330. float GetMobileShadowBiasMul() const { return mobileShadowBiasMul_; }
  331. /// Return shadow depth bias addition for mobile platforms.
  332. /// @property
  333. float GetMobileShadowBiasAdd() const { return mobileShadowBiasAdd_; }
  334. /// Return shadow normal offset multiplier for mobile platforms.
  335. /// @property
  336. float GetMobileNormalOffsetMul() const { return mobileNormalOffsetMul_; }
  337. /// Return number of views rendered.
  338. /// @property
  339. i32 GetNumViews() const { return views_.Size(); }
  340. /// Return number of primitives rendered.
  341. /// @property
  342. i32 GetNumPrimitives() const { return numPrimitives_; }
  343. /// Return number of batches rendered.
  344. /// @property
  345. i32 GetNumBatches() const { return numBatches_; }
  346. /// Return number of geometries rendered.
  347. /// @property
  348. i32 GetNumGeometries(bool allViews = false) const;
  349. /// Return number of lights rendered.
  350. /// @property
  351. i32 GetNumLights(bool allViews = false) const;
  352. /// Return number of shadow maps rendered.
  353. /// @property
  354. i32 GetNumShadowMaps(bool allViews = false) const;
  355. /// Return number of occluders rendered.
  356. /// @property
  357. i32 GetNumOccluders(bool allViews = false) const;
  358. /// Return the default zone.
  359. /// @property
  360. Zone* GetDefaultZone() const { return defaultZone_; }
  361. /// Return the default material.
  362. /// @property
  363. Material* GetDefaultMaterial() const { return defaultMaterial_; }
  364. /// Return the default range attenuation texture.
  365. /// @property
  366. Texture2D* GetDefaultLightRamp() const { return defaultLightRamp_; }
  367. /// Return the default spotlight attenuation texture.
  368. /// @property
  369. Texture2D* GetDefaultLightSpot() const { return defaultLightSpot_; }
  370. /// Return the shadowed pointlight face selection cube map.
  371. TextureCube* GetFaceSelectCubeMap() const { return faceSelectCubeMap_; }
  372. /// Return the shadowed pointlight indirection cube map.
  373. TextureCube* GetIndirectionCubeMap() const { return indirectionCubeMap_; }
  374. /// Return the instancing vertex buffer.
  375. VertexBuffer* GetInstancingBuffer() const { return dynamicInstancing_ ? instancingBuffer_.Get() : nullptr; }
  376. /// Return the frame update parameters.
  377. const FrameInfo& GetFrameInfo() const { return frame_; }
  378. /// Update for rendering. Called by HandleRenderUpdate().
  379. void Update(float timeStep);
  380. /// Render. Called by Engine.
  381. void Render();
  382. /// Add debug geometry to the debug renderer.
  383. void DrawDebugGeometry(bool depthTest);
  384. /// Queue a render surface's viewports for rendering. Called by the surface, or by View.
  385. void QueueRenderSurface(RenderSurface* renderTarget);
  386. /// Queue a viewport for rendering. Null surface means backbuffer.
  387. void QueueViewport(RenderSurface* renderTarget, Viewport* viewport);
  388. /// Return volume geometry for a light.
  389. Geometry* GetLightGeometry(Light* light);
  390. /// Return quad geometry used in postprocessing.
  391. Geometry* GetQuadGeometry();
  392. /// Allocate a shadow map. If shadow map reuse is disabled, a different map is returned each time.
  393. Texture2D* GetShadowMap(Light* light, Camera* camera, i32 viewWidth, i32 viewHeight);
  394. /// Allocate a rendertarget or depth-stencil texture for deferred rendering or postprocessing. Should only be called during actual rendering, not before.
  395. Texture* GetScreenBuffer
  396. (int width, int height, unsigned format, int multiSample, bool autoResolve, bool cubemap, bool filtered, bool srgb, hash32 persistentKey = 0);
  397. /// Allocate a depth-stencil surface that does not need to be readable. Should only be called during actual rendering, not before.
  398. RenderSurface* GetDepthStencil(int width, int height, int multiSample, bool autoResolve);
  399. /// Allocate an occlusion buffer.
  400. OcclusionBuffer* GetOcclusionBuffer(Camera* camera);
  401. /// Allocate a temporary shadow camera and a scene node for it. Is thread-safe.
  402. Camera* GetShadowCamera();
  403. /// Mark a view as prepared by the specified culling camera.
  404. void StorePreparedView(View* view, Camera* camera);
  405. /// Return a prepared view if exists for the specified camera. Used to avoid duplicate view preparation CPU work.
  406. View* GetPreparedView(Camera* camera);
  407. /// Choose shaders for a forward rendering batch. The related batch queue is provided in case it has extra shader compilation defines.
  408. void SetBatchShaders(Batch& batch, Technique* tech, bool allowShadows, const BatchQueue& queue);
  409. /// Choose shaders for a deferred light volume batch.
  410. void SetLightVolumeBatchShaders
  411. (Batch& batch, Camera* camera, const String& vsName, const String& psName, const String& vsDefines, const String& psDefines);
  412. /// Set cull mode while taking possible projection flipping into account.
  413. void SetCullMode(CullMode mode, Camera* camera);
  414. /// Ensure sufficient size of the instancing vertex buffer. Return true if successful.
  415. bool ResizeInstancingBuffer(i32 numInstances);
  416. /// Optimize a light by scissor rectangle.
  417. void OptimizeLightByScissor(Light* light, Camera* camera);
  418. /// Optimize a light by marking it to the stencil buffer and setting a stencil test.
  419. void OptimizeLightByStencil(Light* light, Camera* camera);
  420. /// Return a scissor rectangle for a light.
  421. const Rect& GetLightScissor(Light* light, Camera* camera);
  422. /// Return a view or its source view if it uses one. Used internally for render statistics.
  423. static View* GetActualView(View* view);
  424. private:
  425. /// Initialize when screen mode initially set.
  426. void Initialize();
  427. /// Reload shaders.
  428. void LoadShaders();
  429. /// Reload shaders for a material pass. The related batch queue is provided in case it has extra shader compilation defines.
  430. void LoadPassShaders(Pass* pass, Vector<SharedPtr<ShaderVariation>>& vertexShaders, Vector<SharedPtr<ShaderVariation>>& pixelShaders, const BatchQueue& queue);
  431. /// Release shaders used in materials.
  432. void ReleaseMaterialShaders();
  433. /// Reload textures.
  434. void ReloadTextures();
  435. /// Create light volume geometries.
  436. void CreateGeometries();
  437. /// Create instancing vertex buffer.
  438. void CreateInstancingBuffer();
  439. /// Create point light shadow indirection texture data.
  440. void SetIndirectionTextureData();
  441. /// Update a queued viewport for rendering.
  442. void UpdateQueuedViewport(i32 index);
  443. /// Prepare for rendering of a new view.
  444. void PrepareViewRender();
  445. /// Remove unused occlusion and screen buffers.
  446. void RemoveUnusedBuffers();
  447. /// Reset shadow map allocation counts.
  448. void ResetShadowMapAllocations();
  449. /// Reset screem buffer allocation counts.
  450. void ResetScreenBufferAllocations();
  451. /// Remove all shadow maps. Called when global shadow map resolution or format is changed.
  452. void ResetShadowMaps();
  453. /// Remove all occlusion and screen buffers.
  454. void ResetBuffers();
  455. /// Find variations for shadow shaders.
  456. String GetShadowVariations() const;
  457. /// Handle screen mode event.
  458. void HandleScreenMode(StringHash eventType, VariantMap& eventData);
  459. /// Handle render update event.
  460. void HandleRenderUpdate(StringHash eventType, VariantMap& eventData);
  461. /// Blur the shadow map.
  462. void BlurShadowMap(View* view, Texture2D* shadowMap, float blurScale);
  463. /// Graphics subsystem.
  464. WeakPtr<Graphics> graphics_;
  465. /// Default renderpath.
  466. SharedPtr<RenderPath> defaultRenderPath_;
  467. /// Default non-textured material technique.
  468. SharedPtr<Technique> defaultTechnique_;
  469. /// Default zone.
  470. SharedPtr<Zone> defaultZone_;
  471. /// Directional light quad geometry.
  472. SharedPtr<Geometry> dirLightGeometry_;
  473. /// Spot light volume geometry.
  474. SharedPtr<Geometry> spotLightGeometry_;
  475. /// Point light volume geometry.
  476. SharedPtr<Geometry> pointLightGeometry_;
  477. /// Instance stream vertex buffer.
  478. SharedPtr<VertexBuffer> instancingBuffer_;
  479. /// Default material.
  480. SharedPtr<Material> defaultMaterial_;
  481. /// Default range attenuation texture.
  482. SharedPtr<Texture2D> defaultLightRamp_;
  483. /// Default spotlight attenuation texture.
  484. SharedPtr<Texture2D> defaultLightSpot_;
  485. /// Face selection cube map for shadowed pointlights.
  486. SharedPtr<TextureCube> faceSelectCubeMap_;
  487. /// Indirection cube map for shadowed pointlights.
  488. SharedPtr<TextureCube> indirectionCubeMap_;
  489. /// Reusable scene nodes with shadow camera components.
  490. Vector<SharedPtr<Node>> shadowCameraNodes_;
  491. /// Reusable occlusion buffers.
  492. Vector<SharedPtr<OcclusionBuffer>> occlusionBuffers_;
  493. /// Shadow maps by resolution.
  494. HashMap<int, Vector<SharedPtr<Texture2D>>> shadowMaps_;
  495. /// Shadow map dummy color buffers by resolution.
  496. HashMap<int, SharedPtr<Texture2D>> colorShadowMaps_;
  497. /// Shadow map allocations by resolution.
  498. HashMap<int, Vector<Light*>> shadowMapAllocations_;
  499. /// Instance of shadow map filter.
  500. Object* shadowMapFilterInstance_{};
  501. /// Function pointer of shadow map filter.
  502. ShadowMapFilter shadowMapFilter_{};
  503. /// Screen buffers by resolution and format.
  504. HashMap<hash64, Vector<SharedPtr<Texture>>> screenBuffers_;
  505. /// Current screen buffer allocations by resolution and format.
  506. HashMap<hash64, i32> screenBufferAllocations_;
  507. /// Cache for light scissor queries.
  508. HashMap<Pair<Light*, Camera*>, Rect> lightScissorCache_;
  509. /// Backbuffer viewports.
  510. Vector<SharedPtr<Viewport>> viewports_;
  511. /// Render surface viewports queued for update.
  512. Vector<Pair<WeakPtr<RenderSurface>, WeakPtr<Viewport>>> queuedViewports_;
  513. /// Views that have been processed this frame.
  514. Vector<WeakPtr<View>> views_;
  515. /// Prepared views by culling camera.
  516. HashMap<Camera*, WeakPtr<View>> preparedViews_;
  517. /// Octrees that have been updated during the frame.
  518. HashSet<Octree*> updatedOctrees_;
  519. /// Techniques for which missing shader error has been displayed.
  520. HashSet<Technique*> shaderErrorDisplayed_;
  521. /// Mutex for shadow camera allocation.
  522. Mutex rendererMutex_;
  523. /// Current variation names for deferred light volume shaders.
  524. Vector<String> deferredLightPSVariations_;
  525. /// Frame info for rendering.
  526. FrameInfo frame_;
  527. /// Texture anisotropy level.
  528. int textureAnisotropy_{4};
  529. /// Texture filtering mode.
  530. TextureFilterMode textureFilterMode_{FILTER_TRILINEAR};
  531. /// Texture quality level.
  532. MaterialQuality textureQuality_{QUALITY_HIGH};
  533. /// Material quality level.
  534. MaterialQuality materialQuality_{QUALITY_HIGH};
  535. /// Shadow map resolution.
  536. int shadowMapSize_{1024};
  537. /// Shadow quality.
  538. ShadowQuality shadowQuality_{SHADOWQUALITY_PCF_16BIT};
  539. /// Shadow softness, only works when SHADOWQUALITY_BLUR_VSM is used.
  540. float shadowSoftness_{1.0f};
  541. /// Shadow parameters when VSM is used, they help to reduce light bleeding.
  542. Vector2 vsmShadowParams_{0.0000001f, 0.9f};
  543. /// Multisample level for VSM shadows.
  544. int vsmMultiSample_{1};
  545. /// Maximum number of shadow maps per resolution.
  546. int maxShadowMaps_{1};
  547. /// Minimum number of instances required in a batch group to render as instanced.
  548. int minInstances_{2};
  549. /// Maximum sorted instances per batch group.
  550. int maxSortedInstances_{1000};
  551. /// Maximum occluder triangles.
  552. int maxOccluderTriangles_{5000};
  553. /// Occlusion buffer width.
  554. int occlusionBufferSize_{256};
  555. /// Occluder screen size threshold.
  556. float occluderSizeThreshold_{0.025f};
  557. /// Mobile platform shadow depth bias multiplier.
  558. float mobileShadowBiasMul_{1.0f};
  559. /// Mobile platform shadow depth bias addition.
  560. float mobileShadowBiasAdd_{};
  561. /// Mobile platform shadow normal offset multiplier.
  562. float mobileNormalOffsetMul_{1.0f};
  563. /// Number of occlusion buffers in use.
  564. i32 numOcclusionBuffers_{};
  565. /// Number of temporary shadow cameras in use.
  566. i32 numShadowCameras_{};
  567. /// Number of primitives (3D geometry only).
  568. i32 numPrimitives_{};
  569. /// Number of batches (3D geometry only).
  570. i32 numBatches_{};
  571. /// Frame number on which shaders last changed.
  572. i32 shadersChangedFrameNumber_{NINDEX};
  573. /// Current stencil value for light optimization.
  574. unsigned char lightStencilValue_{};
  575. /// HDR rendering flag.
  576. bool hdrRendering_{};
  577. /// Specular lighting flag.
  578. bool specularLighting_{true};
  579. /// Draw shadows flag.
  580. bool drawShadows_{true};
  581. /// Shadow map reuse flag.
  582. bool reuseShadowMaps_{true};
  583. /// Dynamic instancing flag.
  584. bool dynamicInstancing_{true};
  585. /// Number of extra instancing data elements.
  586. int numExtraInstancingBufferElements_{};
  587. /// Threaded occlusion rendering flag.
  588. bool threadedOcclusion_{};
  589. /// Shaders need reloading flag.
  590. bool shadersDirty_{true};
  591. /// Initialized flag.
  592. bool initialized_{};
  593. /// Flag for views needing reset.
  594. bool resetViews_{};
  595. };
  596. }