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 API_RENDER_SHADERS_COMMON_POST_PROCESS_COMMON_H
17 #define API_RENDER_SHADERS_COMMON_POST_PROCESS_COMMON_H
18 
19 #include "render_post_process_structs_common.h"
20 
21 #ifdef VULKAN
22 
23 /**
24  * returns vignette coefficient with values in the range 0-1
25  */
getVignetteCoeff(const vec2 uv,CORE_RELAXEDP const float coeff,CORE_RELAXEDP const float power)26 float getVignetteCoeff(const vec2 uv, CORE_RELAXEDP const float coeff, CORE_RELAXEDP const float power)
27 {
28     vec2 uvVal = uv.xy * (vec2(1.0) - uv.yx);
29     float vignette = uvVal.x * uvVal.y * coeff;
30     vignette = pow(vignette, power);
31     return clamp(vignette, 0.0, 1.0);
32 }
33 
34 /**
35  * returns chroma coefficient with values in the range 0-1
36  */
getChromaCoeff(const vec2 uv,CORE_RELAXEDP const float chromaCoefficient)37 float getChromaCoeff(const vec2 uv, CORE_RELAXEDP const float chromaCoefficient)
38 {
39     // this is cheap chroma
40     vec2 distUv = (uv - 0.5) * 2.0;
41     return dot(distUv, distUv) * chromaCoefficient;
42 }
43 
44 /**
45  * Returns 0-1 and input should be 0-1
46  */
RandomDither(vec2 st)47 float RandomDither(vec2 st)
48 {
49     return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453);
50 }
51 
52 #endif
53 
54 #endif // API_RENDER_SHADERS_COMMON_POST_PROCESS_COMMON_H
55