Renderer.h 24 KB

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