Zone.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Graphics/Drawable.h"
  5. #include "../GraphicsAPI/Texture.h"
  6. #include "../Math/Color.h"
  7. namespace Urho3D
  8. {
  9. /// %Component that describes global rendering properties.
  10. class URHO3D_API Zone : public Drawable
  11. {
  12. URHO3D_OBJECT(Zone, Drawable);
  13. public:
  14. /// Construct.
  15. explicit Zone(Context* context);
  16. /// Destruct.
  17. ~Zone() override;
  18. /// Register object factory. Drawable must be registered first.
  19. /// @nobind
  20. static void RegisterObject(Context* context);
  21. /// Visualize the component as debug geometry.
  22. void DrawDebugGeometry(DebugRenderer* debug, bool depthTest) override;
  23. /// Set local-space bounding box. Will be used as an oriented bounding box to test whether objects or the camera are inside.
  24. /// @property
  25. void SetBoundingBox(const BoundingBox& box);
  26. /// Set ambient color.
  27. /// @property
  28. void SetAmbientColor(const Color& color);
  29. /// Set fog color.
  30. /// @property
  31. void SetFogColor(const Color& color);
  32. /// Set fog start distance.
  33. /// @property
  34. void SetFogStart(float start);
  35. /// Set fog end distance.
  36. /// @property
  37. void SetFogEnd(float end);
  38. /// Set fog height distance relative to the scene node's world position. Effective only in height fog mode.
  39. /// @property
  40. void SetFogHeight(float height);
  41. /// Set fog height scale. Effective only in height fog mode.
  42. /// @property
  43. void SetFogHeightScale(float scale);
  44. /// Set zone priority. If an object or camera is inside several zones, the one with highest priority is used.
  45. /// @property
  46. void SetPriority(int priority);
  47. /// Set height fog mode.
  48. /// @property
  49. void SetHeightFog(bool enable);
  50. /// Set override mode. If camera is inside an override zone, that zone will be used for all rendered objects instead of their own zone.
  51. /// @property
  52. void SetOverride(bool enable);
  53. /// Set ambient gradient mode. In gradient mode ambient color is interpolated from neighbor zones.
  54. /// @property
  55. void SetAmbientGradient(bool enable);
  56. /// Set zone texture. This will be bound to the zone texture unit when rendering objects inside the zone. Note that the default shaders do not use it.
  57. /// @property
  58. void SetZoneTexture(Texture* texture);
  59. /// Return inverse world transform.
  60. /// @property
  61. const Matrix3x4& GetInverseWorldTransform() const;
  62. /// Return zone's own ambient color, disregarding gradient mode.
  63. /// @property
  64. const Color& GetAmbientColor() const { return ambientColor_; }
  65. /// Return ambient start color. Not safe to call from worker threads due to possible octree query.
  66. /// @property
  67. const Color& GetAmbientStartColor();
  68. /// Return ambient end color. Not safe to call from worker threads due to possible octree query.
  69. /// @property
  70. const Color& GetAmbientEndColor();
  71. /// Return fog color.
  72. /// @property
  73. const Color& GetFogColor() const { return fogColor_; }
  74. /// Return fog start distance.
  75. /// @property
  76. float GetFogStart() const { return fogStart_; }
  77. /// Return fog end distance.
  78. /// @property
  79. float GetFogEnd() const { return fogEnd_; }
  80. /// Return fog height distance relative to the scene node's world position.
  81. /// @property
  82. float GetFogHeight() const { return fogHeight_; }
  83. /// Return fog height scale.
  84. /// @property
  85. float GetFogHeightScale() const { return fogHeightScale_; }
  86. /// Return zone priority.
  87. /// @property
  88. int GetPriority() const { return priority_; }
  89. /// Return whether height fog mode is enabled.
  90. /// @property
  91. bool GetHeightFog() const { return heightFog_; }
  92. /// Return whether override mode is enabled.
  93. /// @property
  94. bool GetOverride() const { return override_; }
  95. /// Return whether ambient gradient mode is enabled.
  96. /// @property
  97. bool GetAmbientGradient() const { return ambientGradient_; }
  98. /// Return zone texture.
  99. /// @property
  100. Texture* GetZoneTexture() const { return zoneTexture_; }
  101. /// Check whether a point is inside.
  102. bool IsInside(const Vector3& point) const;
  103. /// Set zone texture attribute.
  104. void SetZoneTextureAttr(const ResourceRef& value);
  105. /// Return zone texture attribute.
  106. ResourceRef GetZoneTextureAttr() const;
  107. protected:
  108. /// Handle node transform being dirtied.
  109. void OnMarkedDirty(Node* node) override;
  110. /// Recalculate the world-space bounding box.
  111. void OnWorldBoundingBoxUpdate() override;
  112. /// Handle removal from octree.
  113. void OnRemoveFromOctree() override;
  114. /// Recalculate the ambient gradient colors from neighbor zones. Not safe to call from worker threads due to octree query.
  115. void UpdateAmbientGradient();
  116. /// Clear zone reference from drawables inside the bounding box.
  117. void ClearDrawablesZone();
  118. /// Mark node transform dirty.
  119. void MarkNodeDirty() { OnMarkedDirty(node_); }
  120. /// Cached inverse world transform matrix.
  121. mutable Matrix3x4 inverseWorld_;
  122. /// Inverse transform dirty flag.
  123. mutable bool inverseWorldDirty_;
  124. /// Height fog mode flag.
  125. bool heightFog_;
  126. /// Override mode flag.
  127. bool override_;
  128. /// Ambient gradient mode flag.
  129. bool ambientGradient_;
  130. /// Last world-space bounding box.
  131. BoundingBox lastWorldBoundingBox_;
  132. /// Ambient color.
  133. Color ambientColor_;
  134. /// Cached ambient start color.
  135. Color ambientStartColor_;
  136. /// Cached ambient end color.
  137. Color ambientEndColor_;
  138. /// Fog color.
  139. Color fogColor_;
  140. /// Fog start distance.
  141. float fogStart_;
  142. /// Fog end distance.
  143. float fogEnd_;
  144. /// Fog height distance.
  145. float fogHeight_;
  146. /// Fog height cale.
  147. float fogHeightScale_;
  148. /// Zone priority.
  149. int priority_;
  150. /// Zone texture.
  151. SharedPtr<Texture> zoneTexture_;
  152. /// Last zone used for ambient gradient start color.
  153. WeakPtr<Zone> lastAmbientStartZone_;
  154. /// Last zone used for ambient gradient end color.
  155. WeakPtr<Zone> lastAmbientEndZone_;
  156. };
  157. }