Renderer.h 25 KB

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