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 CORE__RENDER__NODE__RENDER_NODE_DEFAULT_CAMERAS_H
17 #define CORE__RENDER__NODE__RENDER_NODE_DEFAULT_CAMERAS_H
18 
19 #include <3d/namespace.h>
20 #include <base/math/matrix.h>
21 #include <base/util/uid.h>
22 #include <core/namespace.h>
23 #include <render/nodecontext/intf_render_node.h>
24 #include <render/resource_handle.h>
25 
26 #include "render/render_node_scene_util.h"
27 
28 CORE_BEGIN_NAMESPACE()
29 class IFrustumUtil;
30 CORE_END_NAMESPACE()
31 
32 CORE3D_BEGIN_NAMESPACE()
33 class IRenderDataStoreDefaultLight;
34 
35 class RenderNodeDefaultCameras final : public RENDER_NS::IRenderNode {
36 public:
37     RenderNodeDefaultCameras() = default;
38     ~RenderNodeDefaultCameras() override = default;
39 
40     void InitNode(RENDER_NS::IRenderNodeContextManager& renderNodeContextMgr) override;
41     void PreExecuteFrame() override;
42     void ExecuteFrame(RENDER_NS::IRenderCommandList& cmdList) override;
GetExecuteFlags()43     ExecuteFlags GetExecuteFlags() const override
44     {
45         // there should be cameras every frame with 3D
46         return 0U;
47     }
48 
49     // for plugin / factory interface
50     static constexpr BASE_NS::Uid UID { "b42910bb-33c4-4790-a257-3f1837415fce" };
51     static constexpr char const* TYPE_NAME = "RenderNodeDefaultCameras";
52     static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT;
53     static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE;
54     static IRenderNode* Create();
55     static void Destroy(IRenderNode* instance);
56 
57 private:
58     struct JitterProjection {
59         BASE_NS::Math::Mat4X4 baseProj { BASE_NS::Math::IDENTITY_4X4 };
60         BASE_NS::Math::Mat4X4 proj { BASE_NS::Math::IDENTITY_4X4 };
61         BASE_NS::Math::Vec4 jitter { 0.0f, 0.0f, 0.0f, 0.0f };
62     };
63 
64     // get projection matrix with possible jittering
65     JitterProjection GetProjectionMatrix(const RenderCamera& camera, const bool prevFrame) const;
66     BASE_NS::Math::Mat4X4 GetShadowBiasMatrix(
67         const IRenderDataStoreDefaultLight* dataStore, const RenderCamera& camera) const;
68 
69     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
70     CORE_NS::IFrustumUtil* frustumUtil_ { nullptr };
71 
72     SceneRenderDataStores stores_;
73 
74     RENDER_NS::RenderHandleReference resHandle_;
75     uint32_t jitterIndex_ { 0u };
76 };
77 CORE3D_END_NAMESPACE()
78 
79 #endif // CORE__RENDER__NODE__RENDER_NODE_DEFAULT_CAMERAS_H
80