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 #if !defined(API_3D_ECS_COMPONENTS_PLANAR_REFLECTION_COMPONENT_H) || defined(IMPLEMENT_MANAGER)
17 #define API_3D_ECS_COMPONENTS_PLANAR_REFLECTION_COMPONENT_H
18 
19 #if !defined(IMPLEMENT_MANAGER)
20 #include <3d/ecs/components/layer_defines.h>
21 #include <3d/namespace.h>
22 #include <base/math/vector.h>
23 #include <core/ecs/component_struct_macros.h>
24 #include <core/ecs/entity_reference.h>
25 #include <core/ecs/intf_component_manager.h>
26 
27 CORE3D_BEGIN_NAMESPACE()
28 #endif
29 
30 /** Planar reflection is used to create planar reflections, like mirrors.
31  */
32 BEGIN_COMPONENT(IPlanarReflectionComponentManager, PlanarReflectionComponent)
33 #if !defined(IMPLEMENT_MANAGER)
34     enum FlagBits : uint8_t {
35         /** Disables the reflection, does not affect the plane rendering. */
36         ACTIVE_RENDER_BIT = (1 << 0),
37         MSAA_BIT = (1 << 2)
38     };
39     /** Container for planar reflection flag bits */
40     using Flags = uint8_t;
41 #endif
42 
43     /** Downsample percentage (relative to render resolution), affects reflection quality.
44      */
45     DEFINE_PROPERTY(float, screenPercentage, "Downsample Percentage", 0, 0.5f)
46 
47     /** Quick access to current render target resolution.
48      */
49     DEFINE_ARRAY_PROPERTY(uint32_t, 2, renderTargetResolution, "Render Target Resolution", 0, ARRAY_VALUE(0, 0))
50 
51     /** Reflection output render target.
52      */
53     DEFINE_PROPERTY(CORE_NS::EntityReference, colorRenderTarget, "Render Output Target", 0, )
54 
55     /** Reflection pass depth render target.
56      */
57     DEFINE_PROPERTY(CORE_NS::EntityReference, depthRenderTarget, "Depth Output Target", 0, )
58 
59     /** Clip offset to reflection plane.
60      */
61     DEFINE_PROPERTY(float, clipOffset, "Reflection Clip Offset", 0, VALUE(0.0f))
62 
63     /** Additional flags for reflection processing.
64      */
65     DEFINE_BITFIELD_PROPERTY(Flags, additionalFlags, "Flags", PropertyFlags::IS_BITFIELD,
66         VALUE(FlagBits::ACTIVE_RENDER_BIT), PlanarReflectionComponent::FlagBits)
67 
68     /** Defines a layer mask which affects reflection camera's rendering. Default is all layer mask when the
69      * reflection camera renders objects from all layers. */
70     DEFINE_BITFIELD_PROPERTY(uint64_t, layerMask, "Layer Mask", PropertyFlags::IS_BITFIELD,
71         VALUE(LayerConstants::ALL_LAYER_MASK), LayerFlagBits)
72 
73 END_COMPONENT(IPlanarReflectionComponentManager, PlanarReflectionComponent, "5081ccf4-2013-43c1-b9bb-23041e73ac6d")
74 #if !defined(IMPLEMENT_MANAGER)
75 CORE3D_END_NAMESPACE()
76 #endif
77 
78 #endif
79