Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Sky.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_SKY_H_
34#define DVD_SKY_H_
35
36#include "Sun.h"
40
41namespace Divide {
42
43class GFXDevice;
44struct PushConstantsStruct;
45
46class Texture;
47class Sphere3D;
48class ShaderProgram;
49
50FWD_DECLARE_MANAGED_CLASS(SceneGraphNode);
51
52enum class RenderStage : U8;
53
55{
56 NONE,
58 DONE
59};
60
62{
63 public:
64 explicit Sky( const ResourceDescriptor<Sky>& descriptor );
65
66 static void OnStartup(PlatformContext& context);
67 // Returns the sun position and intensity details for the specified date-time
68 const SunInfo& setDateTime(struct tm *dateTime) noexcept;
69 const SunInfo& setGeographicLocation(SimpleLocation location) noexcept;
70 const SunInfo& setDateTimeAndLocation(struct tm *dateTime, SimpleLocation location) noexcept;
71
72 [[nodiscard]] SimpleTime GetTimeOfDay() const noexcept;
73 [[nodiscard]] SimpleLocation GetGeographicLocation() const noexcept;
74
75 [[nodiscard]] const SunInfo& getCurrentDetails() const;
76 [[nodiscard]] vec3<F32> getSunPosition(F32 radius = 1.f) const;
77 [[nodiscard]] vec3<F32> getSunDirection(F32 radius = 1.f) const;
78 [[nodiscard]] bool isDay() const;
79
80 PROPERTY_R(Atmosphere, atmosphere);
81 PROPERTY_R(Atmosphere, defaultAtmosphere);
82 PROPERTY_R(Atmosphere, initialAtmosphere);
83 PROPERTY_R(bool, enableProceduralClouds, true);
84 PROPERTY_R(bool, use);
85 PROPERTY_R(bool, useDaySkybox, true);
86 PROPERTY_R(bool, useNightSkybox, true);
87 PROPERTY_R(F32, moonScale, 0.5f);
88 PROPERTY_R(F32, exposure, 0.1f);
89 PROPERTY_R(U16, rayCount, 128u);
93 PROPERTY_R(SamplerDescriptor, skyboxSampler);
94
95 void setAtmosphere(const Atmosphere& atmosphere);
96 void enableProceduralClouds(bool val);
97 void useDaySkybox(bool val);
98 void useNightSkybox(bool val);
99 void moonScale(F32 val);
100 void exposure(F32 val);
101 void rayCount(U16 val);
102 void moonColour(FColour4 val);
103 void nightSkyColour(FColour4 val);
104 void groundColour(FColour4 val);
105
106 [[nodiscard]] Handle<Texture> activeSkyBox() const noexcept;
107
108 protected:
109 friend class ResourceCache;
110 template <typename T> friend struct ResourcePool;
111
112 bool postLoad() override;
113 bool unload() override;
114
115 protected:
116 void postLoad(SceneGraphNode* sgn) override;
117
118 void sceneUpdate(U64 deltaTimeUS, SceneGraphNode* sgn, SceneState& sceneState) override;
119
120 void buildDrawCommands(SceneGraphNode* sgn, GenericDrawCommandContainer& cmdsOut) override;
121
122 void prepareRender( SceneGraphNode* sgn,
123 RenderingComponent& rComp,
124 RenderPackage& pkg,
125 GFX::MemoryBarrierCommand& postDrawMemCmd,
126 RenderStagePass renderStagePass,
127 const CameraSnapshot& cameraSnapshot,
128 bool refreshData) override;
129
130 protected:
131 template <typename T>
132 friend class ImplResourceLoader;
133
134 bool load( PlatformContext& context ) override;
135
136 void setSkyShaderData( RenderStagePass renderStagePass, PushConstantsStruct& constantsInOut);
137
138protected:
139 Sun _sun;
140 Handle<Texture> _skybox{ INVALID_HANDLE<Texture> };
141 Handle<Texture> _weatherTex{ INVALID_HANDLE<Texture> };
142 Handle<Texture> _curlNoiseTex{ INVALID_HANDLE<Texture> };
143 Handle<Texture> _worlNoiseTex{ INVALID_HANDLE<Texture> };
144 Handle<Texture> _perlWorlNoiseTex{ INVALID_HANDLE<Texture> };
145 Handle<Sphere3D> _sky{ INVALID_HANDLE<Sphere3D> };
146 U32 _diameter{1u};
147 bool _atmosphereChanged{true};
148};
149
151
152} // namespace Divide
153
154#endif //DVD_SKY_H_
#define PROPERTY_R(...)
Convenience method to add a class member with public read access but protected write access.
#define TYPEDEF_SMART_POINTERS_FOR_TYPE(T)
#define FWD_DECLARE_MANAGED_CLASS(T)
#define DEFINE_NODE_TYPE(Name, Enum)
Definition: SceneNodeFwd.h:120
FColour4 WHITE
Random stuff added for convenience.
Definition: Colours.cpp:8
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool load() override
bool unload() override
uint8_t U8
uint16_t U16
eastl::fixed_vector< GenericDrawCommand, 1, true > GenericDrawCommandContainer
uint32_t U32
RebuildCommandsState
Definition: Sky.h:55
uint64_t U64