ProcSky.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  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. #if _MSC_VER
  24. #define fmax max
  25. #define fmin min
  26. #endif
  27. #include "../Graphics/Drawable.h"
  28. #include "../Graphics/Texture2D.h"
  29. #include "../Graphics/IndexBuffer.h"
  30. #include "../Graphics/VertexBuffer.h"
  31. #include "../Graphics/Geometry.h"
  32. #include "../Graphics/Material.h"
  33. #include "../Graphics/Zone.h"
  34. #include "../Scene/Node.h"
  35. namespace Atomic
  36. {
  37. class ATOMIC_API ProcSky : public Drawable
  38. {
  39. ATOMIC_OBJECT(ProcSky, Drawable);
  40. public:
  41. /// Construct.
  42. ///
  43. ProcSky(Context* context);
  44. /// Destruct.
  45. ~ProcSky();
  46. /// Register object factory. Drawable must be registered first.
  47. static void RegisterObject(Context* context);
  48. float SetDayTime(float time);
  49. float GetDayTime()
  50. {
  51. return dayTime_;
  52. }
  53. void SetAutoUpdate(bool autoUpdate)
  54. {
  55. autoUpdate_ = autoUpdate;
  56. }
  57. /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
  58. virtual void UpdateBatches(const FrameInfo& frame);
  59. /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
  60. virtual void UpdateGeometry(const FrameInfo& frame);
  61. /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
  62. virtual UpdateGeometryType GetUpdateGeometryType();
  63. static float GetTimeOfDay() { return timeOfDay_; }
  64. protected:
  65. SharedPtr<Texture2D> skyTexture_;
  66. SharedPtr<Material> skyMaterial_;
  67. SharedPtr<Light> sunlight_;
  68. /// Geometry.
  69. SharedPtr<Geometry> geometry_;
  70. /// Vertex buffer.
  71. SharedPtr<VertexBuffer> vertexBuffer_;
  72. /// Index buffer.
  73. SharedPtr<IndexBuffer> indexBuffer_;
  74. SharedPtr<Zone> zone_;
  75. void UpdateVertexBuffer(const FrameInfo& frame);
  76. void UpdateIndexBuffer();
  77. bool autoUpdate_;
  78. float dayTime_;
  79. float lastDayTimeUpdate_;
  80. float shadowFade_;
  81. static float timeOfDay_;
  82. float sunAngle_;
  83. float sunSize_;
  84. Color topColor_;
  85. Color horizColor_;
  86. Color lerpColor_;
  87. Color fogColor_;
  88. /// Custom world transform.
  89. Matrix3x4 customWorldTransform_;
  90. bool initialized_;
  91. bool flipped_;
  92. void OnNodeSet(Node* node);
  93. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
  94. void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
  95. void Initialize();
  96. void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
  97. /// Recalculate the world-space bounding box.
  98. virtual void OnWorldBoundingBoxUpdate();
  99. };
  100. }