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 #ifndef SCENEPLUGIN_INTF_CAMERA_H 16 #define SCENEPLUGIN_INTF_CAMERA_H 17 18 #include <scene_plugin/interface/intf_node.h> 19 #include <scene_plugin/interface/intf_postprocess.h> 20 21 #include <base/containers/vector.h> 22 23 #include <meta/api/animation/animation.h> 24 #include <meta/base/types.h> 25 #include <meta/interface/intf_container.h> 26 27 #include <scene_plugin/interface/compatibility.h> 28 29 SCENE_BEGIN_NAMESPACE() 30 31 // Implemented by SCENE_NS::ClassId::Camera 32 REGISTER_INTERFACE(ICamera, "cf283e39-40c6-4838-993b-af8f47899150") 33 class ICamera : public CORE_NS::IInterface { 34 META_INTERFACE(CORE_NS::IInterface, ICamera, InterfaceId::ICamera) 35 public: 36 /** 37 * @brief Field of view of the camera (perspective only). 38 * @return 39 */ 40 META_PROPERTY(float, FoV) 41 /** 42 * @brief Aspect ratio of the camera (perspective only). 43 * If aspect is 0 or less the aspect ratio of the canvas should be used. 44 * @return 45 */ 46 META_PROPERTY(float, AspectRatio) 47 /** 48 * @brief Near distance. 49 * @return 50 */ 51 META_PROPERTY(float, NearPlane) 52 53 /** 54 * @brief Far distance. 55 * @return 56 */ 57 META_PROPERTY(float, FarPlane) 58 59 /** 60 * @brief Viewport horizontal scale (orthographic projection). 61 * @return 62 */ 63 META_PROPERTY(float, XMagnification) 64 65 /** 66 * @brief Viewport vertical scale (orthographic projection). 67 * @return 68 */ 69 META_PROPERTY(float, YMagnification) 70 71 /** 72 * @brief Viewport horizontal offset (frustum projection). 73 * @return 74 */ 75 META_PROPERTY(float, XOffset) 76 77 /** 78 * @brief Viewport vertical offset (frustum projection). 79 * @return 80 */ 81 META_PROPERTY(float, YOffset) 82 83 /** 84 * @brief The SceneCameraProjection enum 85 */ 86 enum SceneCameraProjection { 87 /* Orthographic camera */ 88 SCENE_CAM_PROJECTION_ORTHOGRAPHIC = 0, 89 /* Perspective camera */ 90 SCENE_CAM_PROJECTION_PERSPECTIVE = 1, 91 /* Perspective camera */ 92 SCENE_CAM_PROJECTION_FRUSTUM = 2 93 }; 94 95 /** 96 * @brief Projection type of the camera. SCENE_CAM_PROJECTION_PERSPECTIVE is used by default. 97 * @return 98 */ 99 META_PROPERTY(uint8_t, Projection) 100 101 /** 102 * @brief The SceneCameraCulling enum 103 */ 104 enum SceneCameraCulling { 105 SCENE_CAM_CULLING_NONE = 0, 106 /* Basic view frustum cull for objects */ 107 SCENE_CAM_CULLING_VIEW_FRUSTUM = 1 108 }; 109 110 /** 111 * @brief Culling mode for the camera. 112 * @return 113 */ 114 META_PROPERTY(uint8_t, Culling) 115 116 /** 117 * @brief The SceneCameraPipeline enum 118 */ 119 enum SceneCameraPipeline { 120 /* Light weight forward pipeline. Renders directly to back buffer */ 121 SCENE_CAM_PIPELINE_LIGHT_FORWARD = 0, 122 /* Default forward pipeline */ 123 SCENE_CAM_PIPELINE_FORWARD = 1, 124 /* Deferred pipeline */ 125 SCENE_CAM_PIPELINE_DEFERRED = 2, 126 /* Custom rendering pipeline */ 127 SCENE_CAM_PIPELINE_CUSTOM = 3, 128 }; 129 130 /** 131 * @brief Default camera rendering pipeline. Defaults to SCENE_CAM_PIPELINE_FORWARD 132 * @return 133 */ 134 META_PROPERTY(uint8_t, RenderingPipeline) 135 136 /** 137 * @brief Scene flags. 138 * @return 139 */ 140 META_PROPERTY(uint32_t, SceneFlags) 141 142 /** 143 * @brief Render pipeline flags. 144 * @return 145 */ 146 META_PROPERTY(uint32_t, PipelineFlags) 147 148 /** 149 * @brief Viewport position and size in normalized render resolution: [0] = x, [1] = y, [2] = relative width [3] = 150 * relative height. (NOTE: relative width/height does not remove the offset) 151 * @return 152 */ 153 META_PROPERTY(BASE_NS::Math::Vec4, Viewport) 154 155 /** 156 * @brief Scissor offset and size in normalized render resolution: [0] = x, [1] = y, [2] = relative width [3] = 157 * relative height. (NOTE: relative width/height does not remove the offset) 158 * @return 159 */ 160 META_PROPERTY(BASE_NS::Math::Vec4, Scissor) 161 162 /** 163 * @brief Render resolution of the camera: [0] = width in pixels, [1] = height in pixels. 164 * @return 165 */ 166 META_PROPERTY(BASE_NS::Math::UVec2, RenderTargetSize) 167 168 /** 169 * @brief Clear color value. Clears the color buffer(s) if clearFlags set. 170 * @return 171 */ 172 META_PROPERTY(SCENE_NS::Color, ClearColor) 173 174 /** 175 * @brief Clear depth value. Clears the depth buffer(s) if clearFlags set. 176 * @return 177 */ 178 META_PROPERTY(float, ClearDepth) 179 180 /** 181 * @brief Custom camera render node graph file. (Can be patched with e.g. post process ids etc.) 182 * Chosen only if no explicit customSceneRenderNodeGraph. 183 * @return 184 */ 185 META_PROPERTY(BASE_NS::string, RenderNodeGraphFile) 186 187 /** 188 * @brief Camera post process configuration. 189 * @return 190 */ 191 META_PROPERTY(IPostProcess::Ptr, PostProcess) 192 193 /** 194 * @brief Set the given camera as multi view camera to this instance. Camera will be rendered only as a part of 195 * this camera rendering. Will hold a strong reference to the given camera. Same instance can be added and removed 196 * multiple times. 197 * @param camera Camera to render on as a part of this camera. 198 */ 199 virtual void AddMultiviewCamera(ICamera::Ptr camera) = 0; 200 201 /** 202 * @brief Remove the given camera as multi view camera from this instance. Camera flag for multiview rendering is 203 * restored. Same instance can be added and removed multiple times. 204 */ 205 virtual void RemoveMultiviewCamera(const ICamera::Ptr& camera) = 0; 206 207 /** Projects normalized screen coordinates to world coordinates. Origin is at the top left corner. Z-value of the 208 * screen coordinate is interpreted so that 0.0 maps to the near plane and 1.0 to the far plane. 209 * @param screenCoordinate Normalized screen coordinates. 210 * @return Projected world coordinates. 211 */ 212 virtual IPickingResult::Ptr ScreenToWorld(BASE_NS::Math::Vec3 screenCoordinate) const = 0; 213 214 /** Projects world coordinates to normalized screen coordinates. 215 * @param worldCoordinate World coordinates to be projected. 216 * @return Projected screen coordinates. 217 */ 218 virtual IPickingResult::Ptr WorldToScreen(BASE_NS::Math::Vec3 worldCoordinate) const = 0; 219 220 /** 221 * Get all nodes hit by ray using a camera and 2D screen coordinates as input. 222 * @param screenPos screen coordinates for hit test. Where (0, 0) is the upper left corner of the screen and (1, 1) 223 * the lower left corner. 224 * @return Array of raycast results that describe node that was hit and distance to intersection (ordered by 225 * distance). 226 */ 227 virtual IRayCastResult::Ptr RayCastFromCamera(const BASE_NS::Math::Vec2& screenPos) const = 0; 228 229 /** 230 * Get nodes hit by ray using this camera and 2D screen coordinates as input. Only nodes having the given layer 231 * mask are in the result. 232 * @param screenPos screen coordinates for hit test. Where (0, 0) is the upper left corner of the screen and (1, 1) 233 * the lower left corner. 234 * @param layerMask Layer mask for limiting the returned result. 235 * @return Array of raycast results that describe node that was hit and distance to intersection (ordered by 236 * distance). 237 */ 238 virtual IRayCastResult::Ptr RayCastFromCamera(const BASE_NS::Math::Vec2& screenPos, uint64_t layerMask) const = 0; 239 240 /** Resolve origin and direction of the ray 241 * @param screenPos Screen coordinates to be projected. 242 * @return On success, the first entry on the array tells the ray origin, and second one tells the normalized 243 * direction 244 */ 245 virtual IPickingResult::Ptr RayFromCamera(const BASE_NS::Math::Vec2& screenPos) const = 0; 246 247 virtual void SetDefaultRenderTargetSize(uint64_t width, uint64_t height) = 0; 248 }; 249 250 SCENE_END_NAMESPACE() 251 252 META_TYPE(SCENE_NS::ICamera::WeakPtr); 253 META_TYPE(SCENE_NS::ICamera::Ptr); 254 255 #endif // SCENEPLUGIN_INTF_CAMERA_H 256