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 API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H 17 #define API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H 18 19 #include "render/shaders/common/render_compatibility_common.h" 20 21 // defines 22 #ifdef VULKAN 23 24 // needs to match api/core/render/render_data_store_render_pods.h 25 #define POST_PROCESS_SPECIALIZATION_TONEMAP_BIT (1 << 0) 26 #define POST_PROCESS_SPECIALIZATION_VIGNETTE_BIT (1 << 1) 27 #define POST_PROCESS_SPECIALIZATION_DITHER_BIT (1 << 2) 28 #define POST_PROCESS_SPECIALIZATION_COLOR_CONVERSION_BIT (1 << 3) 29 #define POST_PROCESS_SPECIALIZATION_COLOR_FRINGE_BIT (1 << 4) 30 31 #define POST_PROCESS_SPECIALIZATION_BLUR_BIT (1 << 8) 32 #define POST_PROCESS_SPECIALIZATION_BLOOM_BIT (1 << 9) 33 #define POST_PROCESS_SPECIALIZATION_FXAA_BIT (1 << 10) 34 #define POST_PROCESS_SPECIALIZATION_TAA_BIT (1 << 11) 35 36 #define POST_PROCESS_INDEX_TONEMAP 0 37 #define POST_PROCESS_INDEX_VIGNETTE 1 38 #define POST_PROCESS_INDEX_DITHER 2 39 #define POST_PROCESS_INDEX_COLOR_CONVERSION 3 40 #define POST_PROCESS_INDEX_COLOR_FRINGE 4 41 42 #define POST_PROCESS_INDEX_BLUR 8 43 #define POST_PROCESS_INDEX_BLOOM 9 44 #define POST_PROCESS_INDEX_FXAA 10 45 #define POST_PROCESS_INDEX_TAA 11 46 #define POST_PROCESS_INDEX_DOF 12 47 #define POST_PROCESS_INDEX_MOTION_BLUR 13 48 49 // should be aligned to 512 (i.e. 14 x vec4 + 2 x vec4 + 16 x vec4) 50 #define POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT 14 51 #define POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT 16 52 // aligned to 256 53 #define POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT 16 54 55 #define CORE_POST_PROCESS_TONEMAP_ACES 0 56 #define CORE_POST_PROCESS_TONEMAP_ACES_2020 1 57 #define CORE_POST_PROCESS_TONEMAP_FILMIC 2 58 #define CORE_POST_PROCESS_TONEMAP_PBR_NEUTRAL 3 59 60 #define CORE_POST_PROCESS_DITHER_INTERLEAVED 0 61 #define CORE_POST_PROCESS_DITHER_TRIANGLE 1 62 #define CORE_POST_PROCESS_DITHER_TRIANGLE_RGB 2 63 64 #define CORE_POST_PROCESS_COLOR_CONVERSION_SRGB (1 << 0) 65 #define CORE_POST_PROCESS_COLOR_CONVERSION_ALPHA_MULTIPLY (1 << 1) 66 67 #define TAA_USE_BICUBIC_BIT 1 68 #define TAA_USE_VARIANCE_CLIPPING_BIT 2 69 #define TAA_USE_YCOCG_BIT 3 70 #define TAA_IGNORE_EDGES_BIT 4 71 72 #else 73 74 // note global post process UBO struct alignment for 512 75 constexpr uint32_t POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT { 14u }; 76 constexpr uint32_t POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT { 16u }; 77 // note UBO struct alignment for 256 78 constexpr uint32_t POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT { 16u }; 79 80 constexpr uint32_t TAA_USE_BICUBIC_BIT { 1u }; 81 constexpr uint32_t TAA_USE_VARIANCE_CLIPPING_BIT { 2u }; 82 constexpr uint32_t TAA_USE_YCOCG_BIT { 3u }; 83 constexpr uint32_t TAA_IGNORE_EDGES_BIT { 4u }; 84 85 #endif 86 87 // the same data throughout the pipeline 88 // should be aligned to 512 (i.e. 32 x vec4) 89 // needs to match api/core/render/RenderDataStoreRenderPods.h 90 struct GlobalPostProcessStruct { 91 // enable flags 92 uvec4 flags; 93 // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint) 94 vec4 renderTimings; 95 96 // all factors from defines 97 vec4 factors[POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT]; 98 99 // all user factors that are automatically mapped 100 vec4 userFactors[POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT]; 101 }; 102 103 // local data for a specific post process 104 // should be aligned to 256 (i.e. 16 x vec4) 105 // NOTE: one can create a new struct in their own shader, please note the alignment 106 struct LocalPostProcessStruct { 107 // all factors for the specific post process material 108 vec4 factors[POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT]; 109 }; 110 111 struct LocalPostProcessPushConstantStruct { 112 // viewport size and inverse viewport size for this draw 113 vec4 viewportSizeInvSize; 114 // fast factors for effect, might be direction for blur, some specific coefficients etc. 115 vec4 factor; 116 }; 117 118 struct PostProcessTonemapStruct { 119 vec4 texSizeInvTexSize; 120 121 uvec4 flags; 122 123 vec4 tonemap; 124 vec4 vignette; 125 vec4 colorFringe; 126 vec4 dither; 127 // .x is thresholdHard, .y is thresholdSoft, .z is amountCoefficient, .w is dirtMaskCoefficient 128 vec4 bloomParameters; 129 }; 130 131 #endif // API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H 132