ProcSky.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #pragma once
  5. #if defined(_WIN32) || defined(_WIN64)
  6. #define fmax max
  7. #define fmin min
  8. #endif
  9. #include "../Graphics/Drawable.h"
  10. #include "../Graphics/Texture2D.h"
  11. #include "../Graphics/IndexBuffer.h"
  12. #include "../Graphics/VertexBuffer.h"
  13. #include "../Graphics/Geometry.h"
  14. #include "../Graphics/Material.h"
  15. #include "../Graphics/Zone.h"
  16. #include "../Scene/Node.h"
  17. namespace Atomic
  18. {
  19. class ProcSky : public Drawable
  20. {
  21. OBJECT(ProcSky);
  22. public:
  23. /// Construct.
  24. ///
  25. ProcSky(Context* context);
  26. /// Destruct.
  27. ~ProcSky();
  28. /// Register object factory. Drawable must be registered first.
  29. static void RegisterObject(Context* context);
  30. float SetDayTime(float time);
  31. float GetDayTime()
  32. {
  33. return dayTime_;
  34. }
  35. void SetAutoUpdate(bool autoUpdate)
  36. {
  37. autoUpdate_ = autoUpdate;
  38. }
  39. /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
  40. virtual void UpdateBatches(const FrameInfo& frame);
  41. /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
  42. virtual void UpdateGeometry(const FrameInfo& frame);
  43. /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
  44. virtual UpdateGeometryType GetUpdateGeometryType();
  45. static float GetTimeOfDay() { return timeOfDay_; }
  46. protected:
  47. SharedPtr<Texture2D> skyTexture_;
  48. SharedPtr<Material> skyMaterial_;
  49. SharedPtr<Light> sunlight_;
  50. /// Geometry.
  51. SharedPtr<Geometry> geometry_;
  52. /// Vertex buffer.
  53. SharedPtr<VertexBuffer> vertexBuffer_;
  54. /// Index buffer.
  55. SharedPtr<IndexBuffer> indexBuffer_;
  56. SharedPtr<Zone> zone_;
  57. void UpdateVertexBuffer(const FrameInfo& frame);
  58. void UpdateIndexBuffer();
  59. bool autoUpdate_;
  60. float dayTime_;
  61. float lastDayTimeUpdate_;
  62. float shadowFade_;
  63. static float timeOfDay_;
  64. float sunAngle_;
  65. float sunSize_;
  66. Color topColor_;
  67. Color horizColor_;
  68. Color lerpColor_;
  69. Color fogColor_;
  70. /// Custom world transform.
  71. Matrix3x4 customWorldTransform_;
  72. bool initialized_;
  73. bool flipped_;
  74. void OnNodeSet(Node* node);
  75. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
  76. void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
  77. void Initialize();
  78. void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
  79. /// Recalculate the world-space bounding box.
  80. virtual void OnWorldBoundingBoxUpdate();
  81. };
  82. }