• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 SCENE_INTERFACE_ICAMERA_H
17 #define SCENE_INTERFACE_ICAMERA_H
18 
19 #include <scene/base/types.h>
20 #include <scene/interface/intf_postprocess.h>
21 #include <scene/interface/intf_render_target.h>
22 
23 #include <base/math/matrix.h>
24 #include <base/util/color.h>
25 #include <base/util/formats.h>
26 
27 #include <meta/base/interface_macros.h>
28 #include <meta/base/types.h>
29 #include <meta/interface/interface_macros.h>
30 
31 SCENE_BEGIN_NAMESPACE()
32 
33 /**
34  * @brief The Camera projection type
35  */
36 enum class CameraProjection : uint8_t {
37     /* Orthographic camera */
38     ORTHOGRAPHIC = 0,
39     /* Perspective camera */
40     PERSPECTIVE = 1,
41     /* Perspective camera */
42     FRUSTUM = 2,
43     /* Custom matrix provided for camera */
44     CUSTOM = 3
45 };
46 
47 /**
48  * @brief The Camera culling mode
49  */
50 enum class CameraCulling : uint8_t {
51     NONE = 0,
52     /* Basic view frustum cull for objects */
53     VIEW_FRUSTUM = 1
54 };
55 
56 /**
57  * @brief The Camera pipeline type
58  */
59 enum class CameraPipeline : uint8_t {
60     /* Light weight forward pipeline. Renders directly to back buffer */
61     LIGHT_FORWARD = 0,
62     /* Default forward pipeline */
63     FORWARD = 1,
64     /* Deferred pipeline */
65     DEFERRED = 2,
66     /* Custom rendering pipeline */
67     CUSTOM = 3,
68 };
69 
70 enum class CameraPipelineFlag : uint32_t {
71     /** Target clear flags depth. Override camera render node graph loadOp with clear.
72      * Without clear the default render node graph based loadOp is used. (Default pipelines use depth clear)
73      */
74     CLEAR_DEPTH_BIT = (1 << 0),
75     /** Target clear flags color. Override camera render node graph loadOp with clear.
76      * Without clear the default render node graph based loadOp is used. (Default pipelines do not use color clear)
77      */
78     CLEAR_COLOR_BIT = (1 << 1),
79     /** Enable MSAA for rendering. Only affects non deferred default pipelines. */
80     MSAA_BIT = (1 << 2),
81     /** Automatically use pre-pass if there are default material needs (e.g. for transmission). Automatic RNG
82        generation needs to be enabled for the ECS scene. */
83     ALLOW_COLOR_PRE_PASS_BIT = (1 << 3),
84     /** Force pre-pass every frame. Use for e.g. custom shaders without default material needs. Automatic RNG
85        generation needs to be enabled for the ECS scene. */
86     FORCE_COLOR_PRE_PASS_BIT = (1 << 4),
87     /** Store history (store history for next frame, needed for e.g. temporal filtering) */
88     HISTORY_BIT = (1 << 5),
89     /** Jitter camera. With Halton sampling */
90     JITTER_BIT = (1 << 6),
91     /** Output samplable velocity / normal */
92     VELOCITY_OUTPUT_BIT = (1 << 7),
93     /** Output samplable depth */
94     DEPTH_OUTPUT_BIT = (1 << 8),
95     /** Is a multi-view camera and is not be rendered separately at all
96      * The camera is added to other camera as multiViewCameras
97      */
98     MULTI_VIEW_ONLY_BIT = (1 << 9),
99 
100     /** Empty bit (1 << 10) */
101 
102     /** Disallow reflection plane for camera
103      */
104     DISALLOW_REFLECTION_BIT = (1 << 11),
105     /** Automatic cubemap camera targets
106      * Can be used e.g. with dynamic cubemap renderings for camera
107      */
108     CUBEMAP_BIT = (1 << 12),
109 };
110 inline CameraPipelineFlag operator|(CameraPipelineFlag l, CameraPipelineFlag r)
111 {
112     return CameraPipelineFlag(uint32_t(l) | uint32_t(r));
113 }
114 
115 enum class CameraSceneFlag : uint32_t {
116     /** Camera is rendered when it's active. */
117     ACTIVE_RENDER_BIT = (1 << 0),
118     /** Main camera. If multiple main cameras, the first is chosen as ECS main camera. Main camera is treated always
119        as active. */
120     MAIN_CAMERA_BIT = (1 << 1),
121 };
122 inline CameraSceneFlag operator|(CameraSceneFlag l, CameraSceneFlag r)
123 {
124     return CameraSceneFlag(uint32_t(l) | uint32_t(r));
125 }
126 
127 struct ColorFormat {
128     BASE_NS::Format format { BASE_NS::Format::BASE_FORMAT_UNDEFINED };
129     uint32_t usageFlags {};
130 };
131 
132 class ICamera : public CORE_NS::IInterface {
133     META_INTERFACE(CORE_NS::IInterface, ICamera, "76af2b00-f3eb-414e-b547-8758adf4d31a")
134 public:
135     /**
136      * @brief Field of view of the camera (perspective only).
137      */
138     META_PROPERTY(float, FoV)
139     /**
140      * @brief Aspect ratio of the camera (perspective only).
141      *  If aspect is 0 or less the aspect ratio of the canvas should be used.
142      */
143     META_PROPERTY(float, AspectRatio)
144     /**
145      * @brief Near distance.
146      */
147     META_PROPERTY(float, NearPlane)
148 
149     /**
150      * @brief Far distance.
151      */
152     META_PROPERTY(float, FarPlane)
153 
154     /**
155      * @brief Viewport horizontal scale (orthographic projection).
156      */
157     META_PROPERTY(float, XMagnification)
158 
159     /**
160      * @brief Viewport vertical scale (orthographic projection).
161      */
162     META_PROPERTY(float, YMagnification)
163 
164     /**
165      * @brief Viewport horizontal offset (frustum projection).
166      */
167     META_PROPERTY(float, XOffset)
168 
169     /**
170      * @brief Viewport vertical offset (frustum projection).
171      */
172     META_PROPERTY(float, YOffset)
173 
174     /**
175      * @brief Projection type of the camera. SCENE_CAM_PROJECTION_PERSPECTIVE is used by default.
176      */
177     META_PROPERTY(CameraProjection, Projection)
178 
179     /**
180      * @brief Culling mode for the camera.
181      */
182     META_PROPERTY(CameraCulling, Culling)
183 
184     /**
185      * @brief  Default camera rendering pipeline. Defaults to LIGHT_FORWARD
186      */
187     META_PROPERTY(CameraPipeline, RenderingPipeline)
188 
189     /**
190      * @brief Scene flags.
191      */
192     META_PROPERTY(uint32_t, SceneFlags)
193 
194     /**
195      * @brief Render pipeline flags.
196      */
197     META_PROPERTY(uint32_t, PipelineFlags)
198 
199     /**
200      * @brief Viewport position and size in normalized render resolution: [0] = x, [1] = y, [2] = relative width [3] =
201      * relative height. (NOTE: relative width/height does not remove the offset)
202      */
203     META_PROPERTY(BASE_NS::Math::Vec4, Viewport)
204 
205     /**
206      * @brief Scissor offset and size in normalized render resolution: [0] = x, [1] = y, [2] = relative width [3] =
207      * relative height. (NOTE: relative width/height does not remove the offset)
208      */
209     META_PROPERTY(BASE_NS::Math::Vec4, Scissor)
210 
211     /**
212      * @brief Render resolution of the camera: [0] = width in pixels, [1] = height in pixels.
213      */
214     META_PROPERTY(BASE_NS::Math::UVec2, RenderTargetSize)
215 
216     /**
217      * @brief Clear color value. Clears the color buffer(s) if clearFlags set.
218      */
219     META_PROPERTY(BASE_NS::Color, ClearColor)
220 
221     /**
222      * @brief Clear depth value. Clears the depth buffer(s) if clearFlags set.
223      */
224     META_PROPERTY(float, ClearDepth)
225     /**
226      * @brief Defines a layer mask which affects camera's rendering.
227      */
228     META_PROPERTY(uint64_t, LayerMask)
229     /**
230      * @brief Color target creation customization.
231      */
232     META_ARRAY_PROPERTY(ColorFormat, ColorTargetCustomization)
233 
234     /**
235      * @brief Projection matrix used when projection type is CUSTOM.
236      */
237     META_PROPERTY(BASE_NS::Math::Mat4X4, CustomProjectionMatrix)
238 
239     /**
240      * @brief Camera post process configuration.
241      * @return
242      */
243     META_PROPERTY(IPostProcess::Ptr, PostProcess)
244 
245     virtual Future<bool> SetActive(bool active = true) = 0;
246     virtual bool IsActive() const = 0;
247     virtual Future<bool> SetRenderTarget(const IRenderTarget::Ptr&) = 0;
248 };
249 
250 META_REGISTER_CLASS(CameraNode, "3782e343-7e5e-4bee-af14-7f7deaa806f2", META_NS::ObjectCategoryBits::NO_CATEGORY)
251 
252 SCENE_END_NAMESPACE()
253 
254 META_INTERFACE_TYPE(SCENE_NS::ICamera)
255 META_TYPE(SCENE_NS::CameraProjection)
256 META_TYPE(SCENE_NS::CameraCulling)
257 META_TYPE(SCENE_NS::CameraPipeline)
258 META_TYPE(SCENE_NS::CameraPipelineFlag)
259 META_TYPE(SCENE_NS::CameraSceneFlag)
260 META_TYPE(SCENE_NS::ColorFormat)
261 #endif
262