A game about forced loneliness, made by TACStudios
1#ifndef UNITY_HAMMERSLEY_INCLUDED 2#define UNITY_HAMMERSLEY_INCLUDED 3 4#if SHADER_API_MOBILE || SHADER_API_GLES3 || SHADER_API_SWITCH || defined(UNITY_UNIFIED_SHADER_PRECISION_MODEL) 5#pragma warning (disable : 3205) // conversion of larger type to smaller 6#endif 7 8// Ref: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html 9uint ReverseBits32(uint bits) 10{ 11#if (SHADER_TARGET >= 45) 12 return reversebits(bits); 13#else 14 bits = (bits << 16) | (bits >> 16); 15 bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >> 8); 16 bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >> 4); 17 bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2); 18 bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1); 19 return bits; 20#endif 21} 22 23real VanDerCorputBase2(uint i) 24{ 25 return ReverseBits32(i) * rcp(4294967296.0); // 2^-32 26} 27 28real2 Hammersley2dSeq(uint i, uint sequenceLength) 29{ 30 return real2(real(i) / real(sequenceLength), VanDerCorputBase2(i)); 31} 32 33#ifdef HAMMERSLEY_USE_CB 34 #include "Packages/com.unity.render-pipelines.core/Runtime/ShaderLibrary/Sampling/Hammersley.cs.hlsl" 35#else 36 37static const real2 k_Hammersley2dSeq16[] = { 38 real2(0.00000000, 0.00000000), 39 real2(0.06250000, 0.50000000), 40 real2(0.12500000, 0.25000000), 41 real2(0.18750000, 0.75000000), 42 real2(0.25000000, 0.12500000), 43 real2(0.31250000, 0.62500000), 44 real2(0.37500000, 0.37500000), 45 real2(0.43750000, 0.87500000), 46 real2(0.50000000, 0.06250000), 47 real2(0.56250000, 0.56250000), 48 real2(0.62500000, 0.31250000), 49 real2(0.68750000, 0.81250000), 50 real2(0.75000000, 0.18750000), 51 real2(0.81250000, 0.68750000), 52 real2(0.87500000, 0.43750000), 53 real2(0.93750000, 0.93750000) 54}; 55 56static const real2 k_Hammersley2dSeq32[] = { 57 real2(0.00000000, 0.00000000), 58 real2(0.03125000, 0.50000000), 59 real2(0.06250000, 0.25000000), 60 real2(0.09375000, 0.75000000), 61 real2(0.12500000, 0.12500000), 62 real2(0.15625000, 0.62500000), 63 real2(0.18750000, 0.37500000), 64 real2(0.21875000, 0.87500000), 65 real2(0.25000000, 0.06250000), 66 real2(0.28125000, 0.56250000), 67 real2(0.31250000, 0.31250000), 68 real2(0.34375000, 0.81250000), 69 real2(0.37500000, 0.18750000), 70 real2(0.40625000, 0.68750000), 71 real2(0.43750000, 0.43750000), 72 real2(0.46875000, 0.93750000), 73 real2(0.50000000, 0.03125000), 74 real2(0.53125000, 0.53125000), 75 real2(0.56250000, 0.28125000), 76 real2(0.59375000, 0.78125000), 77 real2(0.62500000, 0.15625000), 78 real2(0.65625000, 0.65625000), 79 real2(0.68750000, 0.40625000), 80 real2(0.71875000, 0.90625000), 81 real2(0.75000000, 0.09375000), 82 real2(0.78125000, 0.59375000), 83 real2(0.81250000, 0.34375000), 84 real2(0.84375000, 0.84375000), 85 real2(0.87500000, 0.21875000), 86 real2(0.90625000, 0.71875000), 87 real2(0.93750000, 0.46875000), 88 real2(0.96875000, 0.96875000) 89}; 90 91static const real2 k_Hammersley2dSeq64[] = { 92 real2(0.00000000, 0.00000000), 93 real2(0.01562500, 0.50000000), 94 real2(0.03125000, 0.25000000), 95 real2(0.04687500, 0.75000000), 96 real2(0.06250000, 0.12500000), 97 real2(0.07812500, 0.62500000), 98 real2(0.09375000, 0.37500000), 99 real2(0.10937500, 0.87500000), 100 real2(0.12500000, 0.06250000), 101 real2(0.14062500, 0.56250000), 102 real2(0.15625000, 0.31250000), 103 real2(0.17187500, 0.81250000), 104 real2(0.18750000, 0.18750000), 105 real2(0.20312500, 0.68750000), 106 real2(0.21875000, 0.43750000), 107 real2(0.23437500, 0.93750000), 108 real2(0.25000000, 0.03125000), 109 real2(0.26562500, 0.53125000), 110 real2(0.28125000, 0.28125000), 111 real2(0.29687500, 0.78125000), 112 real2(0.31250000, 0.15625000), 113 real2(0.32812500, 0.65625000), 114 real2(0.34375000, 0.40625000), 115 real2(0.35937500, 0.90625000), 116 real2(0.37500000, 0.09375000), 117 real2(0.39062500, 0.59375000), 118 real2(0.40625000, 0.34375000), 119 real2(0.42187500, 0.84375000), 120 real2(0.43750000, 0.21875000), 121 real2(0.45312500, 0.71875000), 122 real2(0.46875000, 0.46875000), 123 real2(0.48437500, 0.96875000), 124 real2(0.50000000, 0.01562500), 125 real2(0.51562500, 0.51562500), 126 real2(0.53125000, 0.26562500), 127 real2(0.54687500, 0.76562500), 128 real2(0.56250000, 0.14062500), 129 real2(0.57812500, 0.64062500), 130 real2(0.59375000, 0.39062500), 131 real2(0.60937500, 0.89062500), 132 real2(0.62500000, 0.07812500), 133 real2(0.64062500, 0.57812500), 134 real2(0.65625000, 0.32812500), 135 real2(0.67187500, 0.82812500), 136 real2(0.68750000, 0.20312500), 137 real2(0.70312500, 0.70312500), 138 real2(0.71875000, 0.45312500), 139 real2(0.73437500, 0.95312500), 140 real2(0.75000000, 0.04687500), 141 real2(0.76562500, 0.54687500), 142 real2(0.78125000, 0.29687500), 143 real2(0.79687500, 0.79687500), 144 real2(0.81250000, 0.17187500), 145 real2(0.82812500, 0.67187500), 146 real2(0.84375000, 0.42187500), 147 real2(0.85937500, 0.92187500), 148 real2(0.87500000, 0.10937500), 149 real2(0.89062500, 0.60937500), 150 real2(0.90625000, 0.35937500), 151 real2(0.92187500, 0.85937500), 152 real2(0.93750000, 0.23437500), 153 real2(0.95312500, 0.73437500), 154 real2(0.96875000, 0.48437500), 155 real2(0.98437500, 0.98437500) 156}; 157 158static const real2 k_Hammersley2dSeq256[] = { 159 real2(0.00000000, 0.00000000), 160 real2(0.00390625, 0.50000000), 161 real2(0.00781250, 0.25000000), 162 real2(0.01171875, 0.75000000), 163 real2(0.01562500, 0.12500000), 164 real2(0.01953125, 0.62500000), 165 real2(0.02343750, 0.37500000), 166 real2(0.02734375, 0.87500000), 167 real2(0.03125000, 0.06250000), 168 real2(0.03515625, 0.56250000), 169 real2(0.03906250, 0.31250000), 170 real2(0.04296875, 0.81250000), 171 real2(0.04687500, 0.18750000), 172 real2(0.05078125, 0.68750000), 173 real2(0.05468750, 0.43750000), 174 real2(0.05859375, 0.93750000), 175 real2(0.06250000, 0.03125000), 176 real2(0.06640625, 0.53125000), 177 real2(0.07031250, 0.28125000), 178 real2(0.07421875, 0.78125000), 179 real2(0.07812500, 0.15625000), 180 real2(0.08203125, 0.65625000), 181 real2(0.08593750, 0.40625000), 182 real2(0.08984375, 0.90625000), 183 real2(0.09375000, 0.09375000), 184 real2(0.09765625, 0.59375000), 185 real2(0.10156250, 0.34375000), 186 real2(0.10546875, 0.84375000), 187 real2(0.10937500, 0.21875000), 188 real2(0.11328125, 0.71875000), 189 real2(0.11718750, 0.46875000), 190 real2(0.12109375, 0.96875000), 191 real2(0.12500000, 0.01562500), 192 real2(0.12890625, 0.51562500), 193 real2(0.13281250, 0.26562500), 194 real2(0.13671875, 0.76562500), 195 real2(0.14062500, 0.14062500), 196 real2(0.14453125, 0.64062500), 197 real2(0.14843750, 0.39062500), 198 real2(0.15234375, 0.89062500), 199 real2(0.15625000, 0.07812500), 200 real2(0.16015625, 0.57812500), 201 real2(0.16406250, 0.32812500), 202 real2(0.16796875, 0.82812500), 203 real2(0.17187500, 0.20312500), 204 real2(0.17578125, 0.70312500), 205 real2(0.17968750, 0.45312500), 206 real2(0.18359375, 0.95312500), 207 real2(0.18750000, 0.04687500), 208 real2(0.19140625, 0.54687500), 209 real2(0.19531250, 0.29687500), 210 real2(0.19921875, 0.79687500), 211 real2(0.20312500, 0.17187500), 212 real2(0.20703125, 0.67187500), 213 real2(0.21093750, 0.42187500), 214 real2(0.21484375, 0.92187500), 215 real2(0.21875000, 0.10937500), 216 real2(0.22265625, 0.60937500), 217 real2(0.22656250, 0.35937500), 218 real2(0.23046875, 0.85937500), 219 real2(0.23437500, 0.23437500), 220 real2(0.23828125, 0.73437500), 221 real2(0.24218750, 0.48437500), 222 real2(0.24609375, 0.98437500), 223 real2(0.25000000, 0.00781250), 224 real2(0.25390625, 0.50781250), 225 real2(0.25781250, 0.25781250), 226 real2(0.26171875, 0.75781250), 227 real2(0.26562500, 0.13281250), 228 real2(0.26953125, 0.63281250), 229 real2(0.27343750, 0.38281250), 230 real2(0.27734375, 0.88281250), 231 real2(0.28125000, 0.07031250), 232 real2(0.28515625, 0.57031250), 233 real2(0.28906250, 0.32031250), 234 real2(0.29296875, 0.82031250), 235 real2(0.29687500, 0.19531250), 236 real2(0.30078125, 0.69531250), 237 real2(0.30468750, 0.44531250), 238 real2(0.30859375, 0.94531250), 239 real2(0.31250000, 0.03906250), 240 real2(0.31640625, 0.53906250), 241 real2(0.32031250, 0.28906250), 242 real2(0.32421875, 0.78906250), 243 real2(0.32812500, 0.16406250), 244 real2(0.33203125, 0.66406250), 245 real2(0.33593750, 0.41406250), 246 real2(0.33984375, 0.91406250), 247 real2(0.34375000, 0.10156250), 248 real2(0.34765625, 0.60156250), 249 real2(0.35156250, 0.35156250), 250 real2(0.35546875, 0.85156250), 251 real2(0.35937500, 0.22656250), 252 real2(0.36328125, 0.72656250), 253 real2(0.36718750, 0.47656250), 254 real2(0.37109375, 0.97656250), 255 real2(0.37500000, 0.02343750), 256 real2(0.37890625, 0.52343750), 257 real2(0.38281250, 0.27343750), 258 real2(0.38671875, 0.77343750), 259 real2(0.39062500, 0.14843750), 260 real2(0.39453125, 0.64843750), 261 real2(0.39843750, 0.39843750), 262 real2(0.40234375, 0.89843750), 263 real2(0.40625000, 0.08593750), 264 real2(0.41015625, 0.58593750), 265 real2(0.41406250, 0.33593750), 266 real2(0.41796875, 0.83593750), 267 real2(0.42187500, 0.21093750), 268 real2(0.42578125, 0.71093750), 269 real2(0.42968750, 0.46093750), 270 real2(0.43359375, 0.96093750), 271 real2(0.43750000, 0.05468750), 272 real2(0.44140625, 0.55468750), 273 real2(0.44531250, 0.30468750), 274 real2(0.44921875, 0.80468750), 275 real2(0.45312500, 0.17968750), 276 real2(0.45703125, 0.67968750), 277 real2(0.46093750, 0.42968750), 278 real2(0.46484375, 0.92968750), 279 real2(0.46875000, 0.11718750), 280 real2(0.47265625, 0.61718750), 281 real2(0.47656250, 0.36718750), 282 real2(0.48046875, 0.86718750), 283 real2(0.48437500, 0.24218750), 284 real2(0.48828125, 0.74218750), 285 real2(0.49218750, 0.49218750), 286 real2(0.49609375, 0.99218750), 287 real2(0.50000000, 0.00390625), 288 real2(0.50390625, 0.50390625), 289 real2(0.50781250, 0.25390625), 290 real2(0.51171875, 0.75390625), 291 real2(0.51562500, 0.12890625), 292 real2(0.51953125, 0.62890625), 293 real2(0.52343750, 0.37890625), 294 real2(0.52734375, 0.87890625), 295 real2(0.53125000, 0.06640625), 296 real2(0.53515625, 0.56640625), 297 real2(0.53906250, 0.31640625), 298 real2(0.54296875, 0.81640625), 299 real2(0.54687500, 0.19140625), 300 real2(0.55078125, 0.69140625), 301 real2(0.55468750, 0.44140625), 302 real2(0.55859375, 0.94140625), 303 real2(0.56250000, 0.03515625), 304 real2(0.56640625, 0.53515625), 305 real2(0.57031250, 0.28515625), 306 real2(0.57421875, 0.78515625), 307 real2(0.57812500, 0.16015625), 308 real2(0.58203125, 0.66015625), 309 real2(0.58593750, 0.41015625), 310 real2(0.58984375, 0.91015625), 311 real2(0.59375000, 0.09765625), 312 real2(0.59765625, 0.59765625), 313 real2(0.60156250, 0.34765625), 314 real2(0.60546875, 0.84765625), 315 real2(0.60937500, 0.22265625), 316 real2(0.61328125, 0.72265625), 317 real2(0.61718750, 0.47265625), 318 real2(0.62109375, 0.97265625), 319 real2(0.62500000, 0.01953125), 320 real2(0.62890625, 0.51953125), 321 real2(0.63281250, 0.26953125), 322 real2(0.63671875, 0.76953125), 323 real2(0.64062500, 0.14453125), 324 real2(0.64453125, 0.64453125), 325 real2(0.64843750, 0.39453125), 326 real2(0.65234375, 0.89453125), 327 real2(0.65625000, 0.08203125), 328 real2(0.66015625, 0.58203125), 329 real2(0.66406250, 0.33203125), 330 real2(0.66796875, 0.83203125), 331 real2(0.67187500, 0.20703125), 332 real2(0.67578125, 0.70703125), 333 real2(0.67968750, 0.45703125), 334 real2(0.68359375, 0.95703125), 335 real2(0.68750000, 0.05078125), 336 real2(0.69140625, 0.55078125), 337 real2(0.69531250, 0.30078125), 338 real2(0.69921875, 0.80078125), 339 real2(0.70312500, 0.17578125), 340 real2(0.70703125, 0.67578125), 341 real2(0.71093750, 0.42578125), 342 real2(0.71484375, 0.92578125), 343 real2(0.71875000, 0.11328125), 344 real2(0.72265625, 0.61328125), 345 real2(0.72656250, 0.36328125), 346 real2(0.73046875, 0.86328125), 347 real2(0.73437500, 0.23828125), 348 real2(0.73828125, 0.73828125), 349 real2(0.74218750, 0.48828125), 350 real2(0.74609375, 0.98828125), 351 real2(0.75000000, 0.01171875), 352 real2(0.75390625, 0.51171875), 353 real2(0.75781250, 0.26171875), 354 real2(0.76171875, 0.76171875), 355 real2(0.76562500, 0.13671875), 356 real2(0.76953125, 0.63671875), 357 real2(0.77343750, 0.38671875), 358 real2(0.77734375, 0.88671875), 359 real2(0.78125000, 0.07421875), 360 real2(0.78515625, 0.57421875), 361 real2(0.78906250, 0.32421875), 362 real2(0.79296875, 0.82421875), 363 real2(0.79687500, 0.19921875), 364 real2(0.80078125, 0.69921875), 365 real2(0.80468750, 0.44921875), 366 real2(0.80859375, 0.94921875), 367 real2(0.81250000, 0.04296875), 368 real2(0.81640625, 0.54296875), 369 real2(0.82031250, 0.29296875), 370 real2(0.82421875, 0.79296875), 371 real2(0.82812500, 0.16796875), 372 real2(0.83203125, 0.66796875), 373 real2(0.83593750, 0.41796875), 374 real2(0.83984375, 0.91796875), 375 real2(0.84375000, 0.10546875), 376 real2(0.84765625, 0.60546875), 377 real2(0.85156250, 0.35546875), 378 real2(0.85546875, 0.85546875), 379 real2(0.85937500, 0.23046875), 380 real2(0.86328125, 0.73046875), 381 real2(0.86718750, 0.48046875), 382 real2(0.87109375, 0.98046875), 383 real2(0.87500000, 0.02734375), 384 real2(0.87890625, 0.52734375), 385 real2(0.88281250, 0.27734375), 386 real2(0.88671875, 0.77734375), 387 real2(0.89062500, 0.15234375), 388 real2(0.89453125, 0.65234375), 389 real2(0.89843750, 0.40234375), 390 real2(0.90234375, 0.90234375), 391 real2(0.90625000, 0.08984375), 392 real2(0.91015625, 0.58984375), 393 real2(0.91406250, 0.33984375), 394 real2(0.91796875, 0.83984375), 395 real2(0.92187500, 0.21484375), 396 real2(0.92578125, 0.71484375), 397 real2(0.92968750, 0.46484375), 398 real2(0.93359375, 0.96484375), 399 real2(0.93750000, 0.05859375), 400 real2(0.94140625, 0.55859375), 401 real2(0.94531250, 0.30859375), 402 real2(0.94921875, 0.80859375), 403 real2(0.95312500, 0.18359375), 404 real2(0.95703125, 0.68359375), 405 real2(0.96093750, 0.43359375), 406 real2(0.96484375, 0.93359375), 407 real2(0.96875000, 0.12109375), 408 real2(0.97265625, 0.62109375), 409 real2(0.97656250, 0.37109375), 410 real2(0.98046875, 0.87109375), 411 real2(0.98437500, 0.24609375), 412 real2(0.98828125, 0.74609375), 413 real2(0.99218750, 0.49609375), 414 real2(0.99609375, 0.99609375) 415}; 416 417#endif 418 419// Loads elements from one of the precomputed tables for sample counts of 16, 32, 64, 256. 420// Computes sample positions at runtime otherwise. 421real2 Hammersley2d(uint i, uint sampleCount) 422{ 423 switch (sampleCount) 424 { 425 #ifdef HAMMERSLEY_USE_CB 426 case 16: return hammersley2dSeq16[i].xy; 427 case 32: return hammersley2dSeq32[i].xy; 428 case 64: return hammersley2dSeq64[i].xy; 429 case 256: return hammersley2dSeq256[i].xy; 430 #else 431 case 16: return k_Hammersley2dSeq16[i]; 432 case 32: return k_Hammersley2dSeq32[i]; 433 case 64: return k_Hammersley2dSeq64[i]; 434 case 256: return k_Hammersley2dSeq256[i]; 435 #endif 436 default: return Hammersley2dSeq(i, sampleCount); 437 } 438} 439 440#if SHADER_API_MOBILE || SHADER_API_GLES3 || SHADER_API_SWITCH 441#pragma warning (enable : 3205) // conversion of larger type to smaller 442#endif 443 444#endif // UNITY_HAMMERSLEY_INCLUDED