#version 460 compatibility
#define COMP 1
#extension GL_KHR_shader_subgroup_ballot : enable
/*
    References:
        [EPI20] Epic Games, Inc. "Unreal Engine Sky Atmosphere Rendering Technique". 2020.
            MIT License. Copyright (c) 2020 Epic Games, Inc.
            https:
        [HIL20] Hillaire, Sébastien. "A Scalable and Production Ready Sky and Atmosphere Rendering Technique".
            EGSR 2020. 2020.
            https:
        [INT17] Intel Corporation. "Outdoor Light Scattering Sample". 2017.
            Apache License 2.0. Copyright (c) 2017 Intel Corporation.
            https:
        [PRE99] Preetham, A. J. et al. "A Practical Analytic Model for Daylight"
            SIGGRAPH 1999. 1999.
            https:

        You can find full license texts in /licenses

    Other Credits:
        Jessie - Helping with Mie coefficients (https:
*/
// This file is generated by options.main.kts. Do not edit this file manually.
#define TITLE_VERSION 3//[0 1 2 3 4 5]
#define SETTING_PBR_MATERIAL 1//[0 1 2]
#define SETTING_BUILTIN_METALNESS
#ifdef SETTING_BUILTIN_METALNESS
#endif
#define SETTING_EMISSIVE_STRENGTH 4.0//[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0]
#define SETTING_EMISSIVE_PBR_VALUE_CURVE 0.9//[0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0]
#define SETTING_EMISSIVE_ALBEDO_COLOR_CURVE 2.0//[0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0]
#define SETTING_EMISSIVE_ALBEDO_LUM_CURVE 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_EMISSIVE_ARMOR_GLINT_MULT -10//[-20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0]
#define SETTING_EMISSIVE_ARMOR_GLINT_CURVE 1.3//[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define SETTING_MINIMUM_F0 12//[4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32]
#define SETTING_SOLID_MINIMUM_ROUGHNESS 6//[4 5 6 7 8 9 10 11 12 13 14 15 16]
#define SETTING_SOLID_MAXIMUM_ROUGHNESS 5//[2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
#define SETTING_WATER_ROUGHNESS 9.0//[4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0]
#define SETTING_TRANSLUCENT_ROUGHNESS_REDUCTION 1.0//[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0]
#define SETTING_TRANSLUCENT_MINIMUM_ROUGHNESS 10.0//[4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0]
#define SETTING_TRANSLUCENT_MAXIMUM_ROUGHNESS 5.0//[1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0]
#define SETTING_MAXIMUM_SPECULAR_LUMINANCE 65536//[256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216]
#define SETTING_SHADOW_MAP_RESOLUTION 2048//[1024 2048 3072 4096]
const float shadowDistance = 512.0;//[64.0 128.0 192.0 256.0 384.0 512.0]
#define SETTING_DENOISER_HISTORY_LENGTH 64//[4 6 8 12 16 24 32 48 64 96 128 192 256]
#define SETTING_ATM_ALT_SCALE 1000//[1 2 3 4 5 6 7 8 9 10 10 20 30 40 50 60 70 80 90 100 100 200 300 400 500 600 700 800 900 1000 1000]
#define SETTING_ATM_D_SCALE 1000//[1 2 3 4 5 6 7 8 9 10 10 20 30 40 50 60 70 80 90 100 100 200 300 400 500 600 700 800 900 1000 1000]
#define SETTING_ATM_GROUND_ALBEDO_R 45//[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255]
#define SETTING_ATM_GROUND_ALBEDO_G 89//[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255]
#define SETTING_ATM_GROUND_ALBEDO_B 82//[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255]
#define SETTING_EPIPOLAR_SLICES 1024//[256 512 1024 2048]
#define SETTING_SLICE_SAMPLES 512//[128 256 512 1024]
#define SETTING_ATM_MIE_SCT_MUL 1.0//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0]
#define SETTING_ATM_MIE_ABS_MUL 0.1//[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.2 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.3 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.4 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.6 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.69 1.7 1.71 1.72 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.91 1.92 1.93 1.94 1.95 1.96 1.97 1.98 1.99 2.0]
#define SETTING_ATM_RAY_SCT_MUL 1.0//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0]
#define SETTING_ATM_OZO_ABS_MUL 1.0//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0]
#define SETTING_SKYVIEW_RES 256//[128 256 512 1024]
#define SETTING_CLOUDS_MS_RADIUS -2.5//[-5.0 -4.75 -4.5 -4.25 -4.0 -3.75 -3.5 -3.25 -3.0 -2.75 -2.5 -2.25 -2.0 -1.75 -1.5 -1.25 -1.0 -0.75 -0.5 -0.25 0.0]
#define SETTING_CLOUDS_CU
#ifdef SETTING_CLOUDS_CU
#endif
#define SETTING_CLOUDS_LOW_UPSCALE_FACTOR 2//[0 1 2 3 4 5 6]
#define SETTING_CLOUDS_LOW_MAX_ACCUM 16//[4 6 8 12 16 24 32 48 64 96 128]
#define SETTING_CLOUDS_CU_HEIGHT 1.0//[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0]
#define SETTING_CLOUDS_CU_THICKNESS 2.0//[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_BASE_FREQ 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_CURL_FREQ 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_BILLOWY_FREQ 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_BILLOWY_CURL_STR 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_HIGH_BILLOWY_FREQ 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_HIGH_BILLOWY_CURL_STR 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_WISPS_FREQ 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_LOW_WISPS_CURL_STR 0.0//[-4.0 -3.9 -3.8 -3.7 -3.6 -3.5 -3.4 -3.3 -3.2 -3.1 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0]
#define SETTING_CLOUDS_CI
#ifdef SETTING_CLOUDS_CI
#endif
#define SETTING_CLOUDS_CI_HEIGHT 9.0//[6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12.0 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13.0 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 14.0]
#define SETTING_CLOUDS_CI_DENSITY 1.0//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0]
#define SETTING_CLOUDS_CI_COVERAGE 0.4//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define SETTING_CLOUDS_CI_PHASE_RATIO 0.6//[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define SETTING_SUN_RADIUS 1.0//[0.0078125 0.015625 0.03125 0.0625 0.125 0.25 0.5 1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0]
#define SETTING_SUN_DISTANCE 1.0//[0.0078125 0.015625 0.03125 0.0625 0.125 0.25 0.5 1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0]
const float sunPathRotation = -20.0;//[-90.0 -89.0 -88.0 -87.0 -86.0 -85.0 -84.0 -83.0 -82.0 -81.0 -80.0 -79.0 -78.0 -77.0 -76.0 -75.0 -74.0 -73.0 -72.0 -71.0 -70.0 -69.0 -68.0 -67.0 -66.0 -65.0 -64.0 -63.0 -62.0 -61.0 -60.0 -59.0 -58.0 -57.0 -56.0 -55.0 -54.0 -53.0 -52.0 -51.0 -50.0 -49.0 -48.0 -47.0 -46.0 -45.0 -44.0 -43.0 -42.0 -41.0 -40.0 -39.0 -38.0 -37.0 -36.0 -35.0 -34.0 -33.0 -32.0 -31.0 -30.0 -29.0 -28.0 -27.0 -26.0 -25.0 -24.0 -23.0 -22.0 -21.0 -20.0 -19.0 -18.0 -17.0 -16.0 -15.0 -14.0 -13.0 -12.0 -11.0 -10.0 -9.0 -8.0 -7.0 -6.0 -5.0 -4.0 -3.0 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0]
#define SETTING_REAL_SUN_TEMPERATURE
#ifdef SETTING_REAL_SUN_TEMPERATURE
#endif
#define SETTING_SUN_TEMPERATURE 5700//[1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 4300 4400 4500 4600 4700 4800 4900 5000 5100 5200 5300 5400 5500 5600 5700 5800 5900 6000 6100 6200 6300 6400 6500 6600 6700 6800 6900 7000 7100 7200 7300 7400 7500 7600 7700 7800 7900 8000 8100 8200 8300 8400 8500 8600 8700 8800 8900 9000 9100 9200 9300 9400 9500 9600 9700 9800 9900 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000 22000 23000 24000 25000 26000 27000 28000 29000 30000 31000 32000 33000 34000 35000 36000 37000 38000 39000 40000 41000 42000 43000 44000 45000 46000 47000 48000 49000 50000]
#define SETTING_MOON_RADIUS 1.0//[0.0078125 0.015625 0.03125 0.0625 0.125 0.25 0.5 1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0]
#define SETTING_MOON_DISTANCE 1.0//[0.0078125 0.015625 0.03125 0.0625 0.125 0.25 0.5 1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0]
#define SETTING_MOON_ALBEDO 0.12//[0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SETTING_MOON_COLOR_R 0.8//[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SETTING_MOON_COLOR_G 0.9//[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SETTING_MOON_COLOR_B 1.0//[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define SETTING_STARMAP_INTENSITY 6//[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
#define SETTING_STARMAP_BRIGHT_STAR_BOOST 4//[0 1 2 3 4 5 6 7 8]
#define SETTING_STARMAP_GAMMA 0.8//[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define SETTING_MATERIAL_COLOR_SPACE 1//[0 1 2 3 4 5 6 7 8]
#define SETTING_MATERIAL_TRANSFER_FUNC 3//[0 1 2 3 4 5 6 7]
#define SETTING_WORKING_COLOR_SPACE 8//[0 1 2 3 4 5 6 7 8]
#define SETTING_DRT_WORKING_COLOR_SPACE 1//[0 1 2 3 4 5 6 7 8]
//#define SETTING_CONSTELLATIONS
#ifdef SETTING_CONSTELLATIONS
#endif
//#define SETTING_ASSUME_NVIDIA_GPU
#ifdef SETTING_ASSUME_NVIDIA_GPU
#endif
//#define SETTING_DEBUG_AE
#ifdef SETTING_DEBUG_AE
#endif
//#define SETTING_GI_USE_REFERENCE
#ifdef SETTING_GI_USE_REFERENCE
#endif
#if SETTING_SHADOW_MAP_RESOLUTION == 1024
#define SHADOW_MAP_SIZE_D16 64
const int shadowMapResolution = 1024;
#elif SETTING_SHADOW_MAP_RESOLUTION == 2048
#define SHADOW_MAP_SIZE_D16 128
const int shadowMapResolution = 2048;
#elif SETTING_SHADOW_MAP_RESOLUTION == 3072
#define SHADOW_MAP_SIZE_D16 192
const int shadowMapResolution = 3072;
#elif SETTING_SHADOW_MAP_RESOLUTION == 4096
#define SHADOW_MAP_SIZE_D16 256
const int shadowMapResolution = 4096;
#endif
const vec2 SHADOW_MAP_SIZE = vec2(float(shadowMapResolution), 1.0 / float(shadowMapResolution));
#ifndef SKIP_UNIFORMS
uniform int heldItemId;
uniform int worldTime;
uniform int frameCounter;
uniform float sunAngle;
uniform float near;
uniform float far;
uniform vec3 sunPosition;
uniform vec3 shadowLightPosition;
uniform vec3 cameraPosition;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferPreviousModelView;
uniform mat4 textureMatrix = mat4(1.0);
#endif
float vanillaFarPlane = far;
float vanillaNearPlane = near;
#if defined(DISTANT_HORIZONS)
uniform float dhNearPlane;
uniform float dhFarPlane;
#elif defined(VOXY)
uniform int vxRenderDistance;
#endif
#if defined(DISTANT_HORIZONS)
float farPlane = max(dhFarPlane, far);
float nearPlane = min(dhNearPlane, near);
#elif defined(VOXY)
float farPlane = max(far, float(vxRenderDistance * 16));
float nearPlane = near;
#else
float farPlane = far;
float nearPlane = near;
#endif
mat4 gbufferPrevModelView = gbufferPreviousModelView;
#ifndef SKIP_UNIFORMS
uniform vec3 uval_sunDirView;
uniform vec3 uval_sunDirWorld;
uniform vec3 uval_moonDirView;
uniform vec3 uval_moonDirWorld;
uniform vec2 uval_mainImageSizeRcp;
uniform int uval_mainImageSizeIX;
uniform int uval_mainImageSizeIY;
uniform vec2 uval_taaJitter;
uniform vec2 uval_taaJitterUV;
uniform int uval_restirSpatialTileOffsetX;
uniform int uval_restirSpatialTileOffsety;
ivec2 uval_restirSpatialTileOffset = ivec2(uval_restirSpatialTileOffsetX, uval_restirSpatialTileOffsety);
#endif
ivec2 uval_mainImageSizeI = ivec2(uval_mainImageSizeIX, uval_mainImageSizeIY);
#ifndef GLOBAL_DATA_MODIFIER
#define GLOBAL_DATA_MODIFIER restrict readonly buffer
#endif
struct AEData {
    vec4 lastScreenAvgLum;
    vec4 screenAvgLum;
    vec4 expValues;
    vec2 hsPercents;
    uint shadowCount;
    uint highlightCount;
    uint weightSum;
    #ifdef SETTING_DEBUG_AE
    uint lumHistogram[256];
    uint lumHistogramMaxBinCount;
    float finalAvgLum;
    #endif
};
struct CameraData {
    uint frustumPlaneCount;
    vec4 frustumPlanes[6];
};
layout(std430, binding = 0) GLOBAL_DATA_MODIFIER GlobalData {
    uvec4 global_dispatchSize1;
    uvec4 global_dispatchSize2;
    uvec4 global_dispatchSize3;
    uvec4 global_dispatchSize4;
    mat4 gbufferPrevModelViewInverse;
    mat4 global_shadowRotationMatrix;
    mat4 global_shadowRotationMatrixInverse;
    mat4 global_taaJitterMat;
    mat4 global_camProj;
    mat4 global_camProjInverse;
    mat4 global_prevCamProj;
    mat4 global_prevCamProjInverse;
    mat4 global_shadowProj;
    mat4 global_shadowProjInverse;
    mat4 global_shadowProjNext;
    mat4 global_shadowProjNextInverse;
    mat4 global_shadowView;
    mat4 global_shadowViewInverse;
    mat4 global_sceneToShadowNDC;
    mat4 global_shadowViewToShadowNDC;
    mat4 global_shadowNDCToScene;
    vec3 global_prevCameraDelta;
    CameraData global_cameraData;
    vec2 global_mipmapSizes[16];
    vec2 global_mipmapSizesRcp[16];
    ivec4 global_mipmapTiles3[16];
    ivec2 global_mipmapSizesI[16];
    ivec2 global_mipmapSizePrefixesPadded[16];
    ivec2 global_mipmapSizePrefixes[16];
    ivec4 global_hizTiles[16];
    ivec4 global_mipmapTileCeil[16];
    ivec4 global_mipmapTileCeilPadded[16];
    ivec3 global_shadowAABBMinPrev;
    ivec3 global_shadowAABBMaxPrev;
    ivec3 global_shadowAABBMin;
    ivec3 global_shadowAABBMax;
    vec3 global_shadowAABBMinHistory;
    vec3 global_shadowAABBMaxHistory;
    ivec3 global_shadowAABBMinNew;
    ivec3 global_shadowAABBMaxNew;
    float global_focusDistance;
    int global_lastWorldTime;
    float global_historyResetFactor;
    vec4 global_motionFactor;
    vec4 global_taaResetFactor;
    float global_turbidity;
    AEData global_aeData;
    uint global_atomicCounters[16];
};
layout(std430, binding = 1) GLOBAL_DATA_MODIFIER IndirectComputeData {
    uint indirectComputeData[];
};
#ifndef SKIP_UNIFORMS
uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform usampler2D colortex8;
uniform usampler2D colortex9;
uniform sampler2D colortex10;
uniform sampler3D usam_skyViewLUT;
uniform sampler3D usam_stbnVec1;
uniform sampler3D usam_stbnVec2;
uniform sampler2D usam_starmap;
uniform sampler2D usam_constellations;
uniform sampler2D usam_cirrus;
uniform sampler2D usam_cloudPhases;
uniform sampler2D usam_hiz;
uniform usampler1D usam_pbrLUT0;
uniform usampler1D usam_pbrLUT1;
uniform sampler1D usam_f82;
#endif
#ifndef SKIP_UNIFORMS
uniform sampler2D usam_rgba16f;
uniform usampler2D usam_rgba32ui;
uniform sampler2D usam_frgba16f;
#endif
ivec2 _textile_texelToTexel(ivec2 texelPos, ivec2 tileOffset, ivec2 tileSize) {
    return clamp(texelPos, ivec2(0), tileSize - 1) + tileOffset;
}
vec2 _textile_uvToUV(vec2 uv, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(uv * tileSizeF, vec2(0.5), tileSizeF - 0.5) + tileOffsetF;
    return clamp(textureTexelPos * atlastSizeRcp, 0.0, 1.0);
}
vec2 _textile_uvToGatherUV(vec2 uv, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(uv * tileSizeF, vec2(1.0), tileSizeF - 1.0) + tileOffsetF;
    return clamp(textureTexelPos * atlastSizeRcp, 0.0, 1.0);
}
vec2 _textile_texelToGatherUV(vec2 texelPos, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(texelPos, vec2(1.0), tileSizeF - 1.0) + tileOffsetF;
    return clamp(textureTexelPos * atlastSizeRcp, 0.0, 1.0);
}
#define _shadesmith_RGBA16F_0_OFFSET (uval_mainImageSizeI * ivec2(0, 0))
#define _shadesmith_RGBA16F_0_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA16F_0_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA16F_0_OFFSET, _shadesmith_RGBA16F_0_SIZE)
#define _shadesmith_RGBA16F_7_OFFSET (uval_mainImageSizeI * ivec2(2, 1))
#define _shadesmith_RGBA16F_7_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA16F_7_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA16F_7_OFFSET, _shadesmith_RGBA16F_7_SIZE)
#define transient_gi2Reprojected_fetch(x) texelFetch(usam_rgba16f, _shadesmith_RGBA16F_7_TEXEL_TO_TEXEL(x), 0)
#define transient_shadow_fetch(x) texelFetch(usam_rgba16f, _shadesmith_RGBA16F_0_TEXEL_TO_TEXEL(x), 0)
#define _shadesmith_RGBA8_2_OFFSET (uval_mainImageSizeI * ivec2(1, 0))
#define _shadesmith_RGBA8_2_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA8_2_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA8_2_OFFSET, _shadesmith_RGBA8_2_SIZE)
#define transient_lmCoord_store(x, v) imageStore(uimg_rgba8, _shadesmith_RGBA8_2_TEXEL_TO_TEXEL(x), v)
#define _shadesmith_RGBA32UI_0_OFFSET (uval_mainImageSizeI * ivec2(0, 0))
#define _shadesmith_RGBA32UI_0_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA32UI_0_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA32UI_0_OFFSET, _shadesmith_RGBA32UI_0_SIZE)
#define _shadesmith_RGBA32UI_5_OFFSET (uval_mainImageSizeI * ivec2(1, 2))
#define _shadesmith_RGBA32UI_5_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA32UI_5_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA32UI_5_OFFSET, _shadesmith_RGBA32UI_5_SIZE)
#define history_lowCloud_store(x, v) imageStore(uimg_rgba32ui, _shadesmith_RGBA32UI_0_TEXEL_TO_TEXEL(x), v)
#define transient_lowCloudAccumulated_fetch(x) texelFetch(usam_rgba32ui, _shadesmith_RGBA32UI_5_TEXEL_TO_TEXEL(x), 0)
#define _shadesmith_RG32UI_3_OFFSET (uval_mainImageSizeI * ivec2(1, 1))
#define _shadesmith_RG32UI_3_SIZE uval_mainImageSizeI
#define _shadesmith_RG32UI_3_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RG32UI_3_OFFSET, _shadesmith_RG32UI_3_SIZE)
#define transient_giRadianceInputs_store(x, v) imageStore(uimg_rg32ui, _shadesmith_RG32UI_3_TEXEL_TO_TEXEL(x), v)
#define _shadesmith_FRGBA16F_ATLAS_SIZE vec2(1056.0, 832.0)
#define _shadesmith_FRGBA16F_ATLAS_SIZE_RCP (vec2(1.0) / _shadesmith_FRGBA16F_ATLAS_SIZE)
#define _shadesmith_FRGBA16F_1_OFFSET_F vec2(1024.0, 0.0)
#define _shadesmith_FRGBA16F_1_SIZE_F vec2(32.0, 192.0)
#define _shadesmith_FRGBA16F_1_UV_TO_UV(uv) _textile_uvToUV(uv, _shadesmith_FRGBA16F_1_OFFSET_F, _shadesmith_FRGBA16F_1_SIZE_F, _shadesmith_FRGBA16F_ATLAS_SIZE_RCP)
#define _shadesmith_FRGBA16F_2_OFFSET_F vec2(0.0, 768.0)
#define _shadesmith_FRGBA16F_2_SIZE_F vec2(256.0, 64.0)
#define _shadesmith_FRGBA16F_2_UV_TO_UV(uv) _textile_uvToUV(uv, _shadesmith_FRGBA16F_2_OFFSET_F, _shadesmith_FRGBA16F_2_SIZE_F, _shadesmith_FRGBA16F_ATLAS_SIZE_RCP)
#define persistent_cloudsAmbLUT_sample(x) texture(usam_frgba16f, _shadesmith_FRGBA16F_1_UV_TO_UV(x))
#define persistent_transmittanceLUT_sample(x) texture(usam_frgba16f, _shadesmith_FRGBA16F_2_UV_TO_UV(x))
#ifdef DISABLE_FP16
#define NO_HALF a
#define hf
#define float16_t float
#define f16vec2 vec2
#define f16vec3 vec3
#define f16vec4 vec4
#define f16mat2 mat2
#define f16mat3 mat3
#define f16mat4 mat4
#else
#if defined MC_GL_AMD_gpu_shader_half_float
#extension GL_AMD_gpu_shader_half_float : enable
#elif defined MC_GL_NV_gpu_shader5 || defined SETTING_ASSUME_NVIDIA_GPU
#extension GL_NV_gpu_shader5 : enable
#else
#define NO_HALF a
#define hf
#define float16_t float
#define f16vec2 vec2
#define f16vec3 vec3
#define f16vec4 vec4
#define f16mat2 mat2
#define f16mat3 mat3
#define f16mat4 mat4
#endif
#endif
#define COLORS2_COLORSPACES_CIE_XYZ 0
#define COLORS2_COLORSPACES_SRGB 1
#define COLORS2_COLORSPACES_REC709 2
#define COLORS2_COLORSPACES_REC2020 3
#define COLORS2_COLORSPACES_DCI_P3 4
#define COLORS2_COLORSPACES_ADOBE_RGB_1998 5
#define COLORS2_COLORSPACES_ACES_AP0 6
#define COLORS2_COLORSPACES_ACES_AP1 7
#define COLORS2_COLORSPACES_COLOR_MCSPACEFACE 8
#define _colors2_colorspaces_convert(a, b, x) colors2_colorspaces_ ## a ## _to_ ## b ##(x)
#define colors2_colorspaces_convert(a, b, x) _colors2_colorspaces_convert(a, b, x)
#define _colors2_colorspaces_luma(a, x) colors2_colorspaces_ ## a ## _luma(x)
#define colors2_colorspaces_luma(a, x) _colors2_colorspaces_luma(a, x)
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_CIE_XYZ = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_SRGB = mat3(
    3.2406, -1.5372, -0.4986,
    -0.9689, 1.8758, 0.0415,
    0.0557, -0.204, 1.057
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_REC709 = mat3(
    3.2406, -1.5372, -0.4986,
    -0.9689, 1.8758, 0.0415,
    0.0557, -0.204, 1.057
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_REC2020 = mat3(
    1.716651188, -0.3556707838, -0.2533662814,
    -0.6666843518, 1.6164812366, 0.0157685458,
    0.0176398574, -0.0427706133, 0.9421031212
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_DCI_P3 = mat3(
    2.7253940305, -1.0180030062, -0.4401631952,
    -0.7951680258, 1.6897320548, 0.0226471906,
    0.0412418914, -0.0876390192, 1.1009293786
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ADOBE_RGB_1998 = mat3(
    2.04159, -0.56501, -0.34473,
    -0.96924, 1.87597, 0.04156,
    0.01344, -0.11836, 1.01517
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP0 = mat3(
    1.0498110175, 0.0, -9.74845e-05,
    -0.4959030231, 1.3733130458, 0.0982400361,
    0.0, 0.0, 0.9912520182
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP1 = mat3(
    1.6410233797, -0.3248032942, -0.2364246952,
    -0.6636628587, 1.6153315917, 0.0167563477,
    0.0117218943, -0.008284442, 0.9883948585
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_COLOR_MCSPACEFACE = mat3(
    1.8036169276, -0.4552904521, -0.2378028419,
    -0.8777214976, 1.7861935367, 0.044102742,
    -0.0076302897, 0.0213060993, 0.9055290952
);
const mat3 _colors2_colorspaces_mat_SRGB_to_CIE_XYZ = mat3(
    0.4124, 0.3576, 0.1805,
    0.2126, 0.7152, 0.0722,
    0.0193, 0.1192, 0.9505
);
const mat3 _colors2_colorspaces_mat_SRGB_to_SRGB = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_SRGB_to_REC709 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_SRGB_to_REC2020 = mat3(
    0.6274413721, 0.3292974595, 0.0433514584,
    0.0690276171, 0.9195806669, 0.0113614226,
    0.0163642351, 0.0880171625, 0.8955649727
);
const mat3 _colors2_colorspaces_mat_SRGB_to_DCI_P3 = mat3(
    0.8686602648, 0.1289247846, 0.0025580657,
    0.034463766, 0.9618535095, 0.0036450448,
    0.0167452803, 0.071043109, 0.9121578398
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ADOBE_RGB_1998 = mat3(
    0.715177301, 0.284885616, 4.7408e-05,
    -8.1246e-05, 1.000047472, -6e-09,
    -2.7899e-05, 0.041163336, 0.958799413
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ACES_AP0 = mat3(
    0.439643004, 0.3830054714, 0.1773993089,
    0.0897157319, 0.8134750538, 0.0967822524,
    0.0175127205, 0.1115514385, 0.870882793
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ACES_AP1 = mat3(
    0.6131324224, 0.3395380158, 0.047416696,
    0.0701243808, 0.9163940113, 0.013451524,
    0.0205876575, 0.1095745716, 0.869785404
);
const mat3 _colors2_colorspaces_mat_SRGB_to_COLOR_MCSPACEFACE = mat3(
    0.6424391956, 0.2910124185, 0.066641612,
    0.01862347, 0.9688787528, 0.0124565459,
    0.0188551746, 0.1204306855, 0.8606615207
);
const mat3 _colors2_colorspaces_mat_REC709_to_CIE_XYZ = mat3(
    0.4124, 0.3576, 0.1805,
    0.2126, 0.7152, 0.0722,
    0.0193, 0.1192, 0.9505
);
const mat3 _colors2_colorspaces_mat_REC709_to_SRGB = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC709_to_REC709 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC709_to_REC2020 = mat3(
    0.6274413721, 0.3292974595, 0.0433514584,
    0.0690276171, 0.9195806669, 0.0113614226,
    0.0163642351, 0.0880171625, 0.8955649727
);
const mat3 _colors2_colorspaces_mat_REC709_to_DCI_P3 = mat3(
    0.8686602648, 0.1289247846, 0.0025580657,
    0.034463766, 0.9618535095, 0.0036450448,
    0.0167452803, 0.071043109, 0.9121578398
);
const mat3 _colors2_colorspaces_mat_REC709_to_ADOBE_RGB_1998 = mat3(
    0.715177301, 0.284885616, 4.7408e-05,
    -8.1246e-05, 1.000047472, -6e-09,
    -2.7899e-05, 0.041163336, 0.958799413
);
const mat3 _colors2_colorspaces_mat_REC709_to_ACES_AP0 = mat3(
    0.439643004, 0.3830054714, 0.1773993089,
    0.0897157319, 0.8134750538, 0.0967822524,
    0.0175127205, 0.1115514385, 0.870882793
);
const mat3 _colors2_colorspaces_mat_REC709_to_ACES_AP1 = mat3(
    0.6131324224, 0.3395380158, 0.047416696,
    0.0701243808, 0.9163940113, 0.013451524,
    0.0205876575, 0.1095745716, 0.869785404
);
const mat3 _colors2_colorspaces_mat_REC709_to_COLOR_MCSPACEFACE = mat3(
    0.6424391956, 0.2910124185, 0.066641612,
    0.01862347, 0.9688787528, 0.0124565459,
    0.0188551746, 0.1204306855, 0.8606615207
);
const mat3 _colors2_colorspaces_mat_REC2020_to_CIE_XYZ = mat3(
    0.6369580483, 0.1446169036, 0.1688809752,
    0.262700212, 0.6779980715, 0.0593017165,
    0.0, 0.028072693, 1.0609850577
);
const mat3 _colors2_colorspaces_mat_REC2020_to_SRGB = mat3(
    1.6603034854, -0.5875701425, -0.0728900602,
    -0.1243755953, 1.1328344814, -0.0083597372,
    -0.01811228, -0.1005836085, 1.1187703262
);
const mat3 _colors2_colorspaces_mat_REC2020_to_REC709 = mat3(
    1.6603034854, -0.5875701425, -0.0728900602,
    -0.1243755953, 1.1328344814, -0.0083597372,
    -0.01811228, -0.1005836085, 1.1187703262
);
const mat3 _colors2_colorspaces_mat_REC2020_to_REC2020 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC2020_to_DCI_P3 = mat3(
    1.4261665053, -0.3646122688, -0.0615542365,
    -0.0625062418, 1.0689717224, -0.0064654806,
    0.0024438227, -0.0211212969, 1.0186774743
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ADOBE_RGB_1998 = mat3(
    1.151978935, -0.0975047657, -0.0544737317,
    -0.124547502, 1.1329022557, -0.0083434163,
    -0.0225324809, -0.0498056448, 1.0723310102
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ACES_AP0 = mat3(
    0.6790856347, 0.1577009146, 0.1632134507,
    0.0460020031, 0.859054673, 0.094943324,
    -0.0005739432, 0.0284677684, 0.9721061748
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ACES_AP1 = mat3(
    0.9748949779, 0.0195991086, 0.0055059134,
    0.0021795628, 0.9955354689, 0.0022849683,
    0.0047972397, 0.0245320166, 0.9706707437
);
const mat3 _colors2_colorspaces_mat_REC2020_to_COLOR_MCSPACEFACE = mat3(
    1.02924225, -0.0545245427, 0.0252822927,
    -0.08983974, 1.0853508417, 0.0044888983,
    0.0007354405, 0.0387656211, 0.9604989385
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ = mat3(
    0.4451698156, 0.2771344092, 0.1722826698,
    0.2094916779, 0.7215952542, 0.0689130679,
    -0.0, 0.0470605601, 0.9073553944
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_SRGB = mat3(
    1.1573859234, -0.1549414014, -0.0026012394,
    -0.041378309, 1.0455482025, -0.0040707446,
    -0.0180228775, -0.0785725929, 1.0966699081
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_REC709 = mat3(
    1.1573859234, -0.1549414014, -0.0026012394,
    -0.041378309, 1.0455482025, -0.0040707446,
    -0.0180228775, -0.0785725929, 1.0966699081
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_REC2020 = mat3(
    0.7117832307, 0.2436603169, 0.0445564524,
    0.0416151636, 0.9498416297, 0.0085432067,
    -0.0008447284, 0.0191095072, 0.9817352212
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_DCI_P3 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ADOBE_RGB_1998 = mat3(
    0.8159476268, 0.1870365007, -0.0029836898,
    -0.0414978627, 1.0455710024, -0.0040618024,
    -0.0190167405, -0.0323060291, 1.0513156541
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ACES_AP0 = mat3(
    0.4897866453, 0.3183760433, 0.1918373114,
    0.0684129538, 0.8289890733, 0.1025979728,
    -4.4998e-05, 0.0454764943, 0.9545685037
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ACES_AP1 = mat3(
    0.6947248661, 0.2562644839, 0.04901065,
    0.0429788175, 0.9461757697, 0.0108454127,
    0.0036155455, 0.0430194671, 0.9533649873
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_COLOR_MCSPACEFACE = mat3(
    0.7303069694, 0.1994789445, 0.0702140861,
    -0.0187831594, 1.0091068134, 0.009676346,
    0.0013253512, 0.0553550597, 0.9433195891
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ = mat3(
    0.57667, 0.18556, 0.18823,
    0.29734, 0.62736, 0.07529,
    0.02703, 0.07069, 0.99134
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_SRGB = mat3(
    1.398208596, -0.39829809, -3.9774e-05,
    0.000136554, 0.999946439, -6.455e-06,
    3.3869e-05, -0.042926418, 1.042971631
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC709 = mat3(
    1.398208596, -0.39829809, -3.9774e-05,
    0.000136554, 0.999946439, -6.455e-06,
    3.3869e-05, -0.042926418, 1.042971631
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC2020 = mat3(
    0.8773375991, 0.0774977091, 0.0451746704,
    0.0966138895, 0.8915203988, 0.011846867,
    0.0229200098, 0.0430379497, 0.9340446591
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_DCI_P3 = mat3(
    1.2145920645, -0.2171838064, 0.0026126829,
    0.0482902509, 0.9478877447, 0.0038012193,
    0.0234515446, 0.0252011134, 0.9513504319
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ADOBE_RGB_1998 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP0 = mat3(
    0.614764313, 0.2002455356, 0.1849943834,
    0.1255320021, 0.7735159805, 0.1009365364,
    0.024527523, 0.0671725736, 0.9083019068
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP1 = mat3(
    0.857331761, 0.0932620958, 0.0494155164,
    0.0981471377, 0.8878074297, 0.0140266997,
    0.0288267153, 0.0640182469, 0.9071571651
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE = mat3(
    0.8983045668, 0.0322422724, 0.0694645249,
    0.0261430701, 0.9608432342, 0.0129923579,
    0.0264051721, 0.0759552419, 0.897641378
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ = mat3(
    0.9525523959, 0.0, 9.36786e-05,
    0.3439664498, 0.7281660966, -0.0721325464,
    0.0, 0.0, 1.0088251844
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_SRGB = mat3(
    2.5214008886, -1.1339957494, -0.3875618568,
    -0.2762140616, 1.3725955663, -0.0962823557,
    -0.0153202001, -0.1529925618, 1.1683871996
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_REC709 = mat3(
    2.5214008886, -1.1339957494, -0.3875618568,
    -0.2762140616, 1.3725955663, -0.0962823557,
    -0.0153202001, -0.1529925618, 1.1683871996
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_REC2020 = mat3(
    1.4904095205, -0.2661709193, -0.2242386013,
    -0.0801674998, 1.1821671211, -0.1019996212,
    0.0032276312, -0.0347764757, 1.0315488446
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_DCI_P3 = mat3(
    2.1546035168, -0.8084960464, -0.3461074707,
    -0.1788775564, 1.280565414, -0.1016878576,
    0.0086234533, -0.0610453898, 1.0524219365
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ADOBE_RGB_1998 = mat3(
    1.7245612643, -0.4199958158, -0.304565011,
    -0.2764756536, 1.3727208758, -0.0962338848,
    -0.0261287411, -0.0901729979, 1.1162946235
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP0 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP1 = mat3(
    1.4514393161, -0.2365107469, -0.2149285693,
    -0.0765537733, 1.1762296998, -0.0996759265,
    0.0083161484, -0.0060324498, 0.9977163014
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_COLOR_MCSPACEFACE = mat3(
    1.5384451464, -0.3392907066, -0.19915444,
    -0.2208933788, 1.3068226981, -0.0859293193,
    0.0010885009, 0.0122289218, 0.9866825774
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ = mat3(
    0.6624541811, 0.1340042065, 0.156187687,
    0.2722287168, 0.6740817658, 0.0536895174,
    -0.0055746495, 0.0040607335, 1.0103391003
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_SRGB = mat3(
    1.7048586763, -0.6217160219, -0.0832993717,
    -0.1300768242, 1.1407357748, -0.0105598017,
    -0.0239640729, -0.1289755083, 1.1530140189
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_REC709 = mat3(
    1.7048586763, -0.6217160219, -0.0832993717,
    -0.1300768242, 1.1407357748, -0.0105598017,
    -0.0239640729, -0.1289755083, 1.1530140189
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_REC2020 = mat3(
    1.0258247477, -0.0200531908, -0.0057715568,
    -0.0022343695, 1.0045865019, -0.0023521324,
    -0.0050133515, -0.0252900718, 1.0303034233
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_DCI_P3 = mat3(
    1.464120167, -0.3933270416, -0.0707931253,
    -0.0664765138, 1.0752915253, -0.0088150114,
    -0.0025528617, -0.0470296027, 1.0495824644
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ADOBE_RGB_1998 = mat3(
    1.182219458, -0.1196751803, -0.06254384,
    -0.1302534036, 1.1408068945, -0.0105421535,
    -0.0283790646, -0.0767015586, 1.1050735076
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP0 = mat3(
    0.6954522414, 0.1406786965, 0.1638690622,
    0.0447945634, 0.8596711184, 0.0955343182,
    -0.0055258826, 0.0040252103, 1.0015006723
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP1 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_COLOR_MCSPACEFACE = mat3(
    1.0558172503, -0.0760536019, 0.0202363516,
    -0.0946074079, 1.0920168543, 0.0025905536,
    -0.0041475025, 0.0146375846, 0.9895099179
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ = mat3(
    0.6326705035, 0.1593748231, 0.1583847254,
    0.3109383344, 0.6385030652, 0.0505586004,
    -0.0019849432, -0.0136803265, 1.1044717614
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_SRGB = mat3(
    1.5732175875, -0.4582177853, -0.1151565195,
    -0.0298175917, 1.0427085222, -0.0127917816,
    -0.0302889016, -0.1358492065, 1.1662125458
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC709 = mat3(
    1.5732175875, -0.4582177853, -0.1151565195,
    -0.0298175917, 1.0427085222, -0.0127917816,
    -0.0302889016, -0.1358492065, 1.1662125458
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC2020 = mat3(
    0.975967555, 0.0499553701, -0.0259229251,
    0.0808021347, 0.9256507776, -0.0064529123,
    -0.004008449, -0.0373974036, 1.0414058526
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_DCI_P3 = mat3(
    1.3626775245, -0.2639569859, -0.0987205386,
    0.0253970497, 0.9866137758, -0.0120108255,
    -0.0034048709, -0.0575247555, 1.0609296265
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998 = mat3(
    1.1166338266, -0.030670652, -0.0859627369,
    -0.0299799561, 1.0427620595, -0.0127707659,
    -0.0303137568, -0.0873306478, 1.1176372892
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP0 = mat3(
    0.6748538843, 0.1737961892, 0.1513499266,
    0.1139293384, 0.7939320393, 0.0921386223,
    -0.0021565314, -0.0100317066, 1.012188238
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP1 = mat3(
    0.9530274476, 0.0666372627, -0.0196647103,
    0.0825594145, 0.9215416099, -0.0041010244,
    0.0027733055, -0.0133528374, 1.010579532
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
#define colors2_colorspaces_CIE_XYZ_luma(x) (x).y
#define colors2_colorspaces_0_luma(x) colors2_colorspaces_CIE_XYZ_luma(x)
#define colors2_colorspaces_SRGB_luma(x) dot(x, _colors2_colorspaces_mat_SRGB_to_CIE_XYZ[1])
#define colors2_colorspaces_1_luma(x) colors2_colorspaces_SRGB_luma(x)
#define colors2_colorspaces_REC709_luma(x) dot(x, _colors2_colorspaces_mat_REC709_to_CIE_XYZ[1])
#define colors2_colorspaces_2_luma(x) colors2_colorspaces_REC709_luma(x)
#define colors2_colorspaces_REC2020_luma(x) dot(x, _colors2_colorspaces_mat_REC2020_to_CIE_XYZ[1])
#define colors2_colorspaces_3_luma(x) colors2_colorspaces_REC2020_luma(x)
#define colors2_colorspaces_DCI_P3_luma(x) dot(x, _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ[1])
#define colors2_colorspaces_4_luma(x) colors2_colorspaces_DCI_P3_luma(x)
#define colors2_colorspaces_ADOBE_RGB_1998_luma(x) dot(x, _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ[1])
#define colors2_colorspaces_5_luma(x) colors2_colorspaces_ADOBE_RGB_1998_luma(x)
#define colors2_colorspaces_ACES_AP0_luma(x) dot(x, _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ[1])
#define colors2_colorspaces_6_luma(x) colors2_colorspaces_ACES_AP0_luma(x)
#define colors2_colorspaces_ACES_AP1_luma(x) dot(x, _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ[1])
#define colors2_colorspaces_7_luma(x) colors2_colorspaces_ACES_AP1_luma(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_luma(x) dot(x, _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ[1])
#define colors2_colorspaces_8_luma(x) colors2_colorspaces_COLOR_MCSPACEFACE_luma(x)
#define colors2_colorspaces_CIE_XYZ_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_CIE_XYZ)
#define colors2_colorspaces_0_to_0(x) colors2_colorspaces_CIE_XYZ_to_CIE_XYZ(x)
#define colors2_colorspaces_CIE_XYZ_to_SRGB(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_SRGB)
#define colors2_colorspaces_0_to_1(x) colors2_colorspaces_CIE_XYZ_to_SRGB(x)
#define colors2_colorspaces_CIE_XYZ_to_REC709(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_REC709)
#define colors2_colorspaces_0_to_2(x) colors2_colorspaces_CIE_XYZ_to_REC709(x)
#define colors2_colorspaces_CIE_XYZ_to_REC2020(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_REC2020)
#define colors2_colorspaces_0_to_3(x) colors2_colorspaces_CIE_XYZ_to_REC2020(x)
#define colors2_colorspaces_CIE_XYZ_to_DCI_P3(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_DCI_P3)
#define colors2_colorspaces_0_to_4(x) colors2_colorspaces_CIE_XYZ_to_DCI_P3(x)
#define colors2_colorspaces_CIE_XYZ_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ADOBE_RGB_1998)
#define colors2_colorspaces_0_to_5(x) colors2_colorspaces_CIE_XYZ_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_CIE_XYZ_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP0)
#define colors2_colorspaces_0_to_6(x) colors2_colorspaces_CIE_XYZ_to_ACES_AP0(x)
#define colors2_colorspaces_CIE_XYZ_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP1)
#define colors2_colorspaces_0_to_7(x) colors2_colorspaces_CIE_XYZ_to_ACES_AP1(x)
#define colors2_colorspaces_CIE_XYZ_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_0_to_8(x) colors2_colorspaces_CIE_XYZ_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_SRGB_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_SRGB_to_CIE_XYZ)
#define colors2_colorspaces_1_to_0(x) colors2_colorspaces_SRGB_to_CIE_XYZ(x)
#define colors2_colorspaces_SRGB_to_SRGB(x) (x * _colors2_colorspaces_mat_SRGB_to_SRGB)
#define colors2_colorspaces_1_to_1(x) colors2_colorspaces_SRGB_to_SRGB(x)
#define colors2_colorspaces_SRGB_to_REC709(x) (x * _colors2_colorspaces_mat_SRGB_to_REC709)
#define colors2_colorspaces_1_to_2(x) colors2_colorspaces_SRGB_to_REC709(x)
#define colors2_colorspaces_SRGB_to_REC2020(x) (x * _colors2_colorspaces_mat_SRGB_to_REC2020)
#define colors2_colorspaces_1_to_3(x) colors2_colorspaces_SRGB_to_REC2020(x)
#define colors2_colorspaces_SRGB_to_DCI_P3(x) (x * _colors2_colorspaces_mat_SRGB_to_DCI_P3)
#define colors2_colorspaces_1_to_4(x) colors2_colorspaces_SRGB_to_DCI_P3(x)
#define colors2_colorspaces_SRGB_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_SRGB_to_ADOBE_RGB_1998)
#define colors2_colorspaces_1_to_5(x) colors2_colorspaces_SRGB_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_SRGB_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_SRGB_to_ACES_AP0)
#define colors2_colorspaces_1_to_6(x) colors2_colorspaces_SRGB_to_ACES_AP0(x)
#define colors2_colorspaces_SRGB_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_SRGB_to_ACES_AP1)
#define colors2_colorspaces_1_to_7(x) colors2_colorspaces_SRGB_to_ACES_AP1(x)
#define colors2_colorspaces_SRGB_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_SRGB_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_1_to_8(x) colors2_colorspaces_SRGB_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_REC709_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_REC709_to_CIE_XYZ)
#define colors2_colorspaces_2_to_0(x) colors2_colorspaces_REC709_to_CIE_XYZ(x)
#define colors2_colorspaces_REC709_to_SRGB(x) (x * _colors2_colorspaces_mat_REC709_to_SRGB)
#define colors2_colorspaces_2_to_1(x) colors2_colorspaces_REC709_to_SRGB(x)
#define colors2_colorspaces_REC709_to_REC709(x) (x * _colors2_colorspaces_mat_REC709_to_REC709)
#define colors2_colorspaces_2_to_2(x) colors2_colorspaces_REC709_to_REC709(x)
#define colors2_colorspaces_REC709_to_REC2020(x) (x * _colors2_colorspaces_mat_REC709_to_REC2020)
#define colors2_colorspaces_2_to_3(x) colors2_colorspaces_REC709_to_REC2020(x)
#define colors2_colorspaces_REC709_to_DCI_P3(x) (x * _colors2_colorspaces_mat_REC709_to_DCI_P3)
#define colors2_colorspaces_2_to_4(x) colors2_colorspaces_REC709_to_DCI_P3(x)
#define colors2_colorspaces_REC709_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_REC709_to_ADOBE_RGB_1998)
#define colors2_colorspaces_2_to_5(x) colors2_colorspaces_REC709_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_REC709_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_REC709_to_ACES_AP0)
#define colors2_colorspaces_2_to_6(x) colors2_colorspaces_REC709_to_ACES_AP0(x)
#define colors2_colorspaces_REC709_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_REC709_to_ACES_AP1)
#define colors2_colorspaces_2_to_7(x) colors2_colorspaces_REC709_to_ACES_AP1(x)
#define colors2_colorspaces_REC709_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_REC709_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_2_to_8(x) colors2_colorspaces_REC709_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_REC2020_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_REC2020_to_CIE_XYZ)
#define colors2_colorspaces_3_to_0(x) colors2_colorspaces_REC2020_to_CIE_XYZ(x)
#define colors2_colorspaces_REC2020_to_SRGB(x) (x * _colors2_colorspaces_mat_REC2020_to_SRGB)
#define colors2_colorspaces_3_to_1(x) colors2_colorspaces_REC2020_to_SRGB(x)
#define colors2_colorspaces_REC2020_to_REC709(x) (x * _colors2_colorspaces_mat_REC2020_to_REC709)
#define colors2_colorspaces_3_to_2(x) colors2_colorspaces_REC2020_to_REC709(x)
#define colors2_colorspaces_REC2020_to_REC2020(x) (x * _colors2_colorspaces_mat_REC2020_to_REC2020)
#define colors2_colorspaces_3_to_3(x) colors2_colorspaces_REC2020_to_REC2020(x)
#define colors2_colorspaces_REC2020_to_DCI_P3(x) (x * _colors2_colorspaces_mat_REC2020_to_DCI_P3)
#define colors2_colorspaces_3_to_4(x) colors2_colorspaces_REC2020_to_DCI_P3(x)
#define colors2_colorspaces_REC2020_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_REC2020_to_ADOBE_RGB_1998)
#define colors2_colorspaces_3_to_5(x) colors2_colorspaces_REC2020_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_REC2020_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_REC2020_to_ACES_AP0)
#define colors2_colorspaces_3_to_6(x) colors2_colorspaces_REC2020_to_ACES_AP0(x)
#define colors2_colorspaces_REC2020_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_REC2020_to_ACES_AP1)
#define colors2_colorspaces_3_to_7(x) colors2_colorspaces_REC2020_to_ACES_AP1(x)
#define colors2_colorspaces_REC2020_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_REC2020_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_3_to_8(x) colors2_colorspaces_REC2020_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_DCI_P3_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ)
#define colors2_colorspaces_4_to_0(x) colors2_colorspaces_DCI_P3_to_CIE_XYZ(x)
#define colors2_colorspaces_DCI_P3_to_SRGB(x) (x * _colors2_colorspaces_mat_DCI_P3_to_SRGB)
#define colors2_colorspaces_4_to_1(x) colors2_colorspaces_DCI_P3_to_SRGB(x)
#define colors2_colorspaces_DCI_P3_to_REC709(x) (x * _colors2_colorspaces_mat_DCI_P3_to_REC709)
#define colors2_colorspaces_4_to_2(x) colors2_colorspaces_DCI_P3_to_REC709(x)
#define colors2_colorspaces_DCI_P3_to_REC2020(x) (x * _colors2_colorspaces_mat_DCI_P3_to_REC2020)
#define colors2_colorspaces_4_to_3(x) colors2_colorspaces_DCI_P3_to_REC2020(x)
#define colors2_colorspaces_DCI_P3_to_DCI_P3(x) (x * _colors2_colorspaces_mat_DCI_P3_to_DCI_P3)
#define colors2_colorspaces_4_to_4(x) colors2_colorspaces_DCI_P3_to_DCI_P3(x)
#define colors2_colorspaces_DCI_P3_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ADOBE_RGB_1998)
#define colors2_colorspaces_4_to_5(x) colors2_colorspaces_DCI_P3_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_DCI_P3_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ACES_AP0)
#define colors2_colorspaces_4_to_6(x) colors2_colorspaces_DCI_P3_to_ACES_AP0(x)
#define colors2_colorspaces_DCI_P3_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ACES_AP1)
#define colors2_colorspaces_4_to_7(x) colors2_colorspaces_DCI_P3_to_ACES_AP1(x)
#define colors2_colorspaces_DCI_P3_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_DCI_P3_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_4_to_8(x) colors2_colorspaces_DCI_P3_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ)
#define colors2_colorspaces_5_to_0(x) colors2_colorspaces_ADOBE_RGB_1998_to_CIE_XYZ(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_SRGB(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_SRGB)
#define colors2_colorspaces_5_to_1(x) colors2_colorspaces_ADOBE_RGB_1998_to_SRGB(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_REC709(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC709)
#define colors2_colorspaces_5_to_2(x) colors2_colorspaces_ADOBE_RGB_1998_to_REC709(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_REC2020(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC2020)
#define colors2_colorspaces_5_to_3(x) colors2_colorspaces_ADOBE_RGB_1998_to_REC2020(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_DCI_P3)
#define colors2_colorspaces_5_to_4(x) colors2_colorspaces_ADOBE_RGB_1998_to_DCI_P3(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ADOBE_RGB_1998)
#define colors2_colorspaces_5_to_5(x) colors2_colorspaces_ADOBE_RGB_1998_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP0)
#define colors2_colorspaces_5_to_6(x) colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP0(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP1)
#define colors2_colorspaces_5_to_7(x) colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP1(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_5_to_8(x) colors2_colorspaces_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ACES_AP0_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ)
#define colors2_colorspaces_6_to_0(x) colors2_colorspaces_ACES_AP0_to_CIE_XYZ(x)
#define colors2_colorspaces_ACES_AP0_to_SRGB(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_SRGB)
#define colors2_colorspaces_6_to_1(x) colors2_colorspaces_ACES_AP0_to_SRGB(x)
#define colors2_colorspaces_ACES_AP0_to_REC709(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_REC709)
#define colors2_colorspaces_6_to_2(x) colors2_colorspaces_ACES_AP0_to_REC709(x)
#define colors2_colorspaces_ACES_AP0_to_REC2020(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_REC2020)
#define colors2_colorspaces_6_to_3(x) colors2_colorspaces_ACES_AP0_to_REC2020(x)
#define colors2_colorspaces_ACES_AP0_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_DCI_P3)
#define colors2_colorspaces_6_to_4(x) colors2_colorspaces_ACES_AP0_to_DCI_P3(x)
#define colors2_colorspaces_ACES_AP0_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ADOBE_RGB_1998)
#define colors2_colorspaces_6_to_5(x) colors2_colorspaces_ACES_AP0_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ACES_AP0_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP0)
#define colors2_colorspaces_6_to_6(x) colors2_colorspaces_ACES_AP0_to_ACES_AP0(x)
#define colors2_colorspaces_ACES_AP0_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP1)
#define colors2_colorspaces_6_to_7(x) colors2_colorspaces_ACES_AP0_to_ACES_AP1(x)
#define colors2_colorspaces_ACES_AP0_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_6_to_8(x) colors2_colorspaces_ACES_AP0_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ACES_AP1_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ)
#define colors2_colorspaces_7_to_0(x) colors2_colorspaces_ACES_AP1_to_CIE_XYZ(x)
#define colors2_colorspaces_ACES_AP1_to_SRGB(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_SRGB)
#define colors2_colorspaces_7_to_1(x) colors2_colorspaces_ACES_AP1_to_SRGB(x)
#define colors2_colorspaces_ACES_AP1_to_REC709(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_REC709)
#define colors2_colorspaces_7_to_2(x) colors2_colorspaces_ACES_AP1_to_REC709(x)
#define colors2_colorspaces_ACES_AP1_to_REC2020(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_REC2020)
#define colors2_colorspaces_7_to_3(x) colors2_colorspaces_ACES_AP1_to_REC2020(x)
#define colors2_colorspaces_ACES_AP1_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_DCI_P3)
#define colors2_colorspaces_7_to_4(x) colors2_colorspaces_ACES_AP1_to_DCI_P3(x)
#define colors2_colorspaces_ACES_AP1_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ADOBE_RGB_1998)
#define colors2_colorspaces_7_to_5(x) colors2_colorspaces_ACES_AP1_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ACES_AP1_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP0)
#define colors2_colorspaces_7_to_6(x) colors2_colorspaces_ACES_AP1_to_ACES_AP0(x)
#define colors2_colorspaces_ACES_AP1_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP1)
#define colors2_colorspaces_7_to_7(x) colors2_colorspaces_ACES_AP1_to_ACES_AP1(x)
#define colors2_colorspaces_ACES_AP1_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_7_to_8(x) colors2_colorspaces_ACES_AP1_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ)
#define colors2_colorspaces_8_to_0(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_CIE_XYZ(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_SRGB(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_SRGB)
#define colors2_colorspaces_8_to_1(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_SRGB(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_REC709(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC709)
#define colors2_colorspaces_8_to_2(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_REC709(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_REC2020(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC2020)
#define colors2_colorspaces_8_to_3(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_REC2020(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_DCI_P3(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_DCI_P3)
#define colors2_colorspaces_8_to_4(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_DCI_P3(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998)
#define colors2_colorspaces_8_to_5(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP0)
#define colors2_colorspaces_8_to_6(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP0(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP1)
#define colors2_colorspaces_8_to_7(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP1(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_8_to_8(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE(x)
/*
    References:
        [WIK25a] Wikipedia. "Rec. 601". 2025.
            https:
        [WIK25b] Wikipedia. "Rec. 709". 2025.
            https:
        [WIK25c] Wikipedia. "sRGB". 2025.
            https:
        [ITU25] ITU, "Recommendation BT.2100", 2025.
            https:
            
    Note:
        EOTF: Electro-Optical Transfer Function (decoding gamma, non-linear to linear)
        OETF: Opto-Electronic Transfer Function (encoding gamma, linear to non-linear)
*/
/*
    References:
        [WHY23] Whyte, Killian. "Soft Clamp Function". 2023.
            https:

        You can find full license texts in /licenses
*/
#define PI 3.14159265358979323846
#define PI_2 (2.0 * PI)
#define PI_HALF (0.5 * PI)
#define PI_QUARTER (0.25 * PI)
#define RCP_PI (1.0 / PI)
#define RCP_PI_2 (1.0 / PI_2)
#define RCP_PI_HALF (1.0 / PI_HALF)
#define GOLDEN_RATIO 1.618033988749
#define GOLDEN_ANGLE 2.39996322972865332
#define SPHERE_SOLID_ANGLE (4.0 * PI)
#define FLT_MAX uintBitsToFloat(0x7F7FFFFF)
#define FLT_MIN uintBitsToFloat(0x00800000)
#define FLT_TRUE_MIN uintBitsToFloat(0x00000001)
#define FLT_POS_INF uintBitsToFloat(0x7F800000)
#define FLT_NEG_INF uintBitsToFloat(0xFF800000)
#define FP16_MAX 65504.0
#define INT32_MAX 2147483647
#define INT32_MIN -2147483648
#define rcp(x) (1.0 / (x))
#define saturate(x) clamp(x, 0.0, 1.0)
float linearStep(float edge0, float edge1, float x) { return saturate((x - edge0) / (edge1 - edge0)); }
vec2 linearStep(float edge0, float edge1, vec2 x) { return saturate((x - edge0) / (edge1 - edge0)); }
vec3 linearStep(float edge0, float edge1, vec3 x) { return saturate((x - edge0) / (edge1 - edge0)); }
vec4 linearStep(float edge0, float edge1, vec4 x) { return saturate((x - edge0) / (edge1 - edge0)); }
float pow2(float x) { return x * x; }
vec2 pow2(vec2 x) { return x * x; }
vec3 pow2(vec3 x) { return x * x; }
vec4 pow2(vec4 x) { return x * x; }
float pow3(float x) { return x * x * x; }
vec2 pow3(vec2 x) { return x * x * x; }
vec3 pow3(vec3 x) { return x * x * x; }
vec4 pow3(vec4 x) { return x * x * x; }
float pow4(float x) {
    float x2 = x * x;
    return x2 * x2;
}
vec2 pow4(vec2 x) {
    vec2 x2 = x * x;
    return x2 * x2;
}
vec3 pow4(vec3 x) {
    vec3 x2 = x * x;
    return x2 * x2;
}
vec4 pow4(vec4 x) {
    vec4 x2 = x * x;
    return x2 * x2;
}
float pow5(float x) {
    float x2 = x * x;
    return x2 * x2 * x;
}
vec2 pow5(vec2 x) {
    vec2 x2 = x * x;
    return x2 * x2 * x;
}
vec3 pow5(vec3 x) {
    vec3 x2 = x * x;
    return x2 * x2 * x;
}
vec4 pow5(vec4 x) {
    vec4 x2 = x * x;
    return x2 * x2 * x;
}
#ifndef NO_HALF
float16_t pow2(float16_t x) { return x * x; }
f16vec2 pow2(f16vec2 x) { return x * x; }
f16vec3 pow2(f16vec3 x) { return x * x; }
f16vec4 pow2(f16vec4 x) { return x * x; }
float16_t pow3(float16_t x) { return x * x * x; }
f16vec2 pow3(f16vec2 x) { return x * x * x; }
f16vec3 pow3(f16vec3 x) { return x * x * x; }
f16vec4 pow3(f16vec4 x) { return x * x * x; }
float16_t pow4(float16_t x) {
    float16_t x2 = x * x;
    return x2 * x2;
}
f16vec2 pow4(f16vec2 x) {
    f16vec2 x2 = x * x;
    return x2 * x2;
}
f16vec3 pow4(f16vec3 x) {
    f16vec3 x2 = x * x;
    return x2 * x2;
}
f16vec4 pow4(f16vec4 x) {
    f16vec4 x2 = x * x;
    return x2 * x2;
}
#endif
float safeRcp(float x) {
    return x <= 0.0 ? 0.0 : rcp(x);
}
vec2 safeRcp(vec2 x) {
    return mix(vec2(0.0), rcp(x), greaterThan(x, vec2(0.0)));
}
vec3 safeRcp(vec3 x) {
    return mix(vec3(0.0), rcp(x), greaterThan(x, vec3(0.0)));
}
float raySphereIntersectNearest(vec3 r0, vec3 rd, vec3 s0, float sR) {
    float a = dot(rd, rd);
    vec3 s0_r0 = r0 - s0;
    float b = 2.0 * dot(rd, s0_r0);
    float c = dot(s0_r0, s0_r0) - (sR * sR);
    float delta = b * b - 4.0*a*c;
    float result = -1.0;
    if (delta >= 0.0 && a != 0.0) {
        float sol0 = (-b - sqrt(delta)) / (2.0*a);
        float sol1 = (-b + sqrt(delta)) / (2.0*a);
        if (sol0 >= 0.0 || sol1 >= 0.0) {
            if (sol0 < 0.0) {
                result = sol1;
            } else if (sol1 < 0.0) {
                result = sol0;
            } else {
                result = min(sol0, sol1);
            }
            result = max(0.0, result);
        }
    }
    return result;
}
#define COLORS2_TF_IDENTITY 0
#define COLORS2_TF_REC601 1
#define COLORS2_TF_REC709 2
#define COLORS2_TF_SRGB   3
#define COLORS2_TF_EXP22  4
#define COLORS2_TF_EXP24  5
#define COLORS2_TF_PQ     6
#define COLORS2_TF_HLG    7
#define _colors2_oetf(a, x) colors2_oetf_## a ##(x)
#define colors2_oetf(a, x) _colors2_oetf(a, x)
#define _colors2_eotf(a, x) colors2_eotf_## a ##(x)
#define colors2_eotf(a, x) _colors2_eotf(a, x)
float colors2_oetf_identity(float c) {
    return c;
}
vec3 colors2_oetf_identity(vec3 c) {
    return c;
}
float colors2_eotf_identity(float c) {
    return c;
}
vec3 colors2_eotf_identity(vec3 c) {
    return c;
}
float colors2_oetf_Rec601(float c) {
    float lower = 4.5 * c;
    float higher = pow(c, 0.45) * 1.099 - 0.099;
    return mix(lower, higher, c >= 0.018);
}
vec3 colors2_oetf_Rec601(vec3 c) {
    vec3 lower = 4.5 * c;
    vec3 higher = pow(c, vec3(0.45)) * 1.099 - 0.099;
    return mix(lower, higher, greaterThanEqual(c, vec3(0.018)));
}
float colors2_eotf_Rec601(float c) {
    float lower = c / 4.5;
    float higher = pow((c + 0.099) / 1.099, 1.0 / 0.45);
    return mix(lower, higher, c >= 0.081);
}
vec3 colors2_eotf_Rec601(vec3 c) {
    vec3 lower = c / 4.5;
    vec3 higher = pow((c + 0.099) / 1.099, vec3(1.0 / 0.45));
    return mix(lower, higher, greaterThanEqual(c, vec3(0.081)));
}
float colors2_oetf_Rec709(float c) {
    return colors2_oetf_Rec601(c);
}
vec3 colors2_oetf_Rec709(vec3 c) {
    return colors2_oetf_Rec601(c);
}
float colors2_eotf_Rec709(float c) {
    return colors2_eotf_Rec601(c);
}
vec3 colors2_eotf_Rec709(vec3 c) {
    return colors2_eotf_Rec601(c);
}
float colors2_oetf_sRGB(float c) {
    float lower = 12.92 * c;
    float higher = pow(c, 1.0 / 2.4) * 1.055 - 0.055;
    return mix(lower, higher, c > 0.0031308);
}
vec3 colors2_oetf_sRGB(vec3 c) {
    vec3 lower = 12.92 * c;
    vec3 higher = pow(c, vec3(1.0 / 2.4)) * 1.055 - 0.055;
    return mix(lower, higher, greaterThan(c, vec3(0.0031308)));
}
float colors2_eotf_sRGB(float c) {
    float lower = c / 12.92;
    float higher = pow((c + 0.055) / 1.055, 2.4);
    return mix(lower, higher, c > 0.04045);
}
vec3 colors2_eotf_sRGB(vec3 c) {
    vec3 lower = c / 12.92;
    vec3 higher = pow((c + 0.055) / 1.055, vec3(2.4));
    return mix(lower, higher, greaterThan(c, vec3(0.04045)));
}
float colors2_oetf_Exp22(float c) {
    return pow(c, 1.0 / 2.2);
}
vec3 colors2_oetf_Exp22(vec3 c) {
    return pow(c, vec3(1.0 / 2.2));
}
float colors2_eotf_Exp22(float c) {
    return pow(c, 2.2);
}
vec3 colors2_eotf_Exp22(vec3 c) {
    return pow(c, vec3(2.2));
}
float colors2_oetf_Exp24(float c) {
    return pow(c, 1.0 / 2.4);
}
vec3 colors2_oetf_Exp24(vec3 c) {
    return pow(c, vec3(1.0 / 2.4));
}
float colors2_eotf_Exp24(float c) {
    return pow(c, 2.4);
}
vec3 colors2_eotf_Exp24(vec3 c) {
    return pow(c, vec3(2.4));
}
const float _PQ_M1 = 2610.0 / 16384.0;
const float _PQ_M2 = 2523.0 / 4096.0 * 128.0;
const float _PQ_C1 = 3424.0 / 4096.0;
const float _PQ_C2 = 2413.0 / 4096.0 * 32.0;
const float _PQ_C3 = 2392.0 / 4096.0 * 32.0;
const float _PQ_PEAK = 10000.0;
float colors2_oetf_PQ(float c) {
    float y = c / _PQ_PEAK;
    float yPow = pow(y, _PQ_M1);
    float numerator = _PQ_C1 + _PQ_C2 * yPow;
    float denominator = 1.0 + _PQ_C3 * yPow;
    return pow(numerator / denominator, _PQ_M2);
}
vec3 colors2_oetf_PQ(vec3 c) {
    vec3 y = c / _PQ_PEAK;
    vec3 yPow = pow(y, vec3(_PQ_M1));
    vec3 numerator = vec3(_PQ_C1) + vec3(_PQ_C2) * yPow;
    vec3 denominator = vec3(1.0) + vec3(_PQ_C3) * yPow;
    return pow(numerator / denominator, vec3(_PQ_M2));
}
float colors2_eotf_PQ(float c) {
    float ePow = pow(c, 1.0 / _PQ_M2);
    float numerator = max(ePow - _PQ_C1, 0.0);
    float denominator = _PQ_C2 - _PQ_C3 * ePow;
    float y = pow(numerator / denominator, 1.0 / _PQ_M1);
    return y * _PQ_PEAK;
}
vec3 colors2_eotf_PQ(vec3 c) {
    vec3 ePow = pow(c, vec3(1.0 / _PQ_M2));
    vec3 numerator = max(ePow - vec3(_PQ_C1), 0.0);
    vec3 denominator = _PQ_C2 - _PQ_C3 * ePow;
    vec3 y = pow(numerator / denominator, vec3(1.0 / _PQ_M1));
    return y * _PQ_PEAK;
}
const float _HLG_A = 0.17883277;
const float _HLG_B = 1.0 - 4.0 * _HLG_A;
const float _HLG_C = 0.5 - _HLG_A * log(4.0 * _HLG_A);
float colors2_oetf_HLG(float c) {
    float lower = sqrt(3.0 * c);
    float higher = _HLG_A * log(12.0 * c - _HLG_B) + _HLG_C;
    return mix(lower, higher, c > 1.0 / 12.0);
}
vec3 colors2_oetf_HLG(vec3 c) {
    vec3 lower = sqrt(3.0 * c);
    vec3 higher = _HLG_A * log(12.0 * c - _HLG_B) + _HLG_C;
    return mix(lower, higher, greaterThan(c, vec3(1.0 / 12.0)));
}
float colors2_eotf_HLG(float c) {
    float lower = c * c / 3.0;
    float higher = (exp((c - _HLG_C) / _HLG_A) + _HLG_B) / 12.0;
    return mix(lower, higher, c > 0.5);
}
vec3 colors2_eotf_HLG(vec3 c) {
    vec3 lower = c * c / 3.0;
    vec3 higher = (exp((c - vec3(_HLG_C)) / vec3(_HLG_A)) + vec3(_HLG_B)) / 12.0;
    return mix(lower, higher, greaterThan(c, vec3(0.5)));
}
float colors2_oetf_0(float c) { return colors2_eotf_identity(c); }
vec3 colors2_oetf_0(vec3 c) { return colors2_eotf_identity(c); }
float colors2_eotf_0(float c) { return colors2_oetf_identity(c); }
vec3 colors2_eotf_0(vec3 c) { return colors2_oetf_identity(c); }
float colors2_oetf_1(float c) { return colors2_oetf_Rec601(c); }
vec3 colors2_oetf_1(vec3 c) { return colors2_oetf_Rec601(c); }
float colors2_eotf_1(float c) { return colors2_eotf_Rec601(c); }
vec3 colors2_eotf_1(vec3 c) { return colors2_eotf_Rec601(c); }
float colors2_oetf_2(float c) { return colors2_oetf_Rec709(c); }
vec3 colors2_oetf_2(vec3 c) { return colors2_oetf_Rec709(c); }
float colors2_eotf_2(float c) { return colors2_eotf_Rec709(c); }
vec3 colors2_eotf_2(vec3 c) { return colors2_eotf_Rec709(c); }
float colors2_oetf_3(float c) { return colors2_oetf_sRGB(c); }
vec3 colors2_oetf_3(vec3 c) { return colors2_oetf_sRGB(c); }
float colors2_eotf_3(float c) { return colors2_eotf_sRGB(c); }
vec3 colors2_eotf_3(vec3 c) { return colors2_eotf_sRGB(c); }
float colors2_oetf_4(float c) { return colors2_oetf_Exp22(c); }
vec3 colors2_oetf_4(vec3 c) { return colors2_oetf_Exp22(c); }
float colors2_eotf_4(float c) { return colors2_eotf_Exp22(c); }
vec3 colors2_eotf_4(vec3 c) { return colors2_eotf_Exp22(c); }
float colors2_oetf_5(float c) { return colors2_oetf_Exp24(c); }
vec3 colors2_oetf_5(vec3 c) { return colors2_oetf_Exp24(c); }
float colors2_eotf_5(float c) { return colors2_eotf_Exp24(c); }
vec3 colors2_eotf_5(vec3 c) { return colors2_eotf_Exp24(c); }
float colors2_oetf_6(float c) { return colors2_oetf_PQ(c); }
vec3 colors2_oetf_6(vec3 c) { return colors2_oetf_PQ(c); }
float colors2_eotf_6(float c) { return colors2_eotf_PQ(c); }
vec3 colors2_eotf_6(vec3 c) { return colors2_eotf_PQ(c); }
float colors2_oetf_7(float c) { return colors2_oetf_HLG(c); }
vec3 colors2_oetf_7(vec3 c) { return colors2_oetf_HLG(c); }
float colors2_eotf_7(float c) { return colors2_eotf_HLG(c); }
vec3 colors2_eotf_7(vec3 c) { return colors2_eotf_HLG(c); }
#define COLORS2_MATERIAL_COLORSPACE SETTING_MATERIAL_COLOR_SPACE
#define COLORS2_MATERIAL_TF SETTING_MATERIAL_TRANSFER_FUNC
#define COLORS2_CONSTANTS_COLORSPACE COLORS2_COLORSPACES_ACES_AP0
#define COLORS2_CONSTANTS_TF COLORS2_TF_IDENTITY
#define COLORS2_WORKING_COLORSPACE SETTING_WORKING_COLOR_SPACE
#define COLORS2_DRT_WORKING_COLORSPACE SETTING_DRT_WORKING_COLOR_SPACE
#define COLORS2_OUTPUT_COLORSPACE COLORS2_COLORSPACES_SRGB
#define COLORS2_OUTPUT_TF COLORS2_TF_SRGB
#define colors2_material_toWorkSpace(x) colors2_colorspaces_convert(COLORS2_MATERIAL_COLORSPACE, COLORS2_WORKING_COLORSPACE, colors2_eotf(COLORS2_MATERIAL_TF, x))
#define colors2_constants_toWorkSpace(x) colors2_colorspaces_convert(COLORS2_CONSTANTS_COLORSPACE, COLORS2_WORKING_COLORSPACE, x)
#if SETTING_EPIPOLAR_SLICES == 256
#define EPIPOLAR_SLICE_D16 16
#define EPIPOLAR_SLICE_D128 2
#elif SETTING_EPIPOLAR_SLICES == 512
#define EPIPOLAR_SLICE_D16 32
#define EPIPOLAR_SLICE_D128 4
#elif SETTING_EPIPOLAR_SLICES == 1024
#define EPIPOLAR_SLICE_D16 64
#define EPIPOLAR_SLICE_D128 8
#elif SETTING_EPIPOLAR_SLICES == 2048
#define EPIPOLAR_SLICE_D16 128
#define EPIPOLAR_SLICE_D128 16
#endif
#if SETTING_SLICE_SAMPLES == 128
#define EPIPOLAR_DATA_Y_SIZE 385
#define SLICE_SAMPLE_D16 8
#elif SETTING_SLICE_SAMPLES == 256
#define EPIPOLAR_DATA_Y_SIZE 769
#define SLICE_SAMPLE_D16 16
#elif SETTING_SLICE_SAMPLES == 512
#define EPIPOLAR_DATA_Y_SIZE 1537
#define SLICE_SAMPLE_D16 32
#elif SETTING_SLICE_SAMPLES == 1024
#define EPIPOLAR_DATA_Y_SIZE 3073
#define SLICE_SAMPLE_D16 64
#endif
#define PLANET_RADIUS_OFFSET 0.01
struct AtmosphereParameters {
    float bottom;
    float top;
    float mieHeight;
    vec3 rayleighSctrCoeff;
    vec3 rayleighExtinction;
    vec3 mieSctrCoeff;
    vec3 mieExtinction;
    float miePhaseG;
    float miePhaseE;
    vec3 ozoneExtinction;
};
vec3 atmosphere_mieCoefficientsPreetham(float turbidity) {
    const vec3 a0 = vec3(-0.00767542206226, -0.00822772032997, -0.0121707541321);
    const vec3 a1 = vec3(0.00771550875198, 0.00827069152678, 0.0122343187466);
    return max(colors2_constants_toWorkSpace(a0 + a1 * turbidity), 0.0);
}
AtmosphereParameters getAtmosphereParameters() {
    const float ATMOSPHERE_BOTTOM = 6378.137;
    const float ATMOSPHERE_TOP = ATMOSPHERE_BOTTOM + 100.0;
    const float MIE_HEIGHT = 1.2;
    const vec3 RAYLEIGH_SCATTERING_BASE = colors2_constants_toWorkSpace(vec3(0.0120766817597, 0.0129498634753, 0.0275704559807));
    vec3 RAYLEIGH_SCATTERING = RAYLEIGH_SCATTERING_BASE * SETTING_ATM_RAY_SCT_MUL;
    vec3 MIE_SCATTERING_BASE = atmosphere_mieCoefficientsPreetham(global_turbidity);
    vec3 MIE_SCATTERING = MIE_SCATTERING_BASE * SETTING_ATM_MIE_SCT_MUL;
    vec3 MIE_ABOSORPTION = MIE_SCATTERING_BASE * SETTING_ATM_MIE_ABS_MUL;
    const float MIE_PHASE_G = 0.7034;
    const float MIE_PHASE_E = 2500.0;
    const vec3 OZONE_ABOSORPTION_BASE = colors2_constants_toWorkSpace(vec3(3.2964135827e-10, 2.9538443418e-10, 3.7326149468e-11) * 100000.0);
    const vec3 OZONE_ABOSORPTION = OZONE_ABOSORPTION_BASE * SETTING_ATM_OZO_ABS_MUL;
    AtmosphereParameters atmosphere;
    atmosphere.bottom = ATMOSPHERE_BOTTOM;
    atmosphere.top = ATMOSPHERE_TOP;
    atmosphere.mieHeight = MIE_HEIGHT;
    atmosphere.rayleighSctrCoeff = RAYLEIGH_SCATTERING;
    atmosphere.rayleighExtinction = RAYLEIGH_SCATTERING;
    atmosphere.miePhaseG = MIE_PHASE_G;
    atmosphere.miePhaseE = MIE_PHASE_E;
    atmosphere.mieSctrCoeff = MIE_SCATTERING;
    atmosphere.mieExtinction = MIE_SCATTERING + MIE_ABOSORPTION;
    atmosphere.ozoneExtinction = OZONE_ABOSORPTION;
    return atmosphere;
}
/*
    References:
        [EPI20] Epic Games, Inc. "Unreal Engine Sky Atmosphere Rendering Technique". 2020.
            MIT License. Copyright (c) 2020 Epic Games, Inc.
            https:
        [HIL20] Hillaire, Sébastien. "A Scalable and Production Ready Sky and Atmosphere Rendering Technique".
            EGSR 2020. 2020.
            https:

        You can find full license texts in /licenses
*/
/*
    References:
        [EPI20] Epic Games, Inc. "Unreal Engine Sky Atmosphere Rendering Technique". 2020.
            MIT License. Copyright (c) 2020 Epic Games, Inc.
            https:
        [HIL20] Hillaire, Sébastien. "A Scalable and Production Ready Sky and Atmosphere Rendering Technique".
            EGSR 2020. 2020.
            https:

        You can find full license texts in /licenses
*/
/*
    References:
        [BRU08] Bruneton, Eric. "Precomputed Atmospheric Scattering". EGSR 2008. 2008.
            https:
        [EPI20] Epic Games, Inc. "Unreal Engine Sky Atmosphere Rendering Technique". 2020.
            MIT License. Copyright (c) 2020 Epic Games, Inc.
            https:
        [HIL20] Hillaire, Sébastien. "A Scalable and Production Ready Sky and Atmosphere Rendering Technique".
            EGSR 2020. 2020.
            https:
        [INT17] Intel Corporation. "Outdoor Light Scattering Sample". 2017.
            Apache License 2.0. Copyright (c) 2017 Intel Corporation.
            https:
        [YUS13] Yusov, Egor. “Practical Implementation of Light Scattering Effects Using Epipolar Sampling and
            1D Min/Max Binary Trees”. GDC 2013. 2013.
            http:

        You can find full license texts in /licenses
*/
struct ScatteringResult {
    vec3 transmittance;
    vec3 inScattering;
};
ScatteringResult scatteringResult_init() {
    ScatteringResult result;
    result.transmittance = vec3(1.0);
    result.inScattering = vec3(0.0);
    return result;
}
vec3 scatteringResult_apply(ScatteringResult result, vec3 color) {
    return result.transmittance * color + result.inScattering;
}
ScatteringResult scatteringResult_blendLayer(ScatteringResult result, ScatteringResult layer, bool aboveLayer) {
    ScatteringResult newResult;
    if (aboveLayer) {
        newResult.inScattering = result.inScattering * layer.transmittance + layer.inScattering;
        newResult.transmittance = result.transmittance * layer.transmittance;
    } else {
        newResult.inScattering = layer.inScattering * result.transmittance + result.inScattering;
        newResult.transmittance = layer.transmittance * result.transmittance;
    }
    return newResult;
}
/*
    References:
        [GIL23] Gilcher, Pascal. "A Better R2 Sequence". 2023.
            https:
        [JIM17] Jimenez, Jorge. "Interleaved Gradient Noise". 2017.
            https:
        [ROB18] Roberts, Martine. "The Unreasonable Effectiveness of Quasirandom Sequences". 2018.
            https:
        [WOL22] Wolfe, Alan. "Interleaved Gradient Noise: A Different Kind of Low Discrepancy Sequence". 2022.
            MIT License. Copyright (c) 2019 Alan Wolfe.
            https:

        You can find full license texts in /licenses
*/
float rand_stbnVec1(ivec2 texelPos, uint frame) {
    return texelFetch(usam_stbnVec1, ivec3(texelPos, frame) & ivec3(127, 127, 63), 0).x;
}
vec2 rand_stbnVec2(ivec2 texelPos, uint frame) {
    return texelFetch(usam_stbnVec2, ivec3(texelPos, frame) & ivec3(127, 127, 63), 0).xy;
}
float rand_IGN(vec2 v) {
    return fract(52.9829189 * fract(0.06711056 * v.x + 0.00583715 * v.y));
}
float rand_IGN(vec2 v, uint frame) {
    frame = frame % 64u;
    v = v + 5.588238 * float(frame);
    return fract(52.9829189 * fract(0.06711056 * v.x + 0.00583715 * v.y));
}
/*
    References:
        [FOU99] G. Fournier, M. Jonasz. “Computer-based underwater imaging analysis”.irborne and In-water Underwater Imaging. 1999.
        [DRA03] Draine, B.T. "Scattering by Interstellar Dust Grains. I. Optical and Ultraviolet".
            The Astrophysical Journal. 2003.
            https:
        [JEN23] Jendersie, Johannes. d'Eon, Eugene. "An Approximate Mie Scattering Function for Fog and Cloud Rendering".
            SIGGRAPH 2023. 2023.
            https:

     Other Credits:
        Jessie - Bi-Lambertian plate and Klein-Nishina phase functions

        You can find full license texts in /licenses
*/
const float UNIFORM_PHASE = 1.0 / (4.0 * PI);
float phasefunc_HenyeyGreenstein(float cosTheta, float g) {
    float g2 = pow2(g);
    float numerator = 1.0 - g2;
    float denominator = pow(1.0 + g2 - 2.0 * g * cosTheta, 3.0 / 2.0);
    float term0 = UNIFORM_PHASE;
    float term1 = numerator / denominator;
    return term0 * term1;
}
vec3 phasefunc_HenyeyGreenstein(float cosTheta, vec3 g) {
    vec3 g2 = pow2(g);
    vec3 numerator = 1.0 - g2;
    vec3 denominator = pow(1.0 + g2 - 2.0 * g * cosTheta, vec3(3.0 / 2.0));
    float term0 = UNIFORM_PHASE;
    vec3 term1 = numerator / denominator;
    return term0 * term1;
}
float phasefunc_BiLambertianPlate(float cosTheta, float g) {
    float phase = 2.0 * (-PI * g * cosTheta + sqrt(saturate(1.0 - pow2(cosTheta))) + cosTheta * acos(-cosTheta));
    return phase / (3.0 * pow2(PI));
}
float phasefunc_KleinNishinaE(float cosTheta, float e) {
    return e / (2.0 * PI * (e * (1.0 - cosTheta) + 1.0) * log(2.0 * e + 1.0));
}
vec3 phasefunc_KleinNishinaE(float cosTheta, vec3 e) {
    return e / (2.0 * PI * (e * (1.0 - cosTheta) + 1.0) * log(2.0 * e + 1.0));
}
float atmosphere_height(AtmosphereParameters atmosphere, float worldPosY) {
    float worldHeight = max(worldPosY - 62.0, float(SETTING_ATM_ALT_SCALE) * 0.001);
    return worldHeight * (1.0 / float(SETTING_ATM_ALT_SCALE)) + atmosphere.bottom;
}
vec3 atmosphere_viewToAtm(AtmosphereParameters atmosphere, vec3 viewPos) {
    vec3 feetPlayer = (gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz;
    vec3 world = feetPlayer + cameraPosition;
    float height = atmosphere_height(atmosphere, world.y);
    return vec3(feetPlayer.x, 0.0, feetPlayer.z) * (1.0 / float(SETTING_ATM_D_SCALE)) + vec3(0.0, height, 0.0);
}
float atmosphere_heightNoClamping(AtmosphereParameters atmosphere, vec3 worldPos) {
    float worldHeight = worldPos.y - 62.0;
    return worldHeight * (1.0 / float(SETTING_ATM_ALT_SCALE)) + atmosphere.bottom;
}
vec3 atmosphere_viewToAtmNoClamping(AtmosphereParameters atmosphere, vec3 viewPos) {
    vec3 feetPlayer = (gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz;
    vec3 world = feetPlayer + cameraPosition;
    float height = atmosphere_heightNoClamping(atmosphere, world);
    return vec3(world.x, 0.0, world.z) * (1.0 / float(SETTING_ATM_D_SCALE)) + vec3(0.0, height, 0.0);
}
#define INVALID_EPIPOLAR_LINE vec4(-1000.0, -1000.0, -100.0, -100.0)
const vec3 GROUND_ALBEDO_BASE = vec3(ivec3(SETTING_ATM_GROUND_ALBEDO_R, SETTING_ATM_GROUND_ALBEDO_G, SETTING_ATM_GROUND_ALBEDO_B)) / 255.0;
/*
    References:
        [ERI07] Ericson, Christer. "Converting RGB to LogLuv in a fragment shader". 2007.
            https:
        [ITU11] ITU. "Recommendation ITU-R BT.601-7". 2011.
            https:
        [ITU15] ITU. "Recommendation ITU-R BT.709-6". 2015.
            https:
        [KAR13] Karis, Brian. "Tone mapping". Graphic Rants. 2013.
            https:
        [LAR98] Wikipedia. "The LogLuv Encoding for Full Gamut, High Dynamic Range Images". 1998.
            http:
        [LOT16] Lottes, Timothy. "Optimized Reversible Tonemapper for Resolve". 2016.
            https:
        [ROS18] Rosseaux, Benjamin. "Matrix-based RGB from/to YCoCg color space conversion". 2018.
            CC0 License (Public Domain).
            https:
        [WIK25a] Wikipedia. "Rec. 601". 2025.
            https:
        [WIK25b] Wikipedia. "Rec. 709". 2025.
            https:
        [WIK25c] Wikipedia. "sRGB". 2025.
            https:
        [WIK26a] Wikipedia. "CIELUV". 2026.
            https:

*/
const mat3 _SRGB_TO_YCOCG = mat3(
    0.25, 0.5, -0.25,
    0.5, 0.0, 0.5,
    0.25, -0.5, -0.25
);
const mat3 _YCOCG_TO_SRGB = mat3(
    1.0, 1.0, 1.0,
    1.0, 0.0, -1.0,
    -1.0, 1.0, -1.0
);
const mat3 _COLORS_LOGLUV32_M = mat3(
    0.2209, 0.3390, 0.4184,
    0.1138, 0.6780, 0.7319,
    0.0102, 0.1130, 0.2969
);
const mat3 _COLORS_LOGLUV32_INVERSE_M = mat3(
    6.0014, -2.7008, -1.7996,
    -1.3320, 3.1029, -5.7721,
    0.3008, -1.0882, 5.6268
);
vec3 colors_LogLuv32ToSRGB(in vec4 vLogLuv) {
    if (all(lessThanEqual(vLogLuv, vec4(0.0)))) {
        return vec3(0.0);
    }
    float Le = vLogLuv.z * 255 + vLogLuv.w;
    vec3 Xp_Y_XYZp;
    Xp_Y_XYZp.y = exp2((Le - 127) / 2);
    Xp_Y_XYZp.z = Xp_Y_XYZp.y / vLogLuv.y;
    Xp_Y_XYZp.x = vLogLuv.x * Xp_Y_XYZp.z;
    vec3 vRGB = _COLORS_LOGLUV32_INVERSE_M * Xp_Y_XYZp;
    return max(vRGB, 0);
}
const vec2 _COLORS_UV_MUL = vec2(6.4313725490, 14.4705882353);
const vec3 _COLORS_UV_DIV = vec3(1.0, 15.0, 3.0);
const float _COLORS_UV_INV_MUL = 0.6219512195;
const vec2 _COLORS_UV_Z_MUL = vec2(-3.0, -20.0);
uint colors_CIEXYZToFP16Luv(vec3 xyz) {
    float uvDiv = safeRcp(dot(xyz, _COLORS_UV_DIV));
    vec2 uv = xyz.xy * uvDiv * _COLORS_UV_MUL;
    uv = clamp(uv, vec2(0.0), vec2(255.0));
    uint result = packHalf2x16(vec2(0.0, xyz.y)) & 0xFFFF0000u;
    result = bitfieldInsert(result, packUnorm4x8(vec4(uv, 0.0, 0.0)), 0, 16);
    return result;
}
uint colors_workingColorToFP16Luv(vec3 color) {
    vec3 xyz = colors2_colorspaces_convert(COLORS2_WORKING_COLORSPACE, COLORS2_COLORSPACES_CIE_XYZ, color);
    return colors_CIEXYZToFP16Luv(xyz);
}
#define LUT_QUANTIZATION_MUL 512.0
#define TRANSMITTANCE_TEXTURE_WIDTH 256
#define TRANSMITTANCE_TEXTURE_HEIGHT 64
const vec2 TRANSMITTANCE_TEXTURE_SIZE = vec2(TRANSMITTANCE_TEXTURE_WIDTH, TRANSMITTANCE_TEXTURE_HEIGHT);
const vec2 TRANSMITTANCE_TEXEL_SIZE = 1.0 / TRANSMITTANCE_TEXTURE_SIZE;
#define MULTI_SCTR_LUT_SIZE 32
#define SKYVIEW_LUT_WIDTH SETTING_SKYVIEW_RES
#define SKYVIEW_LUT_HEIGHT SETTING_SKYVIEW_RES
#define SKYVIEW_LUT_LAYERS 4
#define SKYVIEW_LUT_DEPTH 8
#define SKYVIEW_LUT_SIZE ivec2(SKYVIEW_LUT_WIDTH, SKYVIEW_LUT_HEIGHT)
#define SKYVIEW_LUT_SIZE_F vec2(SKYVIEW_LUT_WIDTH, SKYVIEW_LUT_HEIGHT)
#if SETTING_SKYVIEW_RES == 128
#define SKYVIEW_RES_D16 8
#elif SETTING_SKYVIEW_RES == 256
#define SKYVIEW_RES_D16 16
#elif SETTING_SKYVIEW_RES == 512
#define SKYVIEW_RES_D16 32
#elif SETTING_SKYVIEW_RES == 1024
#define SKYVIEW_RES_D16 64
#endif
float _atmospherics_air_lut_fromUnitToSubUvs(float u, float resolution) { return (u + 0.5f / resolution) * (resolution / (resolution + 1.0f)); }
vec2 _atmospherics_air_lut_fromUnitToSubUvs(vec2 uv, vec2 resolution) { return (uv + 0.5 / resolution) * (resolution / (resolution + 1.0)); }
void _atmospherics_air_lut_lutTransmittanceParamsToUv(AtmosphereParameters atmosphere, float height, float cosZenith, out vec2 uv) {
    height = clamp(height, atmosphere.bottom + 0.0001, atmosphere.top - 0.0001);
    cosZenith = clamp(cosZenith, -1.0, 1.0);
    float H = sqrt(max(0.0, pow2(atmosphere.top) - pow2(atmosphere.bottom)));
    float rho = sqrt(max(0.0, pow2(height) - pow2(atmosphere.bottom)));
    float discriminant = pow2(height) * (cosZenith * cosZenith - 1.0) + pow2(atmosphere.top);
    float d = max(0.0, (-height * cosZenith + sqrt(discriminant)));
    float d_min = atmosphere.top - height;
    float d_max = rho + H;
    float x_mu = (d - d_min) / (d_max - d_min);
    float x_r = rho / H;
    uv = vec2(x_mu, x_r);
}
void _atmospherics_air_lut_skyViewLonLatToUv(float lat, float lon, out vec2 uv) {
    float v = 0.5 + 0.5 * sign(lat) * sqrt(abs(lat) / PI_HALF);
    uv = _atmospherics_air_lut_fromUnitToSubUvs(vec2(lon, v), vec2(SKYVIEW_LUT_WIDTH, SKYVIEW_LUT_HEIGHT));
}
void _atmospherics_air_lut_rayDirToSkyViewLonLat(vec3 rayDir, out float lat, out float lon) {
    lat = asin(clamp(rayDir.y, -1.0, 1.0));
    lon = atan(rayDir.x, -rayDir.z) * RCP_PI_2 + 0.5;
}
vec3 atmospherics_air_lut_sampleTransmittance(AtmosphereParameters atmosphere, float cosLightZenith, float sampleAltitude) {
    vec2 tLUTUV;
    _atmospherics_air_lut_lutTransmittanceParamsToUv(atmosphere, sampleAltitude, cosLightZenith, tLUTUV);
    uint cond = uint(any(lessThan(tLUTUV, vec2(0.0))));
    cond |= uint(any(greaterThan(tLUTUV, vec2(1.0))));
    if (bool(cond)) {
        return vec3(0.0);
    }
    return persistent_transmittanceLUT_sample(tLUTUV).rgb;
}
vec3 _atmospherics_air_lut_sampleSkyViewSlice(vec2 sliceUV, float sliceIndex) {
    vec3 sampleUV = vec3(sliceUV, (sliceIndex + 0.5) / SKYVIEW_LUT_DEPTH);
    return texture(usam_skyViewLUT, sampleUV).rgb;
}
#define _LUMINOUS_EFFICACY 683.002 
#define _blackBody_func1_v0 vec3(-37290175.3986, -40810912.9676, -47350510.215)
#define _blackBody_func1_v1 vec3(7055.3581938, 6758.95549072, 4118.25228444)
#define _blackBody_func1_v2 vec3(0.00484537801959, 0.00491276883428, 0.00506185958018)
#define _blackBody_func1_v3 vec3(-6.810769857e-7, -6.950213321e-7, -6.9539565265e-7)
#define _blackBody_func1_v4 vec3(5.6731538598e-11, 5.8002399769e-11, 5.6337103621e-11)
#define _blackBody_func1_v5 vec3(-2.5703246799e-15, -2.6264426188e-15, -2.4816463488e-15)
#define _blackBody_func1_v6 vec3(4.8909354617e-20, 4.9886030965e-20, 4.5966064285e-20)
#define _blackBody_func1(x) exp2( _blackBody_func1_v0 * rcp(pow2(x)) + _blackBody_func1_v1 * rcp(x) + _blackBody_func1_v2 * x + _blackBody_func1_v3 * pow2(x) + _blackBody_func1_v4 * pow3(x) + _blackBody_func1_v5 * pow4(x) + _blackBody_func1_v6 * pow5(x) )
#define _blackBody_func2_v0 vec3(-8005.4231085, -12668.5089522, 90350.9871613)
#define _blackBody_func2_v1 vec3(-13.8986440037, -13.5414550402, -53.296767586)
#define _blackBody_func2_v2 vec3(0.00322233921192, 0.00326336194057, 0.00762350264707)
#define _blackBody_func2_v3 vec3(-8.7157145477e-8, -8.8899800557e-8, -2.0127905863e-7)
#define _blackBody_func2_v4 vec3(1.2119660239e-12, 1.242334591e-12, 2.7501969304e-12)
#define _blackBody_func2_v5 vec3(-6.7641067868e-18, -6.9583618131e-18, -1.5149377815e-17)
#define _blackBody_func2(x) _blackBody_func2_v0 + _blackBody_func2_v1 * x + _blackBody_func2_v2 * pow2(x) + _blackBody_func2_v3 * pow3(x) + _blackBody_func2_v4 * pow4(x) + _blackBody_func2_v5 * pow5(x)
#define blackBody_evalRadiance_AP0(temperture) (_LUMINOUS_EFFICACY * mix( _blackBody_func1(temperture), _blackBody_func2(temperture), smoothstep(9000.0, 10000.0, float(temperture)) ))
/*
    References:
        [WRE18] Wrensch, Benjamin. "Reverse Z Cheatsheet". IOLITE Development Blog. 2023.
*/
mat3 mat3_rotateY(float angle) {
    float c = cos(angle);
    float s = sin(angle);
    return mat3(
        c, 0.0, s,
        0.0, 1.0, 0.0,
       -s, 0.0, c
    );
}
mat3 mat3_rotateZ(float angle) {
    float c = cos(angle);
    float s = sin(angle);
    return mat3(
        c, -s, 0.0,
        s, c, 0.0,
        0.0, 0.0, 1.0
    );
}
float coords_viewZToReversedZ(float viewZ, float near) {
    return near / -viewZ;
}
vec3 coords_toViewCoord(vec2 texCoord, float viewZ, mat4 projInv) {
    vec2 ndcXY = texCoord * 2.0 - 1.0;
    vec2 clipXY = ndcXY * -viewZ;
    vec2 viewXY = clipXY * vec2(projInv[0][0], projInv[1][1]);
    return vec3(viewXY, viewZ);
}
vec3 coords_octDecode11(vec2 f) {
    vec3 n = vec3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
    float t = saturate(-n.z);
    n.xy += mix(vec2(t), vec2(-t), greaterThanEqual(n.xy, vec2(0.0)));
    return normalize(n);
}
vec2 coords_equirectanglarForward(vec3 direction) {
    float phi = atan(direction.z, direction.x);
    float theta = asin(direction.y);
    vec2 uv = vec2((phi + PI) / (2.0 * PI), (theta + PI / 2.0) / PI);
    return uv;
}
vec2 coords_texelToUV(ivec2 texelPos, vec2 rcpTextureSize) {
    return saturate((vec2(texelPos) + 0.5) * rcpTextureSize);
}
const mat3 _COORDS_EQUATORIAL_TO_GALACTIC = mat3(
    -0.0548755604, 0.4941094279, -0.8676661490,
    -0.8734370902, -0.4448296300, -0.1980763734,
    -0.4838350155, 0.7469822445, 0.4559837762
);
const mat3 _COORDS_WORLD_TO_EQUATORIAL = mat3(
    0.0, 1.0, 0.0,
    1.0, 0.0, 0.0,
    0.0, 0.0, -1.0
);
vec3 coords_worldToEquatorial(vec3 world) {
    return _COORDS_WORLD_TO_EQUATORIAL * world;
}
vec3 coords_equatorial_observerRotation(vec3 equatorial, float solarLon, float hourAngle, float observerLat) {
    mat3 latRotation = mat3_rotateY(observerLat);
    mat3 solarRotation = mat3_rotateZ(PI - solarLon - hourAngle);
    return solarRotation * latRotation * equatorial;
}
vec2 coords_equatorial_rectangularToSpherical(vec3 equatorial) {
    float dec = asin(equatorial.z);
    float ra = atan(equatorial.y, equatorial.x);
    return vec2(ra, dec);
}
vec3 coords_dir_worldToView(vec3 dirWorld) {
    return normalize((mat3(gbufferModelView) * dirWorld));
}
#ifdef SETTING_REAL_SUN_TEMPERATURE
#define SUN_TEMPERATURE 5772.0
#else
#define SUN_TEMPERATURE SETTING_SUN_TEMPERATURE
#endif
#define SUN_RADIUS (695700.0 * SETTING_SUN_RADIUS)
#define SUN_DISTANCE (149597870.7 * SETTING_SUN_DISTANCE)
#define SUN_ANGULAR_RADIUS atan(SUN_RADIUS / SUN_DISTANCE)
#define SUN_SOLID_ANGLE (2.0 * PI * (1.0 - sqrt(pow2(SUN_DISTANCE) - pow2(SUN_RADIUS)) / SUN_DISTANCE))
#define SUN_LUMINANCE colors2_constants_toWorkSpace(blackBody_evalRadiance_AP0(SUN_TEMPERATURE))
#define SUN_ILLUMINANCE (SUN_LUMINANCE * SUN_SOLID_ANGLE)
#define MOON_RADIUS (1737.4 * SETTING_MOON_RADIUS)
#define MOON_DISTANCE (384399 * SETTING_MOON_DISTANCE)
#define MOON_ANGULAR_RADIUS atan(MOON_RADIUS / MOON_DISTANCE)
#define MOON_SOLID_ANGLE (2.0 * PI * (1.0 - sqrt(pow2(MOON_DISTANCE) - pow2(MOON_RADIUS)) / MOON_DISTANCE))
#define MOON_ALBEDO (SETTING_MOON_ALBEDO * vec3(SETTING_MOON_COLOR_R, SETTING_MOON_COLOR_G, SETTING_MOON_COLOR_B))
#define MOON_LUMINANCE (SUN_ILLUMINANCE * MOON_ALBEDO * RCP_PI)
#define MOON_ILLUMINANCE (MOON_LUMINANCE * MOON_SOLID_ANGLE)
float _celestial_circle(vec3 rayDir, vec3 objDir, float objAngularRadius) {
    float objCosTheta = cos(objAngularRadius);
    float cosTheta = saturate(dot(rayDir, objDir));
    return float(cosTheta >= objCosTheta);
}
const float _CELESTIAL_STARMAP_MILKYWAY_LUMINANCE = 0.1927554;
const float _CELESTIAL_REAL_MILKYWAY_LUMINANCE_MCD = 1.5;
const float _CELESTIAL_REAL_MILKYWAY_LUMINANCE_KCD = _CELESTIAL_REAL_MILKYWAY_LUMINANCE_MCD / 1000000.0;
const float _CELESTIAL_STARMAP_EXP = _CELESTIAL_REAL_MILKYWAY_LUMINANCE_KCD / _CELESTIAL_STARMAP_MILKYWAY_LUMINANCE;
const vec2 _CELESTIAL_STARMAP_SIZE = vec2(8192.0, 4096.0);
vec4 BicubicSampling5(sampler2D samplerV, vec2 inHistoryUV, vec2 resolution) {
    vec2 inHistoryST = inHistoryUV * resolution;
    const vec2 rcpResolution = rcp(resolution);
    const vec2 fractional = fract(inHistoryST - 0.5);
    const vec2 uv = (floor(inHistoryST - 0.5) + vec2(0.5f, 0.5f)) * rcpResolution;
    const vec2 t = vec2(fractional);
    const vec2 t2 = vec2(fractional * fractional);
    const vec2 t3 = vec2(fractional * fractional * fractional);
    const float s = float(0.5);
    const vec2 w0 = -s * t3 + float(2.f) * s * t2 - s * t;
    const vec2 w1 = (float(2.f) - s) * t3 + (s - float(3.f)) * t2 + float(1.f);
    const vec2 w2 = (s - float(2.f)) * t3 + (3 - float(2.f) * s) * t2 + s * t;
    const vec2 w3 = s * t3 - s * t2;
    const vec2 s0 = w1 + w2;
    const vec2 f0 = w2 / (w1 + w2);
    const vec2 m0 = uv + f0 * rcpResolution;
    const vec2 tc0 = uv - 1.f * rcpResolution;
    const vec2 tc3 = uv + 2.f * rcpResolution;
    const vec4 A = vec4(texture(samplerV, vec2(m0.x, tc0.y)));
    const vec4 B = vec4(texture(samplerV, vec2(tc0.x, m0.y)));
    const vec4 C = vec4(texture(samplerV, vec2(m0.x, m0.y)));
    const vec4 D = vec4(texture(samplerV, vec2(tc3.x, m0.y)));
    const vec4 E = vec4(texture(samplerV, vec2(m0.x, tc3.y)));
    const vec4 color = (float(0.5f) * (A + B) * w0.x + A * s0.x + float(0.5f) * (A + B) * w3.x) * w0.y + (B * w0.x + C * s0.x + D * w3.x) * s0.y + (float(0.5f) * (B + E) * w0.x + E * s0.x + float(0.5f) * (D + E) * w3.x) * w3.y;
    return color;
}
vec4 celestial_render(ivec2 texelPos, inout vec4 temp6Out) {
    vec2 screenPos = (vec2(texelPos) + 0.5 - uval_taaJitter) * uval_mainImageSizeRcp;
    vec3 viewCoord = coords_toViewCoord(screenPos, -far, global_camProjInverse);
    vec3 viewDir = normalize(viewCoord);
    vec3 viewDirWorld = mat3(gbufferModelViewInverse) * viewDir;
    AtmosphereParameters atmosphere = getAtmosphereParameters();
    vec3 origin = atmosphere_viewToAtm(atmosphere, vec3(0.0));
    origin.y = max(origin.y, atmosphere.bottom + 0.5);
    const vec3 earthCenter = vec3(0.0);
    float earthIntersect = raySphereIntersectNearest(origin, viewDirWorld, earthCenter, atmosphere.bottom);
    float earthOcclusionV = step(earthIntersect, 0.0);
    float sunV = earthOcclusionV *_celestial_circle(viewDir, uval_sunDirView, SUN_ANGULAR_RADIUS * 2.0);
    float moonV = earthOcclusionV *_celestial_circle(viewDir, uval_moonDirView, MOON_ANGULAR_RADIUS * 2.0);
    float moonDarkV = earthOcclusionV * _celestial_circle(viewDir, uval_moonDirView, MOON_ANGULAR_RADIUS * 4.0);
    vec4 result = vec4(0.0, 0.0, 0.0, 1.0);
    result += sunV * vec4(SUN_LUMINANCE, 1.0);
    result += moonV * vec4(MOON_LUMINANCE, 0.0);
    result += moonDarkV * vec4(0.0, 0.0, 0.0, -0.95);
    #if SETTING_STARMAP_INTENSITY
    float solarPos = 0.25;
    float hourAngle = float(worldTime - 18000) / 24000.0 * PI_2;
    vec3 starmapDir = viewDirWorld;
    starmapDir = coords_worldToEquatorial(starmapDir);
    starmapDir = coords_equatorial_observerRotation(starmapDir, solarPos * PI_2, hourAngle, radians(43.0));
    vec2 starmapSpherical = coords_equatorial_rectangularToSpherical(normalize(starmapDir));
    vec2 starmapUV = vec2(
        starmapSpherical.x * RCP_PI * -0.5 + 0.5,
        starmapSpherical.y * RCP_PI + 0.5
    );
    vec3 starmap = colors2_colorspaces_convert(COLORS2_COLORSPACES_SRGB, COLORS2_WORKING_COLORSPACE, colors_LogLuv32ToSRGB(BicubicSampling5(usam_starmap, starmapUV, _CELESTIAL_STARMAP_SIZE)));
    starmap = pow(starmap, vec3(SETTING_STARMAP_GAMMA));
    starmap *= exp2(colors2_colorspaces_luma(COLORS2_WORKING_COLORSPACE, starmap) * SETTING_STARMAP_BRIGHT_STAR_BOOST);
    result.rgb += earthOcclusionV * starmap * _CELESTIAL_STARMAP_EXP * SETTING_STARMAP_INTENSITY * 4.0;
    #ifdef SETTING_CONSTELLATIONS
    float constellationV = earthOcclusionV * texture(usam_constellations, starmapUV).r;
    temp6Out = vec4(vec3(1.0), constellationV * 0.5);
    #endif
    #endif
    result.a = max(result.a, 0.0);
    return result;
}
ScatteringResult _atmospherics_air_lut_sampleSkyView(
    float lat,
    float lon,
    float layerIndex
) {
    vec2 sliceUV;
    _atmospherics_air_lut_skyViewLonLatToUv(lat, lon, sliceUV);
    float sctrSlice = layerIndex * 2.0;
    float tSlice = layerIndex * 2.0 + 1.0;
    ScatteringResult result = scatteringResult_init();
    result.inScattering = _atmospherics_air_lut_sampleSkyViewSlice(sliceUV, sctrSlice);
    result.transmittance = _atmospherics_air_lut_sampleSkyViewSlice(sliceUV, tSlice);
    return result;
}
struct SkyViewLutParams {
    float latitude;
    float longitude;
    float viewHeight;
};
SkyViewLutParams atmospherics_air_lut_setupSkyViewLutParams(
    AtmosphereParameters atmosphere,
    vec3 rayDirWorld
) {
    vec3 rayStart = atmosphere_viewToAtm(atmosphere, vec3(0.0));
    float viewHeight = length(rayStart);
    float lat, lon;
    _atmospherics_air_lut_rayDirToSkyViewLonLat(rayDirWorld, lat, lon);
    return SkyViewLutParams(lat, lon, viewHeight);
}
ScatteringResult atmospherics_air_lut_sampleSkyViewLUT(AtmosphereParameters atmosphere, SkyViewLutParams params, float layerIndex) {
    return _atmospherics_air_lut_sampleSkyView(params.latitude, params.longitude, layerIndex);
}
/* Required extensions:
#extension GL_KHR_shader_subgroup_ballot : enable
*/
float hiz_closest_load(ivec2 texelPos, int level) {
    ivec4 mipTile = global_hizTiles[level];
    ivec2 readPos = mipTile.xy + clamp(texelPos, ivec2(0), mipTile.zw - 1);
    return texelFetch(usam_hiz, readPos, 0).r;
}
float hiz_groupGroundCheckSubgroupLoadViewZ(uvec2 groupOrigin, int level, ivec2 texelPos) {
    bool subgroupCheck = false;
    if (subgroupElect()) {
        subgroupCheck = hiz_closest_load(ivec2(groupOrigin), level) > coords_viewZToReversedZ(-65536.0, near);
    }
    float viewZ = -65536.0;
    if (subgroupBroadcastFirst(subgroupCheck)) {
        viewZ = texelFetch(colortex10, texelPos, 0).r;
    }
    return viewZ;
}
float unpackU4(uint v) { return clamp(float(v) / 15.0, 0.0, 1.0); }
float unpackU8(uint v) { return clamp(float(v) / 255.0, 0.0, 1.0); }
vec3 nzpacking_unpackNormalOct32(uint packedNormal) {
    return coords_octDecode11(unpackSnorm2x16(packedNormal));
}
void nzpacking_unpackNormalOct16(uint packedNormal, out vec3 normal1, out vec3 normal2) {
    vec4 xyzw = unpackSnorm4x8(packedNormal);
    normal1 = coords_octDecode11(xyzw.xy);
    normal2 = coords_octDecode11(xyzw.zw);
}
#ifdef SETTING_GI_USE_REFERENCE
#define USE_REFERENCE 1
#else
#define USE_REFERENCE 0
#endif
#define SKIP_FRAMES 0
#define MAX_FRAMES 0x7fffffff
#define RANDOM_FRAME (frameCounter - SKIP_FRAMES)
#define MC_SPP 16
const float HISTORY_LENGTH = float(SETTING_DENOISER_HISTORY_LENGTH);
const float TOTAL_HISTORY_LENGTH = 255.0;
/*
    Diffuse Color : 48 bits         (1)
    Specular Hit Distance: 16 bits  (1)
    Diffuse fast color: 48 bits     (2)
    Diffuse Hit Distance: 16 bits   (2)

    Specular Color: 48 bits         (3)
    Specular fast color: 48 bits    (4)

    History Length: 8 bits          (5)
    Real History Length: 8 bits     (5)
    Specular History Length: 8 bits (5)
    Glazing Angle Factor: 8 bits    (5)
*/
const float GI_MAX_HIT_DISTANCE = 256.0;
struct GIHistoryData {
    vec3 diffuseColor;
    vec3 diffuseFastColor;
    float diffuseHitDistance;
    vec3 specularColor;
    vec3 specularFastColor;
    float specularHitDistance;
    float historyLength;
    float realHistoryLength;
    float specularHistoryLength;
    float glazingAngleFactor;
};
const float _ROUGHNESS_K = 2.0;
const uint MATERIAL_ID_UNDEFINED = 65535u;
struct GBufferData {
    vec3 geomNormal;
    vec3 geomTangent;
    vec4 pbrSpecular;
    vec3 normal;
    vec2 lmCoord;
    uint materialID;
    vec3 albedo;
    bool isHand;
    bool forceBuiltInPBR;
    int bitangentSign;
};
GBufferData gbufferData_init() {
    GBufferData gData;
    gData.geomNormal = vec3(0.0);
    gData.geomTangent = vec3(0.0);
    gData.pbrSpecular = vec4(0.0);
    gData.normal = vec3(0.0);
    gData.lmCoord = vec2(0.0);
    gData.materialID = MATERIAL_ID_UNDEFINED;
    gData.albedo = vec3(0.0);
    gData.isHand = false;
    gData.forceBuiltInPBR = false;
    return gData;
}
void gbufferData1_unpack_world(uvec4 packedData, inout GBufferData gData) {
    nzpacking_unpackNormalOct16(packedData.r, gData.geomNormal, gData.geomTangent);
    gData.geomNormal = gData.geomNormal;
    gData.geomTangent = gData.geomTangent;
    gData.pbrSpecular = unpackUnorm4x8(packedData.g);
    gData.normal = nzpacking_unpackNormalOct32(packedData.b);
    gData.lmCoord = unpackUnorm4x8(packedData.a).xy;
    gData.materialID = (packedData.a >> 16) & 0xFFFFu;
}
void gbufferData1_unpack(uvec4 packedData, inout GBufferData gData) {
    gbufferData1_unpack_world(packedData, gData);
    gData.geomNormal = coords_dir_worldToView(gData.geomNormal);
    gData.geomTangent = coords_dir_worldToView(gData.geomTangent);
    gData.normal = coords_dir_worldToView(gData.normal);
}
void gbufferData2_unpack(uvec4 packedData, inout GBufferData gData) {
    gData.albedo = unpackUnorm4x8(packedData.r).rgb;
    gData.isHand = bool(bitfieldExtract(packedData.r, 24, 1));
    gData.bitangentSign = int(bitfieldExtract(packedData.r, 25, 1)) * 2 - 1;
    gData.forceBuiltInPBR = bool(bitfieldExtract(packedData.r, 26, 1));
}
struct HardcodedPBR {
    float sss;
    float emissive;
    float ior;
    float roughness;
    float dielectric;
    uint metalIndex;
    int emissiveMultiplier;
    bool isSmallFoliage;
    bool isKnown;
};
HardcodedPBR hardcodedpbr_decode(uint materialID) {
    bool isKnown = materialID != 0u &&
        materialID < textureSize(usam_pbrLUT0, 0).x &&
        materialID < textureSize(usam_pbrLUT1, 0).x;
    if (!isKnown) {
        materialID = 0u;
    }
    uvec4 rawData = uvec4(texelFetch(usam_pbrLUT0, int(materialID), 0));
    uint metalData = texelFetch(usam_pbrLUT1, int(materialID), 0).r;
    HardcodedPBR pbr;
    pbr.sss = unpackU4(bitfieldExtract(rawData.x, 0, 4));
    pbr.emissive = unpackU4(bitfieldExtract(rawData.x, 4, 4));
    pbr.ior = unpackU8(bitfieldExtract(rawData.x, 8, 8)) * 3.0;
    int temp = int(bitfieldExtract(rawData.x, 16, 4));
     pbr.emissiveMultiplier = temp | (0 - (temp & 0x8));
    pbr.isSmallFoliage = bitfieldExtract(rawData.x, 20, 1) == 1u;
    pbr.roughness = unpackU8(bitfieldExtract(rawData.x, 24, 8));
    pbr.metalIndex = bitfieldExtract(metalData, 0, 4);
    pbr.dielectric = unpackU4(bitfieldExtract(metalData, 4, 4));
    pbr.isKnown = isKnown;
    return pbr;
}
const uint MATERIAL_ID_WATER = 1u;
const float AIR_IOR = 1.00029;
const float WATER_IOR = 1.333;
vec3 ior_f0ToIor(vec3 f0) {
    vec3 f0Sqrt = sqrt(f0) * 0.99999;
    return AIR_IOR * ((1.0 + f0Sqrt) / (1.0 - f0Sqrt));
}
float ior_f0ToIor(float f0) {
    float f0Sqrt = sqrt(f0) * 0.99999;
    return AIR_IOR * ((1.0 + f0Sqrt) / (1.0 - f0Sqrt));
}
float ior_iorToF0(float ior) {
    return pow2((ior - AIR_IOR) / (ior + AIR_IOR));
}
struct Material {
    vec3 albedo;
    float roughness;
    vec3 f0RGB;
    vec3 f82TintRGB;
    float f0;
    float f82Tint;
    float dielectric;
    vec3 emissive;
    float porosity;
    float sss;
    float hardCodedIOR;
    mat3 tbn;
    mat3 tbnInv;
    mat3 geomTbn;
    mat3 geomTbnInv;
};
#ifdef MATERIAL_TRANSLUCENT
const float _MATERIAL_F0_EPSILON = exp2(-SETTING_MINIMUM_F0);
const float _MATERIAL_ROUGHNESS_MULTIPLIER = exp2(-SETTING_TRANSLUCENT_ROUGHNESS_REDUCTION);
const float _MATERIAL_MINIMUM_ROUGHNESS = exp2(-SETTING_TRANSLUCENT_MINIMUM_ROUGHNESS);
const float _MATERIAL_MAXIMUM_ROUGHNESS = exp2(-SETTING_TRANSLUCENT_MAXIMUM_ROUGHNESS);
const float _MATERIAL_WATER_ROUGHNESS = exp2(-SETTING_WATER_ROUGHNESS);
#else
const float _MATERIAL_F0_EPSILON = exp2(-SETTING_MINIMUM_F0);
const float _MATERIAL_ROUGHNESS_MULTIPLIER = 1.0;
const float _MATERIAL_MINIMUM_ROUGHNESS = exp2(-SETTING_SOLID_MINIMUM_ROUGHNESS);
const float _MATERIAL_MAXIMUM_ROUGHNESS = 1.0 - exp2(-SETTING_SOLID_MAXIMUM_ROUGHNESS);
#endif
Material material_decode(GBufferData gData) {
    Material material;
    HardcodedPBR hardcoded = hardcodedpbr_decode(gData.materialID);
    bool isWater = gData.materialID == MATERIAL_ID_WATER;
    material.albedo = colors2_material_toWorkSpace(gData.albedo);
    vec4 emissiveAlbedoCurve = vec4(vec3(SETTING_EMISSIVE_ALBEDO_COLOR_CURVE), SETTING_EMISSIVE_ALBEDO_LUM_CURVE);
    float albedoLuma = colors2_colorspaces_luma(COLORS2_MATERIAL_COLORSPACE, gData.albedo);
    #if defined(MC_TEXTURE_FORMAT_LAB_PBR) && SETTING_PBR_MATERIAL == 1 || SETTING_PBR_MATERIAL == 2
    bool useBuiltInPBR = gData.forceBuiltInPBR;
    #else
    bool useBuiltInPBR = true;
    #endif
    float roughness;
    float emissivePBR;
    if (useBuiltInPBR) {
        roughness = hardcoded.roughness;
        emissivePBR = hardcoded.emissive;
        emissiveAlbedoCurve.a += 1.0;
        albedoLuma = smoothstep(0.0, 1.0, albedoLuma);
        material.porosity = 0.0;
        material.sss = hardcoded.sss;
    } else {
        roughness = 1.0 - gData.pbrSpecular.r;
        emissivePBR = gData.pbrSpecular.a;
        emissivePBR = pow(emissivePBR, SETTING_EMISSIVE_PBR_VALUE_CURVE);
        const float _64o255 = 64.0 / 255.0;
        const float _65o255 = 65.0 / 255.0;
        float step64 = step(_65o255, gData.pbrSpecular.b);
        material.porosity = linearStep(0.0, _64o255, gData.pbrSpecular.b);
        material.porosity *= 1.0 - step64;
        material.sss = linearStep(_65o255, 1.0, gData.pbrSpecular.b);
        material.sss *= step64;
        material.sss = sqrt(material.sss);
    }
    roughness = pow2(roughness);
    roughness *= _MATERIAL_ROUGHNESS_MULTIPLIER;
    #ifdef MATERIAL_TRANSLUCENT
    roughness = isWater ? _MATERIAL_WATER_ROUGHNESS : roughness;
    #endif
    emissivePBR = pow(emissivePBR, SETTING_EMISSIVE_PBR_VALUE_CURVE);
    #ifndef MATERIAL_TRANSLUCENT
    roughness = max(roughness, 0.001);
    #endif
    material.roughness = roughness;
    bool resourceMetal = gData.pbrSpecular.g >= (229.5 / 255.0);
    #ifdef SETTING_BUILTIN_METALNESS
    bool useBuiltInMetalness = hardcoded.isKnown;
    #else
    bool useBuiltInMetalness = false;
    #endif
    material.dielectric = useBuiltInMetalness ? hardcoded.dielectric : float(!resourceMetal);
    float dielectricF0 = useBuiltInPBR || resourceMetal
        ? ior_iorToF0(hardcoded.ior)
        : gData.pbrSpecular.g;
    if (material.dielectric == 1.0) {
        material.f0RGB = vec3(dielectricF0);
        material.f82TintRGB = vec3(1.0);
        material.f82Tint = 1.0;
    } else {
        int metalIndex = useBuiltInMetalness && hardcoded.metalIndex != 0u
            ? int(hardcoded.metalIndex) + 229
            : resourceMetal ? int(gData.pbrSpecular.g * 255.0) : 255;
        vec4 f82Data = texelFetch(usam_f82, metalIndex, 0);
        vec3 metalF82Tint = mix(f82Data.aaa, vec3(1.0), f82Data.rgb);
        material.f0RGB = mix(material.albedo, vec3(dielectricF0), material.dielectric);
        material.f82TintRGB = mix(metalF82Tint, vec3(1.0), material.dielectric);
        material.f82Tint = colors2_colorspaces_luma(COLORS2_WORKING_COLORSPACE, material.f82TintRGB);
    }
    material.f0RGB = max(material.f0RGB, _MATERIAL_F0_EPSILON);
    material.f0 = colors2_colorspaces_luma(COLORS2_WORKING_COLORSPACE, material.f0RGB);
    vec4 emissiveAlbedo = pow(max(vec4(gData.albedo, albedoLuma), 1e-8), emissiveAlbedoCurve);
    emissiveAlbedo.rgb = colors2_material_toWorkSpace(emissiveAlbedo.rgb);
    float emissiveValue = emissivePBR * 0.5;
    emissiveValue *= exp2(SETTING_EMISSIVE_STRENGTH);
    material.emissive = emissiveValue * emissiveAlbedo.a * emissiveAlbedo.rgb;
    material.emissive = ldexp(material.emissive, ivec3(hardcoded.emissiveMultiplier));
    #ifdef MATERIAL_TRANSLUCENT
    material.hardCodedIOR = isWater ? 1.3333 : hardcoded.ior;
    #else
    material.hardCodedIOR = hardcoded.ior;
    #endif
    vec3 newTangent = normalize(gData.geomTangent - gData.normal * dot(gData.normal, gData.geomTangent));
    vec3 newBitangent = cross(newTangent, gData.normal) * float(gData.bitangentSign);
    material.tbn = mat3(newTangent, newBitangent, gData.normal);
    material.tbnInv = inverse(material.tbn);
    vec3 geomBitangent = cross(gData.geomTangent, gData.geomNormal) * float(gData.bitangentSign);
    material.geomTbn = mat3(gData.geomTangent, geomBitangent, gData.geomNormal);
    material.geomTbnInv = inverse(material.geomTbn);
    return material;
}
/*
    References:
        [ARN08] Arnott, W.P. "Fresnel equations". 2008.
            https:
        [KUT21] Kutz, Peter, et al. "Novel aspects of the Adobe Standard Material". 2021.
            https:
        [LAB21] shaderLABS. "LabPBR Material Standard". 2021.
            https:
        [LAG13] Lagarde, Sébastien. "Memo on Fresnel equations". 2013.
            https:
        [WIK23] Wikipedia. "Snell's law". 2023.
            https:
        [BEL25a] Belmu. "fresnel.glsl". Noble Shaders.
            GPL v3.0 License. Copyright (c) 2025 Belmu
            https:

        You can find full license texts in /licenses

    Other Credits:
        Jessie - providing beam ratio equation for transmission (https:
*/
vec3 fresnel_dielectricDielectric_transmittance(float cosThetaI, vec3 n1, vec3 n2) {
    float sinThetaI = sqrt(saturate(1.0 - pow2(cosThetaI)));
    vec3 sinThetaT = (n1 / n2) * sinThetaI;
    vec3 cosThetaT = sqrt(saturate(1.0 - pow2(sinThetaT)));
    vec3 result = vec3(1.0);
    if (any(lessThan(sinThetaT, vec3(1.0)))) {
        vec3 numerator = 2.0 * n1 * cosThetaI;
        vec3 Ts = abs(numerator / (n1 * cosThetaI + n2 * cosThetaT));
        vec3 Tp = abs(numerator / (n1 * cosThetaT + n2 * cosThetaI));
        vec3 beamRatio = abs((n2 * cosThetaT) / (n1 * cosThetaI));
        result = saturate(beamRatio * (Ts * Ts + Tp * Tp) * 0.5);
    }
    return result;
}
float fresnel_dielectricDielectric_transmittance(float cosThetaI, float n1, float n2) {
    float sinThetaI = sqrt(saturate(1.0 - pow2(cosThetaI)));
    float sinThetaT = (n1 / n2) * sinThetaI;
    float cosThetaT = sqrt(saturate(1.0 - pow2(sinThetaT)));
    float result = 1.0;
    if (sinThetaT < 1.0) {
        float numerator = 2.0 * n1 * cosThetaI;
        float Ts = abs(numerator / (n1 * cosThetaI + n2 * cosThetaT));
        float Tp = abs(numerator / (n1 * cosThetaT + n2 * cosThetaI));
        float beamRatio = abs((n2 * cosThetaT) / (n1 * cosThetaI));
        result = saturate(beamRatio * (Ts * Ts + Tp * Tp) * 0.5);
    }
    return result;
}
vec3 fresnel_schlick(float cosTheta, vec3 f0) {
    return f0 + (1.0 - f0) * pow5(1.0 - cosTheta);
}
float fresnel_schlick(float cosTheta, float f0) {
    return f0 + (1.0 - f0) * pow5(1.0 - cosTheta);
}
float fresnel_adobe(float cosTheta, float f0, float f82Tint) {
    float oneMinusF0 = 1.0 - f0;
    float b = fma(oneMinusF0, 0.462664878484, f0) * fma(f82Tint, -17.6513843536, 17.6513843536);
    return saturate(fma(fma(fma(cosTheta, cosTheta, -cosTheta), b, oneMinusF0), pow5(1.0 - cosTheta), f0));
}
vec3 fresnel_adobe(float cosTheta, vec3 f0, vec3 f82Tint) {
    vec3 oneMinusF0 = vec3(1.0) - f0;
    vec3 b = fma(oneMinusF0, vec3(0.462664878484), f0) * fma(f82Tint, vec3(-17.6513843536), vec3(17.6513843536));
    return saturate(fma(fma(vec3(fma(cosTheta, cosTheta, -cosTheta)), b, oneMinusF0), vec3(pow5(1.0 - cosTheta)), f0));
}
vec3 fresnel_evalMaterial(Material material, float cosTheta) {
    return fresnel_adobe(cosTheta, material.f0RGB, material.f82TintRGB);
}
/*
    References:
        [GIL23] Gilcher, Pascal. "Better GGX VNDF Sampler". Shadertoy. 2023.
            https:
            MIT License. Copyright (c) 2023 Pascal Gilcher.
        [HAM17] Hammon, Earl, Jr. "PBR Diffuse Lighting for GGX+Smith Microsurfaces". GDC 2017. 2017.
            https:
        [HOF10] Hoffman, Naty. "Background: Physics and Math of Shading".
            SIGGRAPH 2012 Course: Practical Physically Based Shading in Film and Game Production. 2010.
            https:
        [KAR10] Karis, Brian. "Specular BRDF Reference". Graphic Rants. 2013.
            https:

        You can find full license texts in /licenses)
*/
vec3 bsdf_diffuseHammon(Material material, float NDotL, float NDotV, float NDotH, float LDotV) {
    vec3 result = vec3(0.0);
    if (NDotL > 0.0) {
        float facing = saturate(0.5 * LDotV + 0.5);
        float fresnelNL = fresnel_dielectricDielectric_transmittance(max(NDotL, 1e-2), AIR_IOR, ior_f0ToIor(material.f0));
        float fresnelNV = fresnel_dielectricDielectric_transmittance(max(NDotV, 1e-2), AIR_IOR, ior_f0ToIor(material.f0));
        float energyConservationFactor = 1.0 - (4.0 * sqrt(material.f0) + 5.0 * material.f0 * material.f0) * rcp(9.0);
        float singleSmooth = (fresnelNL * fresnelNV) / energyConservationFactor;
        float singleRough = facing * (0.9 - 0.4 * facing) * (0.5 + NDotH) / NDotH;
        float single = mix(singleSmooth, singleRough, material.roughness) * RCP_PI;
        float multi = 0.1159 * material.roughness;
        result = NDotL * (single + material.albedo * multi);
    }
    return result;
}
float _bsdf_g_Smith_Schlick_denom(float cosTheta, float k) {
    return cosTheta * (1.0 - k) + k;
}
float bsdf_ggx(Material material, float NDotL, float NDotV, float NDotH) {
    float result = 0.0;
    if (NDotL > 0.0) {
        float NDotH2 = pow2(NDotH);
        float a2 = pow2(material.roughness);
        float d = a2 / max(PI * pow2(NDotH2 * (a2 - 1.0) + 1.0), 1e-16);
        float k = material.roughness * 0.5;
        float v = rcp(_bsdf_g_Smith_Schlick_denom(NDotL, k) * _bsdf_g_Smith_Schlick_denom(saturate(NDotV), k));
        result = NDotL * d * v * 0.25;
    }
    return result;
}
#define RTWSM_IMAP_SIZE 256
#define IMAP_SIZE_D2 128
#define IMAP_SIZE_D16 16
#define IMAP_SIZE_D32 8
#define IMAP_SIZE_D128 2
#define IMAP1D_X_V (0.5 / 2.0)
#define IMAP1D_Y_V (1.5 / 2.0)
#define WARP_X_V (0.5 / 2.0)
#define WARP_Y_V (1.5 / 2.0)
#define TEXELSIZE_X_V (0.5 / 2.0)
#define TEXELSIZE_Y_V (1.5 / 2.0)
GBufferData lighting_gData = gbufferData_init();
struct LightingResult {
    vec3 diffuse;
    vec3 diffuseLambertian;
    vec3 specular;
    vec3 sss;
};
LightingResult lightingResult_add(LightingResult a, LightingResult b) {
    LightingResult result;
    result.diffuse = a.diffuse + b.diffuse;
    result.diffuseLambertian = a.diffuseLambertian + b.diffuseLambertian;
    result.specular = a.specular + b.specular;
    result.sss = a.sss + b.sss;
    return result;
}
LightingResult directLighting(GBufferData gData, Material material, vec3 irradiance, vec4 shadow, vec3 V, vec3 L, vec3 N) {
    vec3 H = normalize(L + V);
    float LDotV = clamp(dot(L, V), -1.0, 1.0);
    float LDotH = clamp(dot(L, H), -1.0, 1.0);
    float NDotL = clamp(dot(N, L), -1.0, 1.0);
    float NDotV = clamp(dot(N, V), -1.0, 1.0);
    float NDotH = clamp(dot(N, H), -1.0, 1.0);
    vec3 shadowedIrradiance = irradiance * shadow.rgb;
    float surfaceDepth = shadow.w;
    vec3 albedoSRGB = saturate(colors2_colorspaces_convert(COLORS2_WORKING_COLORSPACE, COLORS2_COLORSPACES_SRGB, material.albedo));
    if (gData.isHand) {
        surfaceDepth = max(surfaceDepth, 0.2);
        if (heldItemId == 0) {
            material.sss = 0.1;
            albedoSRGB *= vec3(0.9, 0.7, 0.6);
            albedoSRGB = pow2(albedoSRGB);
        }
    }
    LightingResult result;
    result.sss = vec3(0.0);
    if (material.sss > 0.0) {
        const float ABSORPTION_MULTIPLIER = 12.0;
        const float SCATTERING_MULTIPLIER = 24.0;
        const vec3 ABSO_POW = vec3(1.3, 1.5, 2.0);
        const float SCTR_POW = 0.6;
        float luma = colors2_colorspaces_luma(COLORS2_COLORSPACES_SRGB, albedoSRGB);
        albedoSRGB *= min(0.5 / luma, 1.0);
        vec3 tCoeff = pow(albedoSRGB, vec3(ABSO_POW));
        tCoeff = colors2_colorspaces_convert(COLORS2_COLORSPACES_SRGB, COLORS2_WORKING_COLORSPACE, tCoeff);
        tCoeff = clamp(tCoeff, 0.001, 0.999);
        vec3 aCoeff = max(-log(tCoeff), 0.0);
        vec3 sCoeff = pow(albedoSRGB, vec3(SCTR_POW));
        sCoeff = saturate(colors2_colorspaces_convert(COLORS2_COLORSPACES_SRGB, COLORS2_WORKING_COLORSPACE, sCoeff));
        sCoeff = clamp(sCoeff, 0.001, 0.999);
        aCoeff = aCoeff * ABSORPTION_MULTIPLIER / sqrt(material.sss);
        sCoeff *= SCATTERING_MULTIPLIER * material.sss;
        vec3 sampleScattering = sCoeff;
        vec3 sampleExtinction = (aCoeff + sCoeff);
        vec3 sampleOpticalDepth = sampleExtinction * surfaceDepth;
        vec3 sampleTransmittance = exp(-sampleOpticalDepth);
        vec3 sampleIrradiance = shadowedIrradiance;
        float msRadius = sqrt(surfaceDepth) + 1.0;
        vec3 fMS = (sampleScattering / sampleExtinction) * (1.0 - exp(-msRadius * sampleExtinction));
        vec3 sampleMSIrradiance = shadowedIrradiance;
        sampleMSIrradiance *= UNIFORM_PHASE;
        sampleMSIrradiance *= fMS / (1.0 - fMS);
        sampleIrradiance += sampleMSIrradiance;
        vec3 sampleInSctr = sampleIrradiance * sampleScattering;
        vec3 sampleInSctrInt = (sampleInSctr - sampleInSctr * sampleTransmittance) / sampleExtinction;
        float sunMiePhase = phasefunc_KleinNishinaE(-LDotV, 2e4);
        float sssFresnel = fresnel_schlick(max(abs(LDotH), 0.005), 0.04);
        float phase = phasefunc_BiLambertianPlate(-LDotV, 0.3);
        result.sss = phase * sampleInSctrInt;
        vec3 sheenTransmittance = max(exp(-sampleOpticalDepth), exp(-sampleOpticalDepth * 0.25) * 0.7);
        result.sss += sunMiePhase * sheenTransmittance * shadowedIrradiance * (1.0 - sssFresnel);
        shadowedIrradiance *= float(dot(material.geomTbn[2], L) > 0.0);
    }
    vec3 fresnel = fresnel_evalMaterial(material, saturate(LDotH));
    vec3 diffuseBaseVec3 = material.dielectric * (shadowedIrradiance * (1.0 - fresnel) * material.albedo);
    result.diffuse = diffuseBaseVec3 * bsdf_diffuseHammon(material, NDotL, NDotV, LDotH, LDotV);
    result.diffuseLambertian = diffuseBaseVec3 * (RCP_PI * saturate(NDotL));
    result.specular = shadowedIrradiance * fresnel * bsdf_ggx(material, NDotL, NDotV, NDotH);
    result.specular = min(result.specular, SETTING_MAXIMUM_SPECULAR_LUMINANCE);
    return result;
}
uvec2 morton_8bDecode(uint code) {
    uvec2 result = uvec2(code, code >> 1) & 0x55u;
    result = (result | (result >> 1)) & 0x33u;
    result = (result | (result >> 2)) & 0x0fu;
    return result;
}
layout(std430, binding = 7) readonly buffer ThreadGroupTilingData {
    uvec2 ssbo_threadGroupTiling[];
};
layout(local_size_x = 16, local_size_y = 16) in;
const vec2 workGroupsRender = vec2(1.0, 1.0);
layout(rgba16f) uniform writeonly image2D colorimg0;
layout(rgba8) uniform restrict image2D colorimg6;
layout(rgba16f) uniform restrict image2D uimg_rgba16f;
layout(rgba16f) uniform restrict image2D colorimg3;
layout(rgba8) uniform restrict writeonly image2D uimg_rgba8;
layout(rg32ui) uniform restrict writeonly uimage2D uimg_rg32ui;
layout(rgba32ui) uniform restrict writeonly uimage2D uimg_rgba32ui;
/*
    References:
        [HIL16] Hillaire, Sébastien. "Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite".
            SIGGRAPH 2016. 2016.
            https:
        [SCH15] Schneider, Andrew. "The Real-Time Volumetric Cloudscapes Of Horizon: Zero Dawn"
            SIGGRAPH 2015. 2015.
            https:
        [SCH16] Schneider, Andrew. "Real-Time Volumetric Cloudscapes"
            GPU Pro 7. 2016.
        [SCH17] Schneider, Andrew. "Nubis: Authoring Real-Time Volumetric Cloudscapes with the Decima Engine"
            SIGGRAPH 17. 2017.
            https:
        [QIU25] QiuTang98. "Flower Engine"
            MIT License. Copyright (c) 2025 QiuTang98.
            https:
        [QIU23] QiuTang98. "实时体积云渲染的光照细节". 2023
            https:
        [WDT22] Wo De Tian (oh my god). "一个简单的体积云多重散射近似方法" (A Simple Multiple Scattering Approximation for Volumetric Clouds). 2022.
            https:

        You can find full license texts in /licenses
*/
/*
    References:
        [GEI05] GEISA. "The Database and Associated Software OPAC". 2005. https:
*/
const vec3 CLOUDS_ST_SCATTERING = colors2_constants_toWorkSpace(vec3(0.23777277562949245, 0.23987629843161026, 0.2551375513806795));
const vec3 CLOUDS_ST_EXTINCTION = colors2_constants_toWorkSpace(vec3(0.23777304241545993, 0.2398763953030018, 0.25513757827543126));
const vec3 CLOUDS_ST_ASYM = colors2_constants_toWorkSpace(vec3(0.8629828250733059, 0.8727334366957631, 0.9334765415706695));
const vec3 CLOUDS_ST_E = colors2_constants_toWorkSpace(vec3(1091938.4155551041, 3341273.320789842, 5.699703416476822e12));
const float CLOUDS_ST_R_EFF = 7.33;
const vec3 CLOUDS_CU_SCATTERING = colors2_constants_toWorkSpace(vec3(0.18067349140471628, 0.18215551958414714, 0.19358579492341665));
const vec3 CLOUDS_CU_EXTINCTION = colors2_constants_toWorkSpace(vec3(0.18067367051236774, 0.18215559145291857, 0.19358580629452912));
const vec3 CLOUDS_CU_ASYM = colors2_constants_toWorkSpace(vec3(0.8615159687912013, 0.8732937077048064, 0.9375708300315341));
const vec3 CLOUDS_CU_E = colors2_constants_toWorkSpace(vec3(935502.5670106385, 3581719.839469918, 4.094123822571251E13));
const float CLOUDS_CU_R_EFF = 5.77;
const vec3 CLOUDS_CI_SCATTERING = colors2_constants_toWorkSpace(vec3(6.17017026101243, 6.239057230606717, 6.667813761472693));
const vec3 CLOUDS_CI_EXTINCTION = colors2_constants_toWorkSpace(vec3(6.170170260942012, 6.239057230606713, 6.667813761472693));
const vec3 CLOUDS_CI_ASYM = colors2_constants_toWorkSpace(vec3(0.7816707299139416, 0.7895764808723628, 0.8408420552232578));
const vec3 CLOUDS_CI_E = colors2_constants_toWorkSpace(vec3(4714.18358593152, 6665.142983584232, 143262.2082694281));
const float CLOUDS_CI_R_EFF = 91.7;
struct CloudParticpatingMedium {
    vec3 scattering;
    vec3 extinction;
    vec3 phase;
};
vec3 _clouds_samplePhaseLUT(float cosTheta, float type) {
    const float a0 = 0.672617934627;
    const float a1 = -0.0713555761181;
    const float a2 = 0.0299320735609;
    const float b = 0.264767018876;
    float x1 = acos(cosTheta);
    float x2 = x1 * x1;
    float u = saturate((a0 + a1 * x1 + a2 * x2) * pow(x1, b));
    float v = (type + 0.5) / 3.0;
    vec4 rgbm = texture(usam_cloudPhases, vec2(u, v));
    return colors2_constants_toWorkSpace(rgbm.rgb * rgbm.a);
}
vec3 _clouds_cirrusLUTPhase(float cosTheta) {
    return _clouds_samplePhaseLUT(cosTheta, 0.0);
}
vec3 clouds_phase_ci(float cosTheta, float mixRatio) {
    return mix(phasefunc_HenyeyGreenstein(cosTheta, CLOUDS_CI_ASYM), _clouds_cirrusLUTPhase(cosTheta), mixRatio);
}
CloudParticpatingMedium clouds_ci_medium(float cosTheta) {
    CloudParticpatingMedium medium;
    medium.scattering = CLOUDS_CI_SCATTERING;
    medium.extinction = CLOUDS_CI_EXTINCTION;
    medium.phase = clouds_phase_ci(cosTheta, SETTING_CLOUDS_CI_PHASE_RATIO);
    return medium;
}
struct CloudMainRayParams {
    vec3 rayStart;
    vec3 rayDir;
    vec3 rayEnd;
    float rayStartHeight;
    float rayEndHeight;
};
struct CloudRenderParams {
    vec3 lightDir;
    vec3 lightIrradiance;
    float cosLightTheta;
};
CloudRenderParams cloudRenderParams_init(CloudMainRayParams rayParam, vec3 lightDir, vec3 lightIrradiance) {
    CloudRenderParams params;
    params.lightDir = normalize(lightDir);
    params.lightIrradiance = lightIrradiance;
    params.cosLightTheta = dot(rayParam.rayDir, lightDir);
    return params;
}
struct CloudRaymarchLayerParam {
    CloudParticpatingMedium medium;
    vec3 ambientIrradiance;
    vec2 layerRange;
    vec3 rayStart;
    vec3 rayEnd;
    vec4 rayStep;
};
CloudRaymarchLayerParam clouds_raymarchLayerParam_init(
    CloudMainRayParams mainRayParam,
    CloudParticpatingMedium medium,
    vec3 ambientIrradiance,
    vec2 layerRange,
    float origin2RayOffset,
    float rayLength,
    uint stepCount
) {
    CloudRaymarchLayerParam param;
    param.medium = medium;
    param.ambientIrradiance = ambientIrradiance;
    param.layerRange = layerRange;
    param.rayStart = mainRayParam.rayStart + mainRayParam.rayDir * origin2RayOffset;
    param.rayEnd = param.rayStart + mainRayParam.rayDir * rayLength;
    param.rayStep = vec4(param.rayEnd - param.rayStart, rayLength) * rcp(float(stepCount + 1u));
    return param;
}
struct CloudRaymarchAccumState {
    vec3 totalInSctr;
    vec3 totalTransmittance;
};
CloudRaymarchAccumState clouds_raymarchAccumState_init() {
    CloudRaymarchAccumState state;
    state.totalInSctr = vec3(0.0);
    state.totalTransmittance = vec3(1.0);
    return state;
}
struct CloudRaymarchStepState {
    vec4 origin;
    vec4 position;
    float height;
    vec4 rayStep;
    vec3 upVector;
};
CloudRaymarchStepState clouds_raymarchStepState_init(CloudRaymarchLayerParam layerParam) {
    CloudRaymarchStepState state;
    state.origin = vec4(layerParam.rayStart, 0.0);
    state.position = state.origin;
    state.height = length(state.position.xyz);
    state.upVector = state.position.xyz / state.height;
    state.rayStep = layerParam.rayStep;
    return state;
}
void clouds_computeLighting(
    AtmosphereParameters atmosphere,
    CloudRenderParams renderParams,
    CloudRaymarchLayerParam layerParam,
    CloudRaymarchStepState stepState,
    float sampleDensity,
    float sampleDensityLod,
    vec3 lightOpticalDepth,
    inout CloudRaymarchAccumState accumState
) {
    float cosLightZenith = dot(stepState.upVector, renderParams.lightDir);
    vec3 tLightToSample = atmospherics_air_lut_sampleTransmittance(atmosphere, cosLightZenith, stepState.height);
    vec3 sampleScattering = layerParam.medium.scattering * sampleDensity;
    vec3 sampleExtinction = layerParam.medium.extinction * sampleDensity;
    vec3 sampleOpticalDepth = sampleExtinction * stepState.rayStep.w;
    vec3 sampleTransmittance = exp(-sampleOpticalDepth);
    vec3 sampleLightIrradiance = renderParams.lightIrradiance;
    vec3 sampleLightTransmittance = exp(-lightOpticalDepth);
    sampleLightIrradiance *= tLightToSample * sampleLightTransmittance;
    float D = exp2(SETTING_CLOUDS_MS_RADIUS);
    float ambLightDesnity = mix(sampleDensityLod, sampleDensity, 0.4);
    vec3 ambLightOpticalDepth = layerParam.medium.extinction * ambLightDesnity;
    float horizonFactor = saturate(pow3(renderParams.cosLightTheta));
    ambLightOpticalDepth = mix(ambLightOpticalDepth, lightOpticalDepth, horizonFactor);
    vec3 ambientTransmittance = max(exp(-ambLightOpticalDepth), exp(-ambLightOpticalDepth * 0.25) * 0.7);
    vec3 sampleAmbientIrradiance = layerParam.ambientIrradiance;
    sampleAmbientIrradiance *= ambientTransmittance;
    vec3 sampleIrradiance = sampleLightIrradiance;
    sampleIrradiance *= layerParam.medium.phase;
    sampleIrradiance += sampleAmbientIrradiance;
    vec3 fMS = (sampleScattering / sampleExtinction) * (1.0 - exp(-D * sampleExtinction));
    fMS = mix(fMS, fMS * 0.99, linearStep(0.9, 1.0, fMS));
    vec3 sampleMSIrradiance = sampleLightIrradiance;
    sampleMSIrradiance *= UNIFORM_PHASE;
    sampleMSIrradiance += sampleAmbientIrradiance;
    sampleMSIrradiance *= fMS / (1.0 - fMS);
    sampleIrradiance += sampleMSIrradiance;
    vec3 sampleInSctr = sampleIrradiance * sampleScattering;
    vec3 sampleInSctrInt = (sampleInSctr - sampleInSctr * sampleTransmittance) / sampleExtinction;
    accumState.totalInSctr += sampleInSctrInt * accumState.totalTransmittance;
    accumState.totalTransmittance *= sampleTransmittance;
}
#define CLOUDS_AMBLUT_LAYER_STRAUS 0.5
#define CLOUDS_AMBLUT_LAYER_CUMULUS 1.5
#define CLOUDS_AMBLUT_LAYER_ALTOCUMULUS 2.5
#define CLOUDS_AMBLUT_LAYER_CIRRUS 3.5
#define CLOUDS_AMBLUT_LAYER_CIRROSTRATUS 4.5
#define CLOUDS_AMBLUT_LAYER_NOCTILUCENT 5.5
#define _CLOUDS_AMBLUT_SIZE 16.0
#define _CLOUDS_AMBLUT_SIZE_RCP rcp(_CLOUDS_AMBLUT_SIZE)
#define _CLOUDS_AMBLUT_SIZE_LAYERS 6.0
#define _CLOUDS_AMBLUT_SIZE_LAYERS_RCP rcp(_CLOUDS_AMBLUT_SIZE_LAYERS)
vec2 cloods_amblut_uv(vec3 viewDir, vec2 jitter) {
    vec2 uv = coords_equirectanglarForward(viewDir);
    uv += (jitter - 0.5) * _CLOUDS_AMBLUT_SIZE_RCP;
    uv = fract(uv);
    return uv;
}
vec2 clouds_amblut_tileUV(vec2 uv, float layer) {
    float layerIndex = clamp(floor(layer), 0.0, _CLOUDS_AMBLUT_SIZE_LAYERS - 1.0);
    return vec2(uv.x, (uv.y + layerIndex) * _CLOUDS_AMBLUT_SIZE_LAYERS_RCP);
}
vec4 clouds_amblut_sampleRaw(vec2 uv, float layer) {
    return persistent_cloudsAmbLUT_sample(clouds_amblut_tileUV(uv, layer));
}
vec3 clouds_amblut_sample(vec2 uv, float layer) {
    return clouds_amblut_sampleRaw(uv, layer).rgb;
}
#define MAT2_GOLDEN_ANGLE mat2(-0.737368878, 0.675490294, -0.675490294, -0.737368878)
mat2 mat2_rotate(float angle) {
    float c = cos(angle);
    float s = sin(angle);
    return mat2(
        c, -s,
        s, c
    );
}
/*
    References:
        [QUI08] Quilez, Inigo. "Value Noise Derivatives". 2008.
            https:
        [QUI13a] Quilez, Inigo. "Noise - value - 2D". 2013.
            MIT License. Copyright (c) 2013 Inigo Quilez.
            https:
        [QUI13b] Quilez, Inigo. "Noise - value - 3D". 2013.
            MIT License. Copyright (c) 2013 Inigo Quilez.
            https:
        [QUI17a] Quilez, Inigo. "Noise - Value - 2D - Deriv". 2017.
            MIT License. Copyright (c) 2017 Inigo Quilez.
            https:
        [QUI17b] Quilez, Inigo. "Noise - Value - 3D - Deriv". 2017.
            MIT License. Copyright (c) 2017 Inigo Quilez.
            https:

        You can find full license texts in /licenses
*/
/*
    References:
        [QUI17] Quilez, Inigo. "Integer Hash Functions". 2017.
            MIT License. Copyright (c) 2017,2024 Inigo Quilez.
            https:
            https:
            https:
        [JAR20] Jarzynski, Mark. Olano, Marc. "Hash Functions for GPU Rendering". 2020.
            https:

        You can find full license texts in /licenses
*/
const uvec4 _HASH_LINEAR_COMB_MAGIC_MUL = uvec4(19u, 47u, 101u, 131u);
const uint _HASH_LINEAR_COMB_MAGIC_ADD = 173u;
uvec3 hash_pcg3d_33(uvec3 v) {
    v = v * 1664525u + 1013904223u;
    v.x += v.y * v.z;
    v.y += v.z * v.x;
    v.z += v.x * v.y;
    v = v ^ (v >> 16u);
    v.x += v.y * v.z;
    v.y += v.z * v.x;
    v.z += v.x * v.y;
    return v;
}
const uint _HASH_XXHASH32_PRIME32_2 = 0x85EBCA77u;
const uint _HASH_XXHASH32_PRIME32_3 = 0xC2B2AE3Du;
const uint _HASH_XXHASH32_PRIME32_4 = 0x27D4EB2Fu;
const uint _HASH_XXHASH32_PRIME32_5 = 0x165667B1u;
uvec2 hash_22_q2(uvec2 v) {
    return hash_pcg3d_33(uvec3(v, _HASH_XXHASH32_PRIME32_2)).xy;
}
float hash_uintToFloat(uint v) {
    return uintBitsToFloat(0x3f800000u | (v >> 9u)) - 1.0;
}
vec2 hash_uintToFloat(uvec2 v) {
    return uintBitsToFloat(0x3f800000u | (v >> 9u)) - 1.0;
}
vec3 hash_uintToFloat(uvec3 v) {
    return uintBitsToFloat(0x3f800000u | (v >> 9u)) - 1.0;
}
vec4 hash_uintToFloat(uvec4 v) {
    return uintBitsToFloat(0x3f800000u | (v >> 9u)) - 1.0;
}
#define _NOISE_INTERPOLANT 1
struct FBMParameters {
    float frequency;
    float persistence;
    float lacunarity;
    uint octaveCount;
};
#if _NOISE_INTERPOLANT == 1
#define _NOISE_INTERPO(w) (w * w * w * (w * (w * 6.0 - 15.0) + 10.0))
#define _NOISE_INTERPO_GRAD(w) (30.0 * w * w * (w * (w - 2.0) + 1.0))
#else
#define _NOISE_INTERPO(w) (w * w * (3.0 - 2.0 * w))
#define _NOISE_INTERPO_GRAD(w) (6.0 * w * (1.0 - w))
#endif
ivec2 _noise_hash_coord_signed(vec2 x) {
    return ivec2(floor(x));
}
ivec3 _noise_hash_coord_signed(vec3 x) {
    return ivec3(floor(x));
}
uvec2 _noise_hash_coord(vec2 x) {
    return uvec2(_noise_hash_coord_signed(x));
}
uvec3 _noise_hash_coord(vec3 x) {
    return uvec3(_noise_hash_coord_signed(x));
}
/*
    References:
        [QUI13a] Quilez, Inigo. "Noise - gradient - 2D". 2013.
            MIT License. Copyright (c) 2013 Inigo Quilez.
            https:
        [QUI13b] Quilez, Inigo. "Noise - gradien  - 3D". 2013.
            MIT License. Copyright (c) 2013 Inigo Quilez.
            https:
        [QUI17a] Quilez, Inigo. "Noise - Gradient - 2D - Deriv". 2017.
            MIT License. Copyright (c) 2017 Inigo Quilez.
            https:
        [QUI17b] Quilez, Inigo. "Noise - Gradient - 3D - Deriv". 2017.
            MIT License. Copyright (c) 2017 Inigo Quilez.
            https:
        [QUI17c] Quilez, Inigo. "Gradient Noise Derivatives". 2017.
            https:

        You can find full license texts in /licenses
*/
struct AxisAngle {
    vec3 axis;
    vec3 csc;
};
/*
    References:
        [QUI15] Quilez, Inigo. "Texture Repetition". 2015.
            https:
        [QUI17] Quilez, Inigo. "Texture Repetition V". 2017.
            MIT License. Copyright (c) 2017 Inigo Quilez
            https:
        [DJO12] Djonov, Phill. "Bicubic Filtering in Fewer Taps". 2012.
            https:
        [MJP19] MJP. "An HLSL function for sampling a 2D texture with Catmull-Rom filtering, using 9 texture samples instead of 16". 2019.
            https:

        You can find full license texts in /licenses
*/
#if DERIVATIVE_AVAILABLE
#endif
vec4 sampling_catmullBicubic5Tap(sampler2D texSampler, vec2 texelPos, float sharpness, vec2 texRcpSize){
    vec2 t = fract(texelPos - 0.5);
    vec2 centerUV = (floor(texelPos - 0.5) + vec2(0.5f, 0.5f)) * texRcpSize;
    vec2 f = t;
    vec2 f2 = t * t;
    vec2 f3 = t * t * t;
    float s = sharpness;
    vec2 w0 = -s * f3 + 2.0 * s * f2 - s * f;
    vec2 w1 = (2.0 - s) * f3 + (s - 3.0) * f2 + 1.0;
    vec2 w2 = (s - 2.0) * f3 + (3.0 - 2.0 * s) * f2 + s * f;
    vec2 w3 = s * f3 - s * f2;
    vec2 w12 = w1 + w2;
    vec2 tc12 = centerUV + (w2 / w12) * texRcpSize;
    vec2 tc0 = centerUV - 1.0f * texRcpSize;
    vec2 tc3 = centerUV + 2.0f * texRcpSize;
    vec4 c1 = vec4(texture(texSampler, vec2(tc12.x, tc0.y)));
    vec4 c2 = vec4(texture(texSampler, vec2(tc0.x, tc12.y)));
    vec4 c3 = vec4(texture(texSampler, vec2(tc12.x, tc12.y)));
    vec4 c4 = vec4(texture(texSampler, vec2(tc3.x, tc12.y)));
    vec4 c5 = vec4(texture(texSampler, vec2(tc12.x, tc3.y)));
    float weight1 = w12.x * w0.y;
    float weight2 = w0.x * w12.y;
    float weight3 = w12.x * w12.y;
    float weight4 = w3.x * w12.y;
    float weight5 = w12.x * w3.y;
    vec4 color = weight1 * c1;
    color += weight2 * c2;
    color += weight3 * c3;
    color += weight4 * c4;
    color += weight5 * c5;
    return color * rcp(weight1 + weight2 + weight3 + weight4 + weight5);
}
struct CatmullRomBicubic5TapData {
    vec3 uv1AndWeight;
    vec3 uv2AndWeight;
    vec3 uv3AndWeight;
    vec3 uv4AndWeight;
    vec3 uv5AndWeight;
};
vec4 sampling_catmullBicubic5Tap(sampler2D texSampler, vec2 uv, float sharpness){
    vec2 texSize = vec2(textureSize(texSampler, 0));
    vec2 texelPos = uv * texSize;
    vec2 texRcpSize = rcp(texSize);
    return sampling_catmullBicubic5Tap(texSampler, texelPos, sharpness, texRcpSize);
}
vec4 sampling_bSplineBicubic4Tap(sampler2D texSampler, vec2 texelPos, vec2 texRcpSize) {
    vec2 f = fract(texelPos - 0.5);
    vec2 f2 = f * f;
    vec2 f3 = f2 * f;
    vec2 w0 = f2 - 0.5 * (f3 + f);
    vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
    vec2 w3 = 0.5 * (f3 - f2);
    vec2 w2 = 1.0 - w0 - w1 - w3;
    vec2 s0 = w0 + w1;
    vec2 s1 = w2 + w3;
    vec2 centerUV = (floor(texelPos - 0.5) + 0.5) * texRcpSize;
    vec2 t0 = centerUV + (w1 / s0 - 1.0) * texRcpSize;
    vec2 t1 = centerUV + (w3 / s1 + 1.0) * texRcpSize;
    return (texture(texSampler, vec2(t0.x, t0.y)) * s0.x
    + texture(texSampler, vec2(t1.x, t0.y)) * s1.x) * s0.y
    + (texture(texSampler, vec2(t0.x, t1.y)) * s0.x
    + texture(texSampler, vec2(t1.x, t1.y)) * s1.x) * s1.y;
}
vec4 sampling_bSplineBicubic4Tap(sampler2D texSampler, vec2 uv) {
    vec2 texSize = vec2(textureSize(texSampler, 0));
    vec2 texelPos = uv * texSize;
    vec2 texRcpSize = rcp(texSize);
    return sampling_bSplineBicubic4Tap(texSampler, texelPos, texRcpSize);
}
struct BSplineBicubic4TapData {
    vec2 uv00;
    vec2 uv10;
    vec2 uv01;
    vec2 uv11;
    vec2 weight0;
    vec2 weight1;
};
vec4 sampling_catmullRomBicubic9Tap(sampler2D texSampler, vec2 texelPos, vec2 texRcpSize) {
    vec2 samplePos = texelPos;
    vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
    vec2 f = samplePos - texPos1;
    vec2 w0 = f * (-0.5 + f * (1.0 - 0.5 * f));
    vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);
    vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));
    vec2 w3 = f * f * (-0.5 + 0.5 * f);
    vec2 w12 = w1 + w2;
    vec2 offset12 = w2 / w12;
    vec2 texPos0 = (texPos1 - 1.0) * texRcpSize;
    vec2 texPos3 = (texPos1 + 2.0) * texRcpSize;
    vec2 texPos12 = (texPos1 + offset12) * texRcpSize;
    vec4 result = vec4(0.0);
    result += texture(texSampler, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y;
    result += texture(texSampler, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y;
    result += texture(texSampler, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y;
    result += texture(texSampler, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y;
    result += texture(texSampler, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y;
    result += texture(texSampler, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y;
    result += texture(texSampler, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y;
    result += texture(texSampler, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y;
    result += texture(texSampler, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y;
    return result;
}
vec4 sampling_catmullRomBicubic9Tap(sampler2D texSampler, vec2 uv) {
    vec2 texSize = vec2(textureSize(texSampler, 0));
    vec2 texelPos = uv * texSize;
    vec2 texRcpSize = rcp(texSize);
    return sampling_catmullRomBicubic9Tap(texSampler, texelPos, texRcpSize);
}
struct CatmullRomBicubic9TapData {
    vec2 uv00;
    vec2 uv12_0;
    vec2 uv30;
    vec2 uv01_2;
    vec2 uv12_12;
    vec2 uv31_2;
    vec2 uv03;
    vec2 uv12_3;
    vec2 uv33;
    vec2 weight0;
    vec2 weight12;
    vec2 weight3;
};
vec2 _GradientNoise_2D_hash(uvec2 x) {
    return hash_uintToFloat(hash_22_q2(x)) * 2.0 - 1.0;
}
float GradientNoise_2D_value(vec2 x) {
    uvec2 i = _noise_hash_coord(x);
    vec2 w = fract(x);
    vec2 u = _NOISE_INTERPO(w);
    vec2 ga = _GradientNoise_2D_hash(i + uvec2(0, 0));
    vec2 gb = _GradientNoise_2D_hash(i + uvec2(1, 0));
    vec2 gc = _GradientNoise_2D_hash(i + uvec2(0, 1));
    vec2 gd = _GradientNoise_2D_hash(i + uvec2(1, 1));
    float va = dot(ga, w - vec2(0.0, 0.0));
    float vb = dot(gb, w - vec2(1.0, 0.0));
    float vc = dot(gc, w - vec2(0.0, 1.0));
    float vd = dot(gd, w - vec2(1.0, 1.0));
    float xy0 = mix(va, vb, u.x);
    float xy1 = mix(vc, vd, u.x);
    float value = mix(xy0, xy1, u.y);
    return value;
}
vec2 GradientNoise_2D_grad(vec2 x) {
    uvec2 i = _noise_hash_coord(x);
    vec2 w = fract(x);
    vec2 u = _NOISE_INTERPO(w);
    vec2 du = _NOISE_INTERPO_GRAD(w);
    vec2 ga = _GradientNoise_2D_hash(i + uvec2(0, 0));
    vec2 gb = _GradientNoise_2D_hash(i + uvec2(1, 0));
    vec2 gc = _GradientNoise_2D_hash(i + uvec2(0, 1));
    vec2 gd = _GradientNoise_2D_hash(i + uvec2(1, 1));
    float va = dot(ga, w - vec2(0.0, 0.0));
    float vb = dot(gb, w - vec2(1.0, 0.0));
    float vc = dot(gc, w - vec2(0.0, 1.0));
    float vd = dot(gd, w - vec2(1.0, 1.0));
    vec2 g = mix(mix(ga, gb, u.x), mix(gc, gd, u.x), u.y);
    vec2 d = mix(vec2(vb, vc)-va, vd - vec2(vc, vb), u.yx);
    vec2 grad = g + du * d;
    return grad;
}
float GradientNoise_2D_value_fbm(FBMParameters params, mat2 rotationMatrix, vec2 position) {
    float value = 0.0;
    float amplitude = 1.0;
    vec2 currPosition = position * params.frequency;
    for (uint i = 0; i < params.octaveCount; i++) {
        value += GradientNoise_2D_value(currPosition) * amplitude;
        amplitude *= params.persistence;
        currPosition = (rotationMatrix * currPosition) * params.lacunarity;
    }
    return value;
}
vec2 GradientNoise_2D_grad_fbm(FBMParameters params, mat2 rotationMatrix, vec2 position) {
    vec2 value = vec2(0.0);
    float amplitude = 1.0;
    vec2 currPosition = position * params.frequency;
    for (uint i = 0; i < params.octaveCount; i++) {
        value += GradientNoise_2D_grad(currPosition) * amplitude;
        amplitude *= params.persistence;
        currPosition = (rotationMatrix * currPosition) * params.lacunarity;
    }
    return value;
}
float _clouds_ci_density_layer(vec2 texCoord) {
    return texture(usam_cirrus, texCoord).x;
}
float clouds_ci_density(vec3 rayPos) {
    FBMParameters curlParams;
    curlParams.frequency = 0.01;
    curlParams.persistence = 0.8;
    curlParams.lacunarity = 2.0;
    curlParams.octaveCount = 3u;
    mat2 rotatioMatrix = mat2_rotate(GOLDEN_ANGLE);
    vec2 curl = GradientNoise_2D_grad_fbm(curlParams, rotatioMatrix, rayPos.xz);
    FBMParameters shapeParams;
    shapeParams.frequency = 0.04;
    shapeParams.persistence = 0.6;
    shapeParams.lacunarity = 1.9;
    shapeParams.octaveCount = 3u;
    mat2 shapeRotMat = mat2_rotate(PI_QUARTER);
    float coverage = GradientNoise_2D_value_fbm(shapeParams, shapeRotMat, rayPos.xz + vec2(-8.0, -4.0) + curl * 16.0);
    coverage = pow3(linearStep(0.5 - SETTING_CLOUDS_CI_COVERAGE * 1.5, 1.0, coverage));
    float density = 0.0;
    density += _clouds_ci_density_layer((rayPos.xz + 0.114) * 0.12 + curl * 2.5) * 0.125;
    density += _clouds_ci_density_layer((rayPos.xz + 0.514) * 0.08 + curl * 0.8) * 0.25;
    density += _clouds_ci_density_layer(rayPos.xz * 0.02 + curl * 0.4) * 0.5;
    density *= SETTING_CLOUDS_CI_DENSITY;
    return coverage * density;
}
/*
    References:
        [QUI13a] Quilez, Inigo. "Voronoi - smooth ". 2014.
            MIT License. Copyright (c) 2014 Inigo Quilez.
            https:

        You can find full license texts in /licenses
*/
const float _LOW_BASE_FREQ = exp2(SETTING_CLOUDS_LOW_BASE_FREQ);
const float _LOW_CURL_FREQ = exp2(SETTING_CLOUDS_LOW_CURL_FREQ);
const float _LOW_BILLOWY_FREQ = exp2(SETTING_CLOUDS_LOW_BILLOWY_FREQ - 1.0);
const float _LOW_BILLOWY_CURL_STR = exp2(SETTING_CLOUDS_LOW_BILLOWY_CURL_STR - 1.0);
const float _HIGH_BILLOWY_FREQ = exp2(SETTING_CLOUDS_HIGH_BILLOWY_FREQ);
const float _HIGH_BILLOWY_CURL_STR = exp2(SETTING_CLOUDS_HIGH_BILLOWY_CURL_STR);
const float _LOW_WISPS_FREQ = exp2(SETTING_CLOUDS_LOW_WISPS_FREQ);
const float _LOW_WISPS_CURL_STR = exp2(SETTING_CLOUDS_LOW_WISPS_CURL_STR);
/*
b_{i}
-1.755622
3.6801126
-163.09651
320.59657
-163.29147
0.01273534
*/
/*
c_{i}
-2.8940248
20.938597
-83.765418
114.27168
-53.99707
*/
#if SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 0
#define UPSCALE_FACTOR 1.0
#define DOWNSCALE_DIVIDE(x) x
#define RENDER_MULTIPLIER 1.0
#define CHECK_MIP_LEVEL 3
#define CHECK_MIP_FACTOR 8.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 1
#define UPSCALE_FACTOR 1.5
#define DOWNSCALE_DIVIDE(x) (x * 2 / 3)
#define RENDER_MULTIPLIER 0.6666666667
#define CHECK_MIP_LEVEL 3
#define CHECK_MIP_FACTOR 8.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 2
#define UPSCALE_FACTOR 2.0
#define DOWNSCALE_DIVIDE(x) (x / 2)
#define RENDER_MULTIPLIER 0.5
#define CHECK_MIP_LEVEL 4
#define CHECK_MIP_FACTOR 16.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 3
#define UPSCALE_FACTOR 2.5
#define DOWNSCALE_DIVIDE(x) (x * 2 / 5)
#define RENDER_MULTIPLIER 0.4
#define CHECK_MIP_LEVEL 4
#define CHECK_MIP_FACTOR 16.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 4
#define UPSCALE_FACTOR 3.0
#define DOWNSCALE_DIVIDE(x) (x / 3)
#define RENDER_MULTIPLIER 0.3333333333
#define CHECK_MIP_LEVEL 5
#define CHECK_MIP_FACTOR 32.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 5
#define UPSCALE_FACTOR 3.5
#define DOWNSCALE_DIVIDE(x) (x * 2 / 7)
#define RENDER_MULTIPLIER 0.2857142857
#define CHECK_MIP_LEVEL 5
#define CHECK_MIP_FACTOR 32.0
#elif SETTING_CLOUDS_LOW_UPSCALE_FACTOR == 6
#define UPSCALE_FACTOR 4.0
#define DOWNSCALE_DIVIDE(x) (x / 4)
#define RENDER_MULTIPLIER 0.25
#define CHECK_MIP_LEVEL 6
#define CHECK_MIP_FACTOR 64.0
#endif
ivec2 renderSize = DOWNSCALE_DIVIDE(uval_mainImageSizeI);
#define CLOUDS_SS_MAX_ACCUM SETTING_CLOUDS_LOW_MAX_ACCUM
struct CloudSSHistoryData {
    vec3 inScattering;
    vec3 transmittance;
    float hLen;
};
CloudSSHistoryData clouds_ss_historyData_init() {
    CloudSSHistoryData data;
    data.inScattering = vec3(0.0);
    data.transmittance = vec3(1.0);
    data.hLen = 0.0;
    return data;
}
void clouds_ss_historyData_pack(out uvec4 packedData, CloudSSHistoryData data) {
    data.inScattering = clamp(data.inScattering, 0.0, FP16_MAX);
    packedData.x = packHalf2x16(data.inScattering.xy);
    packedData.y = packHalf2x16(vec2(data.inScattering.z, data.transmittance.x));
    packedData.z = packHalf2x16(data.transmittance.yz);
    packedData.w = floatBitsToUint(data.hLen);
}
void clouds_ss_historyData_unpack(uvec4 packedData, out CloudSSHistoryData data) {
    if (packedData == uvec4(0u)) {
        data = clouds_ss_historyData_init();
    }
    vec2 temp1 = unpackHalf2x16(packedData.x);
    vec2 temp2 = unpackHalf2x16(packedData.y);
    vec2 temp3 = unpackHalf2x16(packedData.z);
    data.inScattering = vec3(temp1.xy, temp2.x);
    data.transmittance = vec3(temp2.y, temp3.xy);
    data.hLen = uintBitsToFloat(packedData.w);
}
/*
    References:
        [INT17] Intel Corporation. "Outdoor Light Scattering Sample". 2017.
            Apache License 2.0. Copyright (c) 2017 Intel Corporation.
            https:

        You can find full license texts in /licenses
*/
const float DENSITY_EPSILON = 0.0001;
ScatteringResult atmospherics_skyComposite(ivec2 texelPos, vec3 viewPos) {
    vec3 originView = vec3(0.0);
    vec3 endView = viewPos;
    mat3 vectorView2World = mat3(gbufferModelViewInverse);
    vec3 viewDirView = normalize(endView - originView);
    vec3 viewDirWorld = normalize(vectorView2World * viewDirView);
    float ignValue = rand_IGN(texelPos, frameCounter);
    AtmosphereParameters atmosphere = getAtmosphereParameters();
    CloudMainRayParams mainRayParams;
    mainRayParams.rayStart = atmosphere_viewToAtmNoClamping(atmosphere, originView);
    const vec3 earthCenter = vec3(0.0);
    ScatteringResult compositeResult = scatteringResult_init();
    vec3 rayDir = viewDirWorld;
    if (viewPos.z <= -65536.0) {
        float rayLen = 0.0;
        if (length(mainRayParams.rayStart) > atmosphere.top) {
            float tTop = raySphereIntersectNearest(mainRayParams.rayStart, rayDir, earthCenter, atmosphere.top);
            if (tTop < 0.0) {
                rayLen = -1.0;
            }
            mainRayParams.rayStart += rayDir * (tTop + 0.001);
        }
        float clampedBottom = min(atmosphere.bottom, length(mainRayParams.rayStart) - 0.001);
        float tBottom = raySphereIntersectNearest(mainRayParams.rayStart, rayDir, earthCenter, clampedBottom);
        float tTop = raySphereIntersectNearest(mainRayParams.rayStart, rayDir, earthCenter, atmosphere.top);
        if (tBottom < 0.0) {
            if (tTop < 0.0) {
                rayLen = -1.0;
            } else {
                rayLen = tTop;
            }
        } else {
            if (tTop > 0.0) {
                rayLen = min(tTop, tBottom);
            }
        }
        if (rayLen >= 0.0) {
            mainRayParams.rayEnd = mainRayParams.rayStart + rayDir * rayLen;
            mainRayParams.rayDir = normalize(mainRayParams.rayEnd - mainRayParams.rayStart);
            mainRayParams.rayStartHeight = length(mainRayParams.rayStart);
            mainRayParams.rayEndHeight = length(mainRayParams.rayEnd);
            float sunAngleWarped = fract(sunAngle + 0.25);
            float sunLightFactor = smoothstep(0.23035, 0.24035, sunAngleWarped);
            sunLightFactor *= smoothstep(0.76965, 0.75965, sunAngleWarped);
            sunLightFactor *= step(0.5, sunLightFactor);
            vec3 lightDir = mix(uval_moonDirWorld, uval_sunDirWorld, sunLightFactor);
            vec3 lightIlluminance = mix(MOON_ILLUMINANCE, SUN_ILLUMINANCE, sunLightFactor);
            CloudRenderParams renderParams = cloudRenderParams_init(mainRayParams, lightDir, lightIlluminance);
            vec2 jitters = rand_stbnVec2(texelPos, frameCounter);
            vec3 viewDir = mainRayParams.rayDir;
            vec2 ambLutUV = cloods_amblut_uv(viewDir, jitters);
            vec3 rayEndView = viewPos;
            vec3 rayDir = normalize(mat3(gbufferModelViewInverse) * rayEndView);
            SkyViewLutParams skyViewLutParams = atmospherics_air_lut_setupSkyViewLutParams(atmosphere, rayDir);
            #ifdef SETTING_CLOUDS_CU
            uvec4 packedData = transient_lowCloudAccumulated_fetch(texelPos);
            history_lowCloud_store(texelPos, packedData);
            #endif
            {
                ScatteringResult layerResult = atmospherics_air_lut_sampleSkyViewLUT(atmosphere, skyViewLutParams, 1.0);
                compositeResult = scatteringResult_blendLayer(compositeResult, layerResult, true);
            }
            #ifdef SETTING_CLOUDS_CU
            {
                float cuMinHeight = atmosphere.bottom + SETTING_CLOUDS_CU_HEIGHT;
                float cuMaxHeight = cuMinHeight + SETTING_CLOUDS_CU_THICKNESS;
                float cuMidHeight = cuMinHeight + SETTING_CLOUDS_CU_THICKNESS * 0.5;
                float cuHeightDiff = cuMidHeight - mainRayParams.rayStartHeight;
                float cuRayLenBot = raySphereIntersectNearest(mainRayParams.rayStart, mainRayParams.rayDir, earthCenter, cuMinHeight);
                float cuRayLenTop = raySphereIntersectNearest(mainRayParams.rayStart, mainRayParams.rayDir, earthCenter, cuMaxHeight);
                bool inLayer = abs(cuHeightDiff) < SETTING_CLOUDS_CU_THICKNESS * 0.5;
                float cuOrigin2RayStart = inLayer ? 0.0 : (cuHeightDiff < 0.0 ? cuRayLenTop : cuRayLenBot);
                uint cuFlag = uint(sign(cuHeightDiff) == sign(mainRayParams.rayDir.y)) | uint(inLayer);
                cuFlag &= uint(cuOrigin2RayStart >= 0.0);
                if (bool(cuFlag)) {
                    CloudSSHistoryData historyData = clouds_ss_historyData_init();
                    clouds_ss_historyData_unpack(packedData, historyData);
                    bool above = inLayer || cuHeightDiff < 0.0;
                    ScatteringResult layerResult = ScatteringResult(
                        historyData.transmittance,
                        historyData.inScattering
                    );
                    compositeResult = scatteringResult_blendLayer(
                        compositeResult,
                        layerResult,
                        above
                    );
                }
            }
            #endif
            {
                ScatteringResult layerResult = atmospherics_air_lut_sampleSkyViewLUT(atmosphere, skyViewLutParams, 2.0);
                bool above = skyViewLutParams.viewHeight >= atmosphere.bottom + SETTING_CLOUDS_CU_HEIGHT + SETTING_CLOUDS_CU_THICKNESS * 0.5;
                compositeResult = scatteringResult_blendLayer(compositeResult, layerResult, above);
            }
            #ifdef SETTING_CLOUDS_CI
            {
                float ciHeight = atmosphere.bottom + SETTING_CLOUDS_CI_HEIGHT;
                float ciMinHeight = ciHeight - 0.5;
                float ciMaxHeight = ciHeight + 0.5;
                float ciHeighDiff = ciHeight - mainRayParams.rayStartHeight;
                float ciOrigin2RayOffset = raySphereIntersectNearest(mainRayParams.rayStart, mainRayParams.rayDir, earthCenter, ciHeight);
                uint ciFlag = uint(sign(ciHeighDiff) == sign(mainRayParams.rayDir.y)) & uint(ciOrigin2RayOffset > 0.0);
                if (bool(ciFlag)) {
                    vec3 ambientIrradiance = clouds_amblut_sample(ambLutUV, CLOUDS_AMBLUT_LAYER_CIRRUS);
                    CloudParticpatingMedium ciMedium = clouds_ci_medium(renderParams.cosLightTheta);
                    CloudRaymarchLayerParam layerParam = clouds_raymarchLayerParam_init(
                        mainRayParams,
                        ciMedium,
                        ambientIrradiance,
                        vec2(ciMinHeight, ciMaxHeight),
                        ciOrigin2RayOffset,
                        1.0,
                        0u
                    );
                    CloudRaymarchStepState stepState = clouds_raymarchStepState_init(layerParam);
                    float sampleDensity = clouds_ci_density(stepState.position.xyz);
                    CloudRaymarchAccumState ciAccum = clouds_raymarchAccumState_init();
                    if (sampleDensity > DENSITY_EPSILON) {
                        clouds_computeLighting(
                            atmosphere,
                            renderParams,
                            layerParam,
                            stepState,
                            sampleDensity,
                            sampleDensity * 0.5,
                            vec3(0.0),
                            ciAccum
                        );
                    };
                    ScatteringResult layerResult = ScatteringResult(
                        ciAccum.totalTransmittance,
                        ciAccum.totalInSctr
                    );
                    bool aboveFlag = ciHeighDiff < 0.0;
                    compositeResult = scatteringResult_blendLayer(compositeResult, layerResult, aboveFlag);
                }
            }
            #endif
            {
                ScatteringResult layerResult = atmospherics_air_lut_sampleSkyViewLUT(atmosphere, skyViewLutParams, 3.0);
                bool above = skyViewLutParams.viewHeight >= atmosphere.bottom + SETTING_CLOUDS_CI_HEIGHT;
                compositeResult = scatteringResult_blendLayer(compositeResult, layerResult, above);
            }
        } else {
            CloudSSHistoryData newHistoryData = clouds_ss_historyData_init();
            uvec4 packedData = uvec4(0u);
            clouds_ss_historyData_pack(packedData, newHistoryData);
            history_lowCloud_store(texelPos, packedData);
        }
    } else {
        CloudSSHistoryData newHistoryData = clouds_ss_historyData_init();
        uvec4 packedData = uvec4(0u);
        clouds_ss_historyData_pack(packedData, newHistoryData);
        history_lowCloud_store(texelPos, packedData);
    }
    return compositeResult;
}
void doLighting(ivec2 texelPos, Material material, vec3 viewPos, vec3 N, inout vec3 mainOut, inout vec4 giOut1, inout vec4 giOut2) {
    vec3 emissiveV = material.emissive;
    AtmosphereParameters atmosphere = getAtmosphereParameters();
    material.albedo = max(material.albedo, 0.0001);
    vec3 feetPlayerPos = (gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz;
    vec3 worldPos = feetPlayerPos + cameraPosition;
    vec3 atmPos = atmosphere_viewToAtm(atmosphere, viewPos);
    atmPos.y = max(atmPos.y, atmosphere.bottom + 0.1);
    float viewAltitude = length(atmPos);
    vec3 upVector = atmPos / viewAltitude;
    const vec3 earthCenter = vec3(0.0, 0.0, 0.0);
    vec3 V = normalize(-viewPos);
    vec4 shadow = transient_shadow_fetch(texelPos);
    const float decay = 256.0 / pow2(shadow.w);
    material.sss -= rand_stbnVec1(texelPos, frameCounter) * (1.0 - rcp(1.0 + pow2(viewPos.z / decay)));
    float shadowIsSun = float(all(equal(sunPosition, shadowLightPosition)));
    float cosSunZenith = dot(uval_sunDirWorld, vec3(0.0, 1.0, 0.0));
    vec3 tSun = atmospherics_air_lut_sampleTransmittance(atmosphere, cosSunZenith, viewAltitude);
    tSun *= float(raySphereIntersectNearest(atmPos, uval_sunDirWorld, earthCenter + PLANET_RADIUS_OFFSET * upVector, atmosphere.bottom) < 0.0);
    vec4 sunShadow = mix(vec4(1.0), shadow, shadowIsSun);
    vec3 sunIrradiance = SUN_ILLUMINANCE * tSun;
    LightingResult sunLighting = directLighting(lighting_gData, material, sunIrradiance, sunShadow, V, uval_sunDirView, N);
    float cosMoonZenith = dot(uval_moonDirWorld, vec3(0.0, 1.0, 0.0));
    vec3 tMoon = atmospherics_air_lut_sampleTransmittance(atmosphere, cosMoonZenith, viewAltitude);
    tMoon *= float(raySphereIntersectNearest(atmPos, uval_moonDirWorld, earthCenter + PLANET_RADIUS_OFFSET * upVector, atmosphere.bottom) < 0.0);
    vec4 moonShadow = mix(shadow, vec4(1.0), shadowIsSun);
    vec3 moonIrradiance = MOON_ILLUMINANCE * tMoon;
    LightingResult moonLighting = directLighting(lighting_gData, material, moonIrradiance, moonShadow, V, uval_moonDirView, N);
    LightingResult combinedLighting = lightingResult_add(sunLighting, moonLighting);
    mainOut += 0.00001 * material.albedo;
    mainOut += emissiveV;
    mainOut += combinedLighting.diffuse;
    mainOut += combinedLighting.specular;
    mainOut += combinedLighting.sss;
    giOut1.rgb += combinedLighting.diffuseLambertian;
    giOut2.rgb += emissiveV;
}
void main() {
    uint workGroupIdx = gl_WorkGroupID.y * gl_NumWorkGroups.x + gl_WorkGroupID.x;
    uvec2 swizzledWGPos = ssbo_threadGroupTiling[workGroupIdx];
    uvec2 workGroupOrigin = swizzledWGPos << 4u;
    uint threadIdx = gl_SubgroupID * gl_SubgroupSize + gl_SubgroupInvocationID;
    uvec2 mortonPos = morton_8bDecode(threadIdx);
    uvec2 mortonGlobalPosU = workGroupOrigin + mortonPos;
    ivec2 texelPos = ivec2(mortonGlobalPosU);
    if (all(lessThan(texelPos, uval_mainImageSizeI))) {
        vec4 mainOut = vec4(0.0);
        float viewZ = hiz_groupGroundCheckSubgroupLoadViewZ(swizzledWGPos.xy, 4, texelPos);
        vec2 screenPos = coords_texelToUV(texelPos, uval_mainImageSizeRcp) - uval_taaJitterUV;
        vec3 viewPos = coords_toViewCoord(screenPos, viewZ, global_camProjInverse);
        ScatteringResult sctrResult = atmospherics_skyComposite(texelPos, viewPos);
        if (viewZ > -65536.0) {
            gbufferData1_unpack(texelFetch(colortex8, texelPos, 0), lighting_gData);
            gbufferData2_unpack(texelFetch(colortex9, texelPos, 0), lighting_gData);
            transient_lmCoord_store(texelPos, vec4(lighting_gData.lmCoord, 0.0, 0.0));
            Material material = material_decode(lighting_gData);
            vec4 glintColorData = texelFetch(colortex4, texelPos, 0);
            vec3 glintColor = colors2_material_toWorkSpace(glintColorData.rgb) * glintColorData.a;
            glintColor = pow(glintColor, vec3(SETTING_EMISSIVE_ARMOR_GLINT_CURVE));
            glintColor *= exp2(SETTING_EMISSIVE_STRENGTH + SETTING_EMISSIVE_ARMOR_GLINT_MULT);
            material.emissive += glintColor + material.albedo * glintColor * 4.0;
            vec4 giOut1 = vec4(0.0);
            vec4 giOut2 = vec4(0.0);
            if (lighting_gData.materialID == 65534u) {
                mainOut = vec4(material.albedo * 0.01, 2.0);
                giOut1 = vec4(0.0);
            } else {
                doLighting(texelPos, material, viewPos, lighting_gData.normal, mainOut.rgb, giOut1, giOut2);
            }
            giOut1.rgb += transient_gi2Reprojected_fetch(texelPos).rgb * min(material.albedo, 0.95);
            giOut1.rgb = clamp(giOut1.rgb, 0.0, FP16_MAX);
            giOut2.rgb = clamp(giOut2.rgb, 0.0, FP16_MAX);
            uvec4 giRadianceInput = uvec4(0u);
            giRadianceInput.x = colors_workingColorToFP16Luv(giOut1.rgb);
            giRadianceInput.y = colors_workingColorToFP16Luv(giOut2.rgb);
            transient_giRadianceInputs_store(texelPos, giRadianceInput);
        } else {
            vec4 temp6Out = texelFetch(colortex6, texelPos, 0);
            mainOut = celestial_render(texelPos, temp6Out);
            #ifdef SETTING_CONSTELLATIONS
            imageStore(colorimg6, texelPos, temp6Out);
            #endif
            mainOut.rgb = scatteringResult_apply(sctrResult, mainOut.rgb);
            transient_giRadianceInputs_store(texelPos, uvec4(0u));
            transient_lmCoord_store(texelPos, vec4(0.0));
        }
        mainOut.rgb = clamp(mainOut.rgb, 0.0, FP16_MAX);
        imageStore(colorimg0, texelPos, mainOut);
    }
}