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_UTIL_COMPONENT_UTIL_FUNCTIONS_H
17 #define CORE_UTIL_COMPONENT_UTIL_FUNCTIONS_H
18 
19 #include <base/math/mathf.h>
20 #include <core/namespace.h>
21 
CORE3D_BEGIN_NAMESPACE()22 CORE3D_BEGIN_NAMESPACE()
23 namespace ComponentUtilFunctions {
24 constexpr float LIGHT_COMPONENT_USER_SET_MIN_LIGHT_RANGE = 0.0001f;
25 /**
26  * Calculates (tries to evaluate) a valid light range if one is not given by the user
27  * @param lightRange If smaller than LIGHT_COMPONENT_USER_SET_MIN_LIGHT_RANGE (i.e. 0) new range is calculated.
28  * @param lightIntensity Used to calculate range if light range is not set.
29  */
30 inline float CalculateSafeLightRange(const float lightRange, const float lightIntensity)
31 {
32     float range = lightRange;
33     if (range <= LIGHT_COMPONENT_USER_SET_MIN_LIGHT_RANGE) { // calculate range
34         constexpr float minLightIntensityAdd = 20.0f;
35         constexpr float powValue = 1.5f;
36         range = BASE_NS::Math::sqrt(BASE_NS::Math::pow(lightIntensity + minLightIntensityAdd, powValue));
37     }
38     return range;
39 }
40 } // namespace ComponentUtilFunctions
41 CORE3D_END_NAMESPACE()
42 
43 #endif // CORE_UTIL_COMPONENT_UTIL_FUNCTIONS_H
44