Renderer.h 25 KB

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