• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CORE3D_DATASTORE_RENDER_DATA_STORE_WEATHER_H
17 #define CORE3D_DATASTORE_RENDER_DATA_STORE_WEATHER_H
18 
19 #include <atomic>
20 
21 #include <3d/namespace.h>
22 #include <base/containers/array_view.h>
23 #include <base/containers/string.h>
24 #include <base/containers/vector.h>
25 #include <base/math/vector.h>
26 #include <base/util/uid.h>
27 #include <render/datastore/intf_render_data_store.h>
28 #include <render/resource_handle.h>
29 
30 RENDER_BEGIN_NAMESPACE()
31 class IRenderContext;
32 RENDER_END_NAMESPACE()
33 
CORE3D_BEGIN_NAMESPACE()34 CORE3D_BEGIN_NAMESPACE()
35 class RenderDataStoreWeather : public RENDER_NS::IRenderDataStore {
36 public:
37     static constexpr const char* const TYPE_NAME = "RenderDataStoreWeather";
38     static constexpr BASE_NS::Uid UID { "13BFD29D-D68A-466F-8577-9F09784DB901" };
39 
40     RenderDataStoreWeather(const RENDER_NS::IRenderContext& renderContext, BASE_NS::string_view name);
41     ~RenderDataStoreWeather() override = default;
42 
43     // for clouds and sky
44     enum class CloudRenderingType : uint8_t {
45         /** Full resolution */
46         FULL = 0,
47         /** Downscaled resolution */
48         DOWNSCALED = 1,
49         /** Reprojected */
50         REPROJECTED = 2,
51     };
52     struct WeatherSettings {
53         static constexpr float SUN_MIN_DISTANCE = 1.4712E11f;
54         static constexpr float SUN_MAX_DISTANCE = 1.5112E11f;
55         static constexpr float SUN_RADIUS = 1392684000.0f;
56         static constexpr float PLANET_RADIUS = 6371E3f;
57         static constexpr float ATMOS_RADIUS = 6471e3f;
58 
59         static constexpr float ATMOSPHERE_RADIUS_OUTER = 50000.0f;
60 
61         BASE_NS::Math::Vec3 windDir = { 1.0f, 0.0f, 1.0f };
62         float windSpeed = 1000.0f;
63 
64         float coverage = 0.0f;
65         float precipitation = -1.0f;
66         float cloudType = 0.0f;
67 
68         float density = 0.2f;
69         float altitude = 0.0f;
70 
71         /* Not really  used */
72         BASE_NS::Math::Vec3 sunColor = { 1.0f, 1.0f, 0.0f };
73         BASE_NS::Math::Vec3 ambientColor = { 1.0f, 0.0f, 0.0f };
74         BASE_NS::Math::Vec3 atmosphereColor = { 0.6f, 0.7f, 0.95f };
75 
76         BASE_NS::Math::Vec3 sunPos = { 0.0f, SUN_MAX_DISTANCE, 0.0f };
77 
78         float silverIntensity = { 0.2f };
79         float silverSpread = { 1.0f };
80         float direct = { 1.0f };
81         float ambient = { 1.0f };
82         float lightStep = { 0.021f };
83         float scatteringDist { 1.0f };
84 
85         float domain[5] = { 58000.0f, 14909.0f, 50681.0f, 1136364.0f, 10000.0f };
86         float anvil_bias = { 0.13f };
87         float brightness = { 1.0f };
88         float eccintricity = { 0.6f };
89 
90         CloudRenderingType cloudRenderingType { CloudRenderingType::REPROJECTED };
91 
92         RENDER_NS::RenderHandle target0;
93         RENDER_NS::RenderHandle target1;
94 
95         RENDER_NS::RenderHandle lowFrequencyImage;
96         RENDER_NS::RenderHandle highFrequencyImage;
97         RENDER_NS::RenderHandle curlNoiseImage;
98         RENDER_NS::RenderHandle cirrusImage;
99         RENDER_NS::RenderHandle weatherMapImage;
100     };
101     void SetWeatherSettings(uint64_t id, const WeatherSettings& settings);
102     WeatherSettings GetWeatherSettings() const;
103 
104     // for water effects
105     struct WaterEffectData {
106         uint64_t id { 0xFFFFFFFFffffffff };
107         BASE_NS::Math::Vec2 planeOffset { 0.0f, 0.0f };
108     };
109     void SetWaterEffect(uint64_t id, BASE_NS::Math::Vec2 offset);
110     BASE_NS::array_view<const WaterEffectData> GetWaterEffectData() const;
111 
112     static BASE_NS::refcnt_ptr<IRenderDataStore> Create(RENDER_NS::IRenderContext& renderContext, const char* name);
113     void Ref() override;
114     void Unref() override;
115     int32_t GetRefCount() override;
116 
117     // IRenderDataStore
118     void PreRender() override {}
119     // clear in post render
120     void PostRender() override;
121     void Clear() override;
122 
123     void PreRenderBackend() override {}
124     void PostRenderBackend() override {}
125 
126     uint32_t GetFlags() const override
127     {
128         return 0;
129     }
130 
131     BASE_NS::string_view GetTypeName() const override
132     {
133         return TYPE_NAME;
134     }
135 
136     BASE_NS::string_view GetName() const override
137     {
138         return name_;
139     }
140 
141     const BASE_NS::Uid& GetUid() const override
142     {
143         return UID;
144     }
145 
146 private:
147     const BASE_NS::string name_;
148     std::atomic_int32_t refcnt_ { 0 };
149     const RENDER_NS::IRenderContext& renderContex_;
150 
151     BASE_NS::vector<WaterEffectData> waterEffectData_;
152 
153     WeatherSettings settings_ {};
154     RENDER_NS::RenderHandleReference weatherMapTex_;
155 };
156 CORE3D_END_NAMESPACE()
157 
158 #endif // CORE3D_DATASTORE_RENDER_DATA_STORE_WEATHER_H
159