• 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 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     void AddCameras(const IRenderDataStoreDefaultCamera* dsCamera, const IRenderDataStoreDefaultLight* dsLight,
65         const BASE_NS::array_view<const RenderCamera> cameras, uint8_t* const data, const uint32_t cameraOffset);
66     void AddEnvironments(const IRenderDataStoreDefaultCamera* dsCamera,
67         const BASE_NS::array_view<const RenderCamera::Environment> environments, uint8_t* const data);
68     // get projection matrix with possible jittering
69     JitterProjection GetProjectionMatrix(const RenderCamera& camera, const bool prevFrame) const;
70     BASE_NS::Math::Mat4X4 GetShadowBiasMatrix(
71         const IRenderDataStoreDefaultLight* dataStore, const RenderCamera& camera) const;
72     BASE_NS::Math::UVec4 GetMultiViewCameraIndices(
73         const IRenderDataStoreDefaultCamera* rds, const RenderCamera& cam, uint32_t cameraCount);
74     BASE_NS::Math::Mat4X4 ResolveViewMatrix(const RenderCamera& camera) const;
75 
76     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
77     CORE_NS::IFrustumUtil* frustumUtil_ { nullptr };
78 
79     SceneRenderDataStores stores_;
80 
81     RENDER_NS::RenderHandleReference camHandle_;
82     RENDER_NS::RenderHandleReference envHandle_;
83     uint32_t jitterIndex_ { 0U };
84 
85     BASE_NS::vector<RenderCamera> cubemapCameras_;
86     BASE_NS::vector<BASE_NS::Math::Mat4X4> cubemapMatrices_;
87 };
88 CORE3D_END_NAMESPACE()
89 
90 #endif // CORE__RENDER__NODE__RENDER_NODE_DEFAULT_CAMERAS_H
91