| 1 | // This file is part of the FidelityFX SDK. |
| 2 | // |
| 3 | // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | // THE SOFTWARE. |
| 21 | |
| 22 | /// A define for a true value in a boolean expression. |
| 23 | /// |
| 24 | /// @ingroup GPU |
| 25 | #define FFX_TRUE (true) |
| 26 | |
| 27 | /// A define for a false value in a boolean expression. |
| 28 | /// |
| 29 | /// @ingroup GPU |
| 30 | #define FFX_FALSE (false) |
| 31 | |
| 32 | /// A define value for positive infinity. |
| 33 | /// |
| 34 | /// @ingroup GPU |
| 35 | #define FFX_POSITIVE_INFINITY_FLOAT ffxAsFloat(0x7f800000u) |
| 36 | |
| 37 | /// A define value for negative infinity. |
| 38 | /// |
| 39 | /// @ingroup GPU |
| 40 | #define FFX_NEGATIVE_INFINITY_FLOAT ffxAsFloat(0xff800000u) |
| 41 | |
| 42 | /// A define value for PI. |
| 43 | /// |
| 44 | /// @ingroup GPU |
| 45 | #define FFX_PI (3.14159) |
| 46 | |
| 47 | |
| 48 | /// Compute the reciprocal of <c><i>value</i></c>. |
| 49 | /// |
| 50 | /// @param [in] value The value to compute the reciprocal of. |
| 51 | /// |
| 52 | /// @returns |
| 53 | /// The 1 / <c><i>value</i></c>. |
| 54 | /// |
| 55 | /// @ingroup GPU |
| 56 | FfxFloat32 ffxReciprocal(FfxFloat32 value) |
| 57 | { |
| 58 | return rcp(value); |
| 59 | } |
| 60 | |
| 61 | /// Compute the reciprocal of <c><i>value</i></c>. |
| 62 | /// |
| 63 | /// @param [in] value The value to compute the reciprocal of. |
| 64 | /// |
| 65 | /// @returns |
| 66 | /// The 1 / <c><i>value</i></c>. |
| 67 | /// |
| 68 | /// @ingroup GPU |
| 69 | FfxFloat32x2 ffxReciprocal(FfxFloat32x2 value) |
| 70 | { |
| 71 | return rcp(value); |
| 72 | } |
| 73 | |
| 74 | /// Compute the reciprocal of <c><i>value</i></c>. |
| 75 | /// |
| 76 | /// @param [in] value The value to compute the reciprocal of. |
| 77 | /// |
| 78 | /// @returns |
| 79 | /// The 1 / <c><i>value</i></c>. |
| 80 | /// |
| 81 | /// @ingroup GPU |
| 82 | FfxFloat32x3 ffxReciprocal(FfxFloat32x3 value) |
| 83 | { |
| 84 | return rcp(value); |
| 85 | } |
| 86 | |
| 87 | /// Compute the reciprocal of <c><i>value</i></c>. |
| 88 | /// |
| 89 | /// @param [in] value The value to compute the reciprocal of. |
| 90 | /// |
| 91 | /// @returns |
| 92 | /// The 1 / <c><i>value</i></c>. |
| 93 | /// |
| 94 | /// @ingroup GPU |
| 95 | FfxFloat32x4 ffxReciprocal(FfxFloat32x4 value) |
| 96 | { |
| 97 | return rcp(value); |
| 98 | } |
| 99 | |
| 100 | /// Compute the min of two values. |
| 101 | /// |
| 102 | /// @param [in] x The first value to compute the min of. |
| 103 | /// @param [in] y The second value to compute the min of. |
| 104 | /// |
| 105 | /// @returns |
| 106 | /// The the lowest of two values. |
| 107 | /// |
| 108 | /// @ingroup GPU |
| 109 | FfxFloat32 ffxMin(FfxFloat32 x, FfxFloat32 y) |
| 110 | { |
| 111 | return min(x, y); |
| 112 | } |
| 113 | |
| 114 | /// Compute the min of two values. |
| 115 | /// |
| 116 | /// @param [in] x The first value to compute the min of. |
| 117 | /// @param [in] y The second value to compute the min of. |
| 118 | /// |
| 119 | /// @returns |
| 120 | /// The the lowest of two values. |
| 121 | /// |
| 122 | /// @ingroup GPU |
| 123 | FfxFloat32x2 ffxMin(FfxFloat32x2 x, FfxFloat32x2 y) |
| 124 | { |
| 125 | return min(x, y); |
| 126 | } |
| 127 | |
| 128 | /// Compute the min of two values. |
| 129 | /// |
| 130 | /// @param [in] x The first value to compute the min of. |
| 131 | /// @param [in] y The second value to compute the min of. |
| 132 | /// |
| 133 | /// @returns |
| 134 | /// The the lowest of two values. |
| 135 | /// |
| 136 | /// @ingroup GPU |
| 137 | FfxFloat32x3 ffxMin(FfxFloat32x3 x, FfxFloat32x3 y) |
| 138 | { |
| 139 | return min(x, y); |
| 140 | } |
| 141 | |
| 142 | /// Compute the min of two values. |
| 143 | /// |
| 144 | /// @param [in] x The first value to compute the min of. |
| 145 | /// @param [in] y The second value to compute the min of. |
| 146 | /// |
| 147 | /// @returns |
| 148 | /// The the lowest of two values. |
| 149 | /// |
| 150 | /// @ingroup GPU |
| 151 | FfxFloat32x4 ffxMin(FfxFloat32x4 x, FfxFloat32x4 y) |
| 152 | { |
| 153 | return min(x, y); |
| 154 | } |
| 155 | |
| 156 | /// Compute the min of two values. |
| 157 | /// |
| 158 | /// @param [in] x The first value to compute the min of. |
| 159 | /// @param [in] y The second value to compute the min of. |
| 160 | /// |
| 161 | /// @returns |
| 162 | /// The the lowest of two values. |
| 163 | /// |
| 164 | /// @ingroup GPU |
| 165 | FfxInt32 ffxMin(FfxInt32 x, FfxInt32 y) |
| 166 | { |
| 167 | return min(x, y); |
| 168 | } |
| 169 | |
| 170 | /// Compute the min of two values. |
| 171 | /// |
| 172 | /// @param [in] x The first value to compute the min of. |
| 173 | /// @param [in] y The second value to compute the min of. |
| 174 | /// |
| 175 | /// @returns |
| 176 | /// The the lowest of two values. |
| 177 | /// |
| 178 | /// @ingroup GPU |
| 179 | FfxInt32x2 ffxMin(FfxInt32x2 x, FfxInt32x2 y) |
| 180 | { |
| 181 | return min(x, y); |
| 182 | } |
| 183 | |
| 184 | /// Compute the min of two values. |
| 185 | /// |
| 186 | /// @param [in] x The first value to compute the min of. |
| 187 | /// @param [in] y The second value to compute the min of. |
| 188 | /// |
| 189 | /// @returns |
| 190 | /// The the lowest of two values. |
| 191 | /// |
| 192 | /// @ingroup GPU |
| 193 | FfxInt32x3 ffxMin(FfxInt32x3 x, FfxInt32x3 y) |
| 194 | { |
| 195 | return min(x, y); |
| 196 | } |
| 197 | |
| 198 | /// Compute the min of two values. |
| 199 | /// |
| 200 | /// @param [in] x The first value to compute the min of. |
| 201 | /// @param [in] y The second value to compute the min of. |
| 202 | /// |
| 203 | /// @returns |
| 204 | /// The the lowest of two values. |
| 205 | /// |
| 206 | /// @ingroup GPU |
| 207 | FfxInt32x4 ffxMin(FfxInt32x4 x, FfxInt32x4 y) |
| 208 | { |
| 209 | return min(x, y); |
| 210 | } |
| 211 | |
| 212 | /// Compute the min of two values. |
| 213 | /// |
| 214 | /// @param [in] x The first value to compute the min of. |
| 215 | /// @param [in] y The second value to compute the min of. |
| 216 | /// |
| 217 | /// @returns |
| 218 | /// The the lowest of two values. |
| 219 | /// |
| 220 | /// @ingroup GPU |
| 221 | FfxUInt32 ffxMin(FfxUInt32 x, FfxUInt32 y) |
| 222 | { |
| 223 | return min(x, y); |
| 224 | } |
| 225 | |
| 226 | /// Compute the min of two values. |
| 227 | /// |
| 228 | /// @param [in] x The first value to compute the min of. |
| 229 | /// @param [in] y The second value to compute the min of. |
| 230 | /// |
| 231 | /// @returns |
| 232 | /// The the lowest of two values. |
| 233 | /// |
| 234 | /// @ingroup GPU |
| 235 | FfxUInt32x2 ffxMin(FfxUInt32x2 x, FfxUInt32x2 y) |
| 236 | { |
| 237 | return min(x, y); |
| 238 | } |
| 239 | |
| 240 | /// Compute the min of two values. |
| 241 | /// |
| 242 | /// @param [in] x The first value to compute the min of. |
| 243 | /// @param [in] y The second value to compute the min of. |
| 244 | /// |
| 245 | /// @returns |
| 246 | /// The the lowest of two values. |
| 247 | /// |
| 248 | /// @ingroup GPU |
| 249 | FfxUInt32x3 ffxMin(FfxUInt32x3 x, FfxUInt32x3 y) |
| 250 | { |
| 251 | return min(x, y); |
| 252 | } |
| 253 | |
| 254 | /// Compute the min of two values. |
| 255 | /// |
| 256 | /// @param [in] x The first value to compute the min of. |
| 257 | /// @param [in] y The second value to compute the min of. |
| 258 | /// |
| 259 | /// @returns |
| 260 | /// The the lowest of two values. |
| 261 | /// |
| 262 | /// @ingroup GPU |
| 263 | FfxUInt32x4 ffxMin(FfxUInt32x4 x, FfxUInt32x4 y) |
| 264 | { |
| 265 | return min(x, y); |
| 266 | } |
| 267 | |
| 268 | /// Compute the max of two values. |
| 269 | /// |
| 270 | /// @param [in] x The first value to compute the max of. |
| 271 | /// @param [in] y The second value to compute the max of. |
| 272 | /// |
| 273 | /// @returns |
| 274 | /// The the lowest of two values. |
| 275 | /// |
| 276 | /// @ingroup GPU |
| 277 | FfxFloat32 ffxMax(FfxFloat32 x, FfxFloat32 y) |
| 278 | { |
| 279 | return max(x, y); |
| 280 | } |
| 281 | |
| 282 | /// Compute the max of two values. |
| 283 | /// |
| 284 | /// @param [in] x The first value to compute the max of. |
| 285 | /// @param [in] y The second value to compute the max of. |
| 286 | /// |
| 287 | /// @returns |
| 288 | /// The the lowest of two values. |
| 289 | /// |
| 290 | /// @ingroup GPU |
| 291 | FfxFloat32x2 ffxMax(FfxFloat32x2 x, FfxFloat32x2 y) |
| 292 | { |
| 293 | return max(x, y); |
| 294 | } |
| 295 | |
| 296 | /// Compute the max of two values. |
| 297 | /// |
| 298 | /// @param [in] x The first value to compute the max of. |
| 299 | /// @param [in] y The second value to compute the max of. |
| 300 | /// |
| 301 | /// @returns |
| 302 | /// The the lowest of two values. |
| 303 | /// |
| 304 | /// @ingroup GPU |
| 305 | FfxFloat32x3 ffxMax(FfxFloat32x3 x, FfxFloat32x3 y) |
| 306 | { |
| 307 | return max(x, y); |
| 308 | } |
| 309 | |
| 310 | /// Compute the max of two values. |
| 311 | /// |
| 312 | /// @param [in] x The first value to compute the max of. |
| 313 | /// @param [in] y The second value to compute the max of. |
| 314 | /// |
| 315 | /// @returns |
| 316 | /// The the lowest of two values. |
| 317 | /// |
| 318 | /// @ingroup GPU |
| 319 | FfxFloat32x4 ffxMax(FfxFloat32x4 x, FfxFloat32x4 y) |
| 320 | { |
| 321 | return max(x, y); |
| 322 | } |
| 323 | |
| 324 | /// Compute the max of two values. |
| 325 | /// |
| 326 | /// @param [in] x The first value to compute the max of. |
| 327 | /// @param [in] y The second value to compute the max of. |
| 328 | /// |
| 329 | /// @returns |
| 330 | /// The the lowest of two values. |
| 331 | /// |
| 332 | /// @ingroup GPU |
| 333 | FfxInt32 ffxMax(FfxInt32 x, FfxInt32 y) |
| 334 | { |
| 335 | return max(x, y); |
| 336 | } |
| 337 | |
| 338 | /// Compute the max of two values. |
| 339 | /// |
| 340 | /// @param [in] x The first value to compute the max of. |
| 341 | /// @param [in] y The second value to compute the max of. |
| 342 | /// |
| 343 | /// @returns |
| 344 | /// The the lowest of two values. |
| 345 | /// |
| 346 | /// @ingroup GPU |
| 347 | FfxInt32x2 ffxMax(FfxInt32x2 x, FfxInt32x2 y) |
| 348 | { |
| 349 | return max(x, y); |
| 350 | } |
| 351 | |
| 352 | /// Compute the max of two values. |
| 353 | /// |
| 354 | /// @param [in] x The first value to compute the max of. |
| 355 | /// @param [in] y The second value to compute the max of. |
| 356 | /// |
| 357 | /// @returns |
| 358 | /// The the lowest of two values. |
| 359 | /// |
| 360 | /// @ingroup GPU |
| 361 | FfxInt32x3 ffxMax(FfxInt32x3 x, FfxInt32x3 y) |
| 362 | { |
| 363 | return max(x, y); |
| 364 | } |
| 365 | |
| 366 | /// Compute the max of two values. |
| 367 | /// |
| 368 | /// @param [in] x The first value to compute the max of. |
| 369 | /// @param [in] y The second value to compute the max of. |
| 370 | /// |
| 371 | /// @returns |
| 372 | /// The the lowest of two values. |
| 373 | /// |
| 374 | /// @ingroup GPU |
| 375 | FfxInt32x4 ffxMax(FfxInt32x4 x, FfxInt32x4 y) |
| 376 | { |
| 377 | return max(x, y); |
| 378 | } |
| 379 | |
| 380 | /// Compute the max of two values. |
| 381 | /// |
| 382 | /// @param [in] x The first value to compute the max of. |
| 383 | /// @param [in] y The second value to compute the max of. |
| 384 | /// |
| 385 | /// @returns |
| 386 | /// The the lowest of two values. |
| 387 | /// |
| 388 | /// @ingroup GPU |
| 389 | FfxUInt32 ffxMax(FfxUInt32 x, FfxUInt32 y) |
| 390 | { |
| 391 | return max(x, y); |
| 392 | } |
| 393 | |
| 394 | /// Compute the max of two values. |
| 395 | /// |
| 396 | /// @param [in] x The first value to compute the max of. |
| 397 | /// @param [in] y The second value to compute the max of. |
| 398 | /// |
| 399 | /// @returns |
| 400 | /// The the lowest of two values. |
| 401 | /// |
| 402 | /// @ingroup GPU |
| 403 | FfxUInt32x2 ffxMax(FfxUInt32x2 x, FfxUInt32x2 y) |
| 404 | { |
| 405 | return max(x, y); |
| 406 | } |
| 407 | |
| 408 | /// Compute the max of two values. |
| 409 | /// |
| 410 | /// @param [in] x The first value to compute the max of. |
| 411 | /// @param [in] y The second value to compute the max of. |
| 412 | /// |
| 413 | /// @returns |
| 414 | /// The the lowest of two values. |
| 415 | /// |
| 416 | /// @ingroup GPU |
| 417 | FfxUInt32x3 ffxMax(FfxUInt32x3 x, FfxUInt32x3 y) |
| 418 | { |
| 419 | return max(x, y); |
| 420 | } |
| 421 | |
| 422 | /// Compute the max of two values. |
| 423 | /// |
| 424 | /// @param [in] x The first value to compute the max of. |
| 425 | /// @param [in] y The second value to compute the max of. |
| 426 | /// |
| 427 | /// @returns |
| 428 | /// The the lowest of two values. |
| 429 | /// |
| 430 | /// @ingroup GPU |
| 431 | FfxUInt32x4 ffxMax(FfxUInt32x4 x, FfxUInt32x4 y) |
| 432 | { |
| 433 | return max(x, y); |
| 434 | } |
| 435 | |
| 436 | /// Compute the value of the first parameter raised to the power of the second. |
| 437 | /// |
| 438 | /// @param [in] x The value to raise to the power y. |
| 439 | /// @param [in] y The power to which to raise x. |
| 440 | /// |
| 441 | /// @returns |
| 442 | /// The value of the first parameter raised to the power of the second. |
| 443 | /// |
| 444 | /// @ingroup GPU |
| 445 | FfxFloat32 ffxPow(FfxFloat32 x, FfxFloat32 y) |
| 446 | { |
| 447 | return pow(x, y); |
| 448 | } |
| 449 | |
| 450 | /// Compute the value of the first parameter raised to the power of the second. |
| 451 | /// |
| 452 | /// @param [in] x The value to raise to the power y. |
| 453 | /// @param [in] y The power to which to raise x. |
| 454 | /// |
| 455 | /// @returns |
| 456 | /// The value of the first parameter raised to the power of the second. |
| 457 | /// |
| 458 | /// @ingroup GPU |
| 459 | FfxFloat32x2 ffxPow(FfxFloat32x2 x, FfxFloat32x2 y) |
| 460 | { |
| 461 | return pow(x, y); |
| 462 | } |
| 463 | |
| 464 | /// Compute the value of the first parameter raised to the power of the second. |
| 465 | /// |
| 466 | /// @param [in] x The value to raise to the power y. |
| 467 | /// @param [in] y The power to which to raise x. |
| 468 | /// |
| 469 | /// @returns |
| 470 | /// The value of the first parameter raised to the power of the second. |
| 471 | /// |
| 472 | /// @ingroup GPU |
| 473 | FfxFloat32x3 ffxPow(FfxFloat32x3 x, FfxFloat32x3 y) |
| 474 | { |
| 475 | return pow(x, y); |
| 476 | } |
| 477 | |
| 478 | /// Compute the value of the first parameter raised to the power of the second. |
| 479 | /// |
| 480 | /// @param [in] x The value to raise to the power y. |
| 481 | /// @param [in] y The power to which to raise x. |
| 482 | /// |
| 483 | /// @returns |
| 484 | /// The value of the first parameter raised to the power of the second. |
| 485 | /// |
| 486 | /// @ingroup GPU |
| 487 | FfxFloat32x4 ffxPow(FfxFloat32x4 x, FfxFloat32x4 y) |
| 488 | { |
| 489 | return pow(x, y); |
| 490 | } |
| 491 | |
| 492 | /// Compute the square root of a value. |
| 493 | /// |
| 494 | /// @param [in] x The first value to compute the min of. |
| 495 | /// |
| 496 | /// @returns |
| 497 | /// The the square root of <c><i>x</i></c>. |
| 498 | /// |
| 499 | /// @ingroup GPU |
| 500 | FfxFloat32 ffxSqrt(FfxFloat32 x) |
| 501 | { |
| 502 | return sqrt(x); |
| 503 | } |
| 504 | |
| 505 | /// Compute the square root of a value. |
| 506 | /// |
| 507 | /// @param [in] x The first value to compute the min of. |
| 508 | /// |
| 509 | /// @returns |
| 510 | /// The the square root of <c><i>x</i></c>. |
| 511 | /// |
| 512 | /// @ingroup GPU |
| 513 | FfxFloat32x2 ffxSqrt(FfxFloat32x2 x) |
| 514 | { |
| 515 | return sqrt(x); |
| 516 | } |
| 517 | |
| 518 | /// Compute the square root of a value. |
| 519 | /// |
| 520 | /// @param [in] x The first value to compute the min of. |
| 521 | /// |
| 522 | /// @returns |
| 523 | /// The the square root of <c><i>x</i></c>. |
| 524 | /// |
| 525 | /// @ingroup GPU |
| 526 | FfxFloat32x3 ffxSqrt(FfxFloat32x3 x) |
| 527 | { |
| 528 | return sqrt(x); |
| 529 | } |
| 530 | |
| 531 | /// Compute the square root of a value. |
| 532 | /// |
| 533 | /// @param [in] x The first value to compute the min of. |
| 534 | /// |
| 535 | /// @returns |
| 536 | /// The the square root of <c><i>x</i></c>. |
| 537 | /// |
| 538 | /// @ingroup GPU |
| 539 | FfxFloat32x4 ffxSqrt(FfxFloat32x4 x) |
| 540 | { |
| 541 | return sqrt(x); |
| 542 | } |
| 543 | |
| 544 | /// Copy the sign bit from 's' to positive 'd'. |
| 545 | /// |
| 546 | /// @param [in] d The value to copy the sign bit into. |
| 547 | /// @param [in] s The value to copy the sign bit from. |
| 548 | /// |
| 549 | /// @returns |
| 550 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 551 | /// |
| 552 | /// @ingroup GPU |
| 553 | FfxFloat32 ffxCopySignBit(FfxFloat32 d, FfxFloat32 s) |
| 554 | { |
| 555 | return ffxAsFloat(ffxAsUInt32(d) | (ffxAsUInt32(s) & FfxUInt32(0x80000000u))); |
| 556 | } |
| 557 | |
| 558 | /// Copy the sign bit from 's' to positive 'd'. |
| 559 | /// |
| 560 | /// @param [in] d The value to copy the sign bit into. |
| 561 | /// @param [in] s The value to copy the sign bit from. |
| 562 | /// |
| 563 | /// @returns |
| 564 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 565 | /// |
| 566 | /// @ingroup GPU |
| 567 | FfxFloat32x2 ffxCopySignBit(FfxFloat32x2 d, FfxFloat32x2 s) |
| 568 | { |
| 569 | return ffxAsFloat(ffxAsUInt32(d) | (ffxAsUInt32(s) & ffxBroadcast2(0x80000000u))); |
| 570 | } |
| 571 | |
| 572 | /// Copy the sign bit from 's' to positive 'd'. |
| 573 | /// |
| 574 | /// @param [in] d The value to copy the sign bit into. |
| 575 | /// @param [in] s The value to copy the sign bit from. |
| 576 | /// |
| 577 | /// @returns |
| 578 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 579 | /// |
| 580 | /// @ingroup GPU |
| 581 | FfxFloat32x3 ffxCopySignBit(FfxFloat32x3 d, FfxFloat32x3 s) |
| 582 | { |
| 583 | return ffxAsFloat(ffxAsUInt32(d) | (ffxAsUInt32(s) & ffxBroadcast3(0x80000000u))); |
| 584 | } |
| 585 | |
| 586 | /// Copy the sign bit from 's' to positive 'd'. |
| 587 | /// |
| 588 | /// @param [in] d The value to copy the sign bit into. |
| 589 | /// @param [in] s The value to copy the sign bit from. |
| 590 | /// |
| 591 | /// @returns |
| 592 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 593 | /// |
| 594 | /// @ingroup GPU |
| 595 | FfxFloat32x4 ffxCopySignBit(FfxFloat32x4 d, FfxFloat32x4 s) |
| 596 | { |
| 597 | return ffxAsFloat(ffxAsUInt32(d) | (ffxAsUInt32(s) & ffxBroadcast4(0x80000000u))); |
| 598 | } |
| 599 | |
| 600 | /// A single operation to return the following: |
| 601 | /// m = NaN := 0 |
| 602 | /// m >= 0 := 0 |
| 603 | /// m < 0 := 1 |
| 604 | /// |
| 605 | /// Uses the following useful floating point logic, |
| 606 | /// saturate(+a*(-INF)==-INF) := 0 |
| 607 | /// saturate( 0*(-INF)== NaN) := 0 |
| 608 | /// saturate(-a*(-INF)==+INF) := 1 |
| 609 | /// |
| 610 | /// This function is useful when creating masks for branch-free logic. |
| 611 | /// |
| 612 | /// @param [in] m The value to test against 0. |
| 613 | /// |
| 614 | /// @returns |
| 615 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 616 | /// |
| 617 | /// @ingroup GPU |
| 618 | FfxFloat32 ffxIsSigned(FfxFloat32 m) |
| 619 | { |
| 620 | return ffxSaturate(m * FfxFloat32(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 621 | } |
| 622 | |
| 623 | /// A single operation to return the following: |
| 624 | /// m = NaN := 0 |
| 625 | /// m >= 0 := 0 |
| 626 | /// m < 0 := 1 |
| 627 | /// |
| 628 | /// Uses the following useful floating point logic, |
| 629 | /// saturate(+a*(-INF)==-INF) := 0 |
| 630 | /// saturate( 0*(-INF)== NaN) := 0 |
| 631 | /// saturate(-a*(-INF)==+INF) := 1 |
| 632 | /// |
| 633 | /// This function is useful when creating masks for branch-free logic. |
| 634 | /// |
| 635 | /// @param [in] m The value to test against 0. |
| 636 | /// |
| 637 | /// @returns |
| 638 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 639 | /// |
| 640 | /// @ingroup GPU |
| 641 | FfxFloat32x2 ffxIsSigned(FfxFloat32x2 m) |
| 642 | { |
| 643 | return ffxSaturate(m * ffxBroadcast2(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 644 | } |
| 645 | |
| 646 | /// A single operation to return the following: |
| 647 | /// m = NaN := 0 |
| 648 | /// m >= 0 := 0 |
| 649 | /// m < 0 := 1 |
| 650 | /// |
| 651 | /// Uses the following useful floating point logic, |
| 652 | /// saturate(+a*(-INF)==-INF) := 0 |
| 653 | /// saturate( 0*(-INF)== NaN) := 0 |
| 654 | /// saturate(-a*(-INF)==+INF) := 1 |
| 655 | /// |
| 656 | /// This function is useful when creating masks for branch-free logic. |
| 657 | /// |
| 658 | /// @param [in] m The value to test against 0. |
| 659 | /// |
| 660 | /// @returns |
| 661 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 662 | /// |
| 663 | /// @ingroup GPU |
| 664 | FfxFloat32x3 ffxIsSigned(FfxFloat32x3 m) |
| 665 | { |
| 666 | return ffxSaturate(m * ffxBroadcast3(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 667 | } |
| 668 | |
| 669 | /// A single operation to return the following: |
| 670 | /// m = NaN := 0 |
| 671 | /// m >= 0 := 0 |
| 672 | /// m < 0 := 1 |
| 673 | /// |
| 674 | /// Uses the following useful floating point logic, |
| 675 | /// saturate(+a*(-INF)==-INF) := 0 |
| 676 | /// saturate( 0*(-INF)== NaN) := 0 |
| 677 | /// saturate(-a*(-INF)==+INF) := 1 |
| 678 | /// |
| 679 | /// This function is useful when creating masks for branch-free logic. |
| 680 | /// |
| 681 | /// @param [in] m The value to test against for have the sign set. |
| 682 | /// |
| 683 | /// @returns |
| 684 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or positive. |
| 685 | /// |
| 686 | /// @ingroup GPU |
| 687 | FfxFloat32x4 ffxIsSigned(FfxFloat32x4 m) |
| 688 | { |
| 689 | return ffxSaturate(m * ffxBroadcast4(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 690 | } |
| 691 | |
| 692 | /// A single operation to return the following: |
| 693 | /// m = NaN := 1 |
| 694 | /// m > 0 := 0 |
| 695 | /// m <= 0 := 1 |
| 696 | /// |
| 697 | /// This function is useful when creating masks for branch-free logic. |
| 698 | /// |
| 699 | /// @param [in] m The value to test against zero. |
| 700 | /// |
| 701 | /// @returns |
| 702 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 703 | /// |
| 704 | /// @ingroup GPU |
| 705 | FfxFloat32 ffxIsGreaterThanZero(FfxFloat32 m) |
| 706 | { |
| 707 | return ffxSaturate(m * FfxFloat32(FFX_POSITIVE_INFINITY_FLOAT)); |
| 708 | } |
| 709 | |
| 710 | /// A single operation to return the following: |
| 711 | /// m = NaN := 1 |
| 712 | /// m > 0 := 0 |
| 713 | /// m <= 0 := 1 |
| 714 | /// |
| 715 | /// This function is useful when creating masks for branch-free logic. |
| 716 | /// |
| 717 | /// @param [in] m The value to test against zero. |
| 718 | /// |
| 719 | /// @returns |
| 720 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 721 | /// |
| 722 | /// @ingroup GPU |
| 723 | FfxFloat32x2 ffxIsGreaterThanZero(FfxFloat32x2 m) |
| 724 | { |
| 725 | return ffxSaturate(m * ffxBroadcast2(FFX_POSITIVE_INFINITY_FLOAT)); |
| 726 | } |
| 727 | |
| 728 | /// A single operation to return the following: |
| 729 | /// m = NaN := 1 |
| 730 | /// m > 0 := 0 |
| 731 | /// m <= 0 := 1 |
| 732 | /// |
| 733 | /// This function is useful when creating masks for branch-free logic. |
| 734 | /// |
| 735 | /// @param [in] m The value to test against zero. |
| 736 | /// |
| 737 | /// @returns |
| 738 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 739 | /// |
| 740 | /// @ingroup GPU |
| 741 | FfxFloat32x3 ffxIsGreaterThanZero(FfxFloat32x3 m) |
| 742 | { |
| 743 | return ffxSaturate(m * ffxBroadcast3(FFX_POSITIVE_INFINITY_FLOAT)); |
| 744 | } |
| 745 | |
| 746 | /// A single operation to return the following: |
| 747 | /// m = NaN := 1 |
| 748 | /// m > 0 := 0 |
| 749 | /// m <= 0 := 1 |
| 750 | /// |
| 751 | /// This function is useful when creating masks for branch-free logic. |
| 752 | /// |
| 753 | /// @param [in] m The value to test against zero. |
| 754 | /// |
| 755 | /// @returns |
| 756 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 757 | /// |
| 758 | /// @ingroup GPU |
| 759 | FfxFloat32x4 ffxIsGreaterThanZero(FfxFloat32x4 m) |
| 760 | { |
| 761 | return ffxSaturate(m * ffxBroadcast4(FFX_POSITIVE_INFINITY_FLOAT)); |
| 762 | } |
| 763 | |
| 764 | /// Convert a 32bit floating point value to sortable integer. |
| 765 | /// |
| 766 | /// - If sign bit=0, flip the sign bit (positives). |
| 767 | /// - If sign bit=1, flip all bits (negatives). |
| 768 | /// |
| 769 | /// The function has the side effects that: |
| 770 | /// - Larger integers are more positive values. |
| 771 | /// - Float zero is mapped to center of integers (so clear to integer zero is a nice default for atomic max usage). |
| 772 | /// |
| 773 | /// @param [in] value The floating point value to make sortable. |
| 774 | /// |
| 775 | /// @returns |
| 776 | /// The sortable integer value. |
| 777 | /// |
| 778 | /// @ingroup GPU |
| 779 | FfxUInt32 ffxFloatToSortableInteger(FfxUInt32 value) |
| 780 | { |
| 781 | return value ^ ((AShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000)); |
| 782 | } |
| 783 | |
| 784 | /// Convert a sortable integer to a 32bit floating point value. |
| 785 | /// |
| 786 | /// The function has the side effects that: |
| 787 | /// - If sign bit=1, flip the sign bit (positives). |
| 788 | /// - If sign bit=0, flip all bits (negatives). |
| 789 | /// |
| 790 | /// @param [in] value The floating point value to make sortable. |
| 791 | /// |
| 792 | /// @returns |
| 793 | /// The sortable integer value. |
| 794 | /// |
| 795 | /// @ingroup GPU |
| 796 | FfxUInt32 ffxSortableIntegerToFloat(FfxUInt32 value) |
| 797 | { |
| 798 | return value ^ ((~AShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000)); |
| 799 | } |
| 800 | |
| 801 | /// Calculate a low-quality approximation for the square root of a value. |
| 802 | /// |
| 803 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 804 | /// presentation materials: |
| 805 | /// |
| 806 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 807 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 808 | /// |
| 809 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 810 | /// |
| 811 | /// @returns |
| 812 | /// An approximation of the square root, estimated to low quality. |
| 813 | /// |
| 814 | /// @ingroup GPU |
| 815 | FfxFloat32 ffxApproximateSqrt(FfxFloat32 a) |
| 816 | { |
| 817 | return ffxAsFloat((ffxAsUInt32(a) >> FfxUInt32(1)) + FfxUInt32(0x1fbc4639)); |
| 818 | } |
| 819 | |
| 820 | /// Calculate a low-quality approximation for the reciprocal of a value. |
| 821 | /// |
| 822 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 823 | /// presentation materials: |
| 824 | /// |
| 825 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 826 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 827 | /// |
| 828 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 829 | /// |
| 830 | /// @returns |
| 831 | /// An approximation of the reciprocal, estimated to low quality. |
| 832 | /// |
| 833 | /// @ingroup GPU |
| 834 | FfxFloat32 ffxApproximateReciprocal(FfxFloat32 a) |
| 835 | { |
| 836 | return ffxAsFloat(FfxUInt32(0x7ef07ebb) - ffxAsUInt32(a)); |
| 837 | } |
| 838 | |
| 839 | /// Calculate a medium-quality approximation for the reciprocal of a value. |
| 840 | /// |
| 841 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 842 | /// presentation materials: |
| 843 | /// |
| 844 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 845 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 846 | /// |
| 847 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 848 | /// |
| 849 | /// @returns |
| 850 | /// An approximation of the reciprocal, estimated to medium quality. |
| 851 | /// |
| 852 | /// @ingroup GPU |
| 853 | FfxFloat32 ffxApproximateReciprocalMedium(FfxFloat32 value) |
| 854 | { |
| 855 | FfxFloat32 b = ffxAsFloat(FfxUInt32(0x7ef19fff) - ffxAsUInt32(value)); |
| 856 | return b * (-b * value + FfxFloat32(2.0)); |
| 857 | } |
| 858 | |
| 859 | /// Calculate a low-quality approximation for the reciprocal of a value. |
| 860 | /// |
| 861 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 862 | /// presentation materials: |
| 863 | /// |
| 864 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 865 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 866 | /// |
| 867 | /// @param [in] value The value to calculate an approximate to the reciprocal square root for. |
| 868 | /// |
| 869 | /// @returns |
| 870 | /// An approximation of the reciprocal square root, estimated to low quality. |
| 871 | /// |
| 872 | /// @ingroup GPU |
| 873 | FfxFloat32 ffxApproximateReciprocalSquareRoot(FfxFloat32 a) |
| 874 | { |
| 875 | return ffxAsFloat(FfxUInt32(0x5f347d74) - (ffxAsUInt32(a) >> FfxUInt32(1))); |
| 876 | } |
| 877 | |
| 878 | /// Calculate a low-quality approximation for the square root of a value. |
| 879 | /// |
| 880 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 881 | /// presentation materials: |
| 882 | /// |
| 883 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 884 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 885 | /// |
| 886 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 887 | /// |
| 888 | /// @returns |
| 889 | /// An approximation of the square root, estimated to low quality. |
| 890 | /// |
| 891 | /// @ingroup GPU |
| 892 | FfxFloat32x2 ffxApproximateSqrt(FfxFloat32x2 a) |
| 893 | { |
| 894 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast2(1u)) + ffxBroadcast2(0x1fbc4639u)); |
| 895 | } |
| 896 | |
| 897 | /// Calculate a low-quality approximation for the reciprocal of a value. |
| 898 | /// |
| 899 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 900 | /// presentation materials: |
| 901 | /// |
| 902 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 903 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 904 | /// |
| 905 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 906 | /// |
| 907 | /// @returns |
| 908 | /// An approximation of the reciprocal, estimated to low quality. |
| 909 | /// |
| 910 | /// @ingroup GPU |
| 911 | FfxFloat32x2 ffxApproximateReciprocal(FfxFloat32x2 a) |
| 912 | { |
| 913 | return ffxAsFloat(ffxBroadcast2(0x7ef07ebbu) - ffxAsUInt32(a)); |
| 914 | } |
| 915 | |
| 916 | /// Calculate a medium-quality approximation for the reciprocal of a value. |
| 917 | /// |
| 918 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 919 | /// presentation materials: |
| 920 | /// |
| 921 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 922 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 923 | /// |
| 924 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 925 | /// |
| 926 | /// @returns |
| 927 | /// An approximation of the reciprocal, estimated to medium quality. |
| 928 | /// |
| 929 | /// @ingroup GPU |
| 930 | FfxFloat32x2 ffxApproximateReciprocalMedium(FfxFloat32x2 a) |
| 931 | { |
| 932 | FfxFloat32x2 b = ffxAsFloat(ffxBroadcast2(0x7ef19fffu) - ffxAsUInt32(a)); |
| 933 | return b * (-b * a + ffxBroadcast2(2.0f)); |
| 934 | } |
| 935 | |
| 936 | /// Calculate a low-quality approximation for the square root of a value. |
| 937 | /// |
| 938 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 939 | /// presentation materials: |
| 940 | /// |
| 941 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 942 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 943 | /// |
| 944 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 945 | /// |
| 946 | /// @returns |
| 947 | /// An approximation of the square root, estimated to low quality. |
| 948 | /// |
| 949 | /// @ingroup GPU |
| 950 | FfxFloat32x2 ffxApproximateReciprocalSquareRoot(FfxFloat32x2 a) |
| 951 | { |
| 952 | return ffxAsFloat(ffxBroadcast2(0x5f347d74u) - (ffxAsUInt32(a) >> ffxBroadcast2(1u))); |
| 953 | } |
| 954 | |
| 955 | /// Calculate a low-quality approximation for the square root of a value. |
| 956 | /// |
| 957 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 958 | /// presentation materials: |
| 959 | /// |
| 960 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 961 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 962 | /// |
| 963 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 964 | /// |
| 965 | /// @returns |
| 966 | /// An approximation of the square root, estimated to low quality. |
| 967 | /// |
| 968 | /// @ingroup GPU |
| 969 | FfxFloat32x3 ffxApproximateSqrt(FfxFloat32x3 a) |
| 970 | { |
| 971 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast3(1u)) + ffxBroadcast3(0x1fbc4639u)); |
| 972 | } |
| 973 | |
| 974 | /// Calculate a low-quality approximation for the reciprocal of a value. |
| 975 | /// |
| 976 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 977 | /// presentation materials: |
| 978 | /// |
| 979 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 980 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 981 | /// |
| 982 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 983 | /// |
| 984 | /// @returns |
| 985 | /// An approximation of the reciprocal, estimated to low quality. |
| 986 | /// |
| 987 | /// @ingroup GPU |
| 988 | FfxFloat32x3 ffxApproximateReciprocal(FfxFloat32x3 a) |
| 989 | { |
| 990 | return ffxAsFloat(ffxBroadcast3(0x7ef07ebbu) - ffxAsUInt32(a)); |
| 991 | } |
| 992 | |
| 993 | /// Calculate a medium-quality approximation for the reciprocal of a value. |
| 994 | /// |
| 995 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 996 | /// presentation materials: |
| 997 | /// |
| 998 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 999 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1000 | /// |
| 1001 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 1002 | /// |
| 1003 | /// @returns |
| 1004 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1005 | /// |
| 1006 | /// @ingroup GPU |
| 1007 | FfxFloat32x3 ffxApproximateReciprocalMedium(FfxFloat32x3 a) |
| 1008 | { |
| 1009 | FfxFloat32x3 b = ffxAsFloat(ffxBroadcast3(0x7ef19fffu) - ffxAsUInt32(a)); |
| 1010 | return b * (-b * a + ffxBroadcast3(2.0f)); |
| 1011 | } |
| 1012 | |
| 1013 | /// Calculate a low-quality approximation for the square root of a value. |
| 1014 | /// |
| 1015 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1016 | /// presentation materials: |
| 1017 | /// |
| 1018 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1019 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1020 | /// |
| 1021 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 1022 | /// |
| 1023 | /// @returns |
| 1024 | /// An approximation of the square root, estimated to low quality. |
| 1025 | /// |
| 1026 | /// @ingroup GPU |
| 1027 | FfxFloat32x3 ffxApproximateReciprocalSquareRoot(FfxFloat32x3 a) |
| 1028 | { |
| 1029 | return ffxAsFloat(ffxBroadcast3(0x5f347d74u) - (ffxAsUInt32(a) >> ffxBroadcast3(1u))); |
| 1030 | } |
| 1031 | |
| 1032 | /// Calculate a low-quality approximation for the square root of a value. |
| 1033 | /// |
| 1034 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1035 | /// presentation materials: |
| 1036 | /// |
| 1037 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1038 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1039 | /// |
| 1040 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 1041 | /// |
| 1042 | /// @returns |
| 1043 | /// An approximation of the square root, estimated to low quality. |
| 1044 | /// |
| 1045 | /// @ingroup GPU |
| 1046 | FfxFloat32x4 ffxApproximateSqrt(FfxFloat32x4 a) |
| 1047 | { |
| 1048 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast4(1u)) + ffxBroadcast4(0x1fbc4639u)); |
| 1049 | } |
| 1050 | |
| 1051 | /// Calculate a low-quality approximation for the reciprocal of a value. |
| 1052 | /// |
| 1053 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1054 | /// presentation materials: |
| 1055 | /// |
| 1056 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1057 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1058 | /// |
| 1059 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 1060 | /// |
| 1061 | /// @returns |
| 1062 | /// An approximation of the reciprocal, estimated to low quality. |
| 1063 | /// |
| 1064 | /// @ingroup GPU |
| 1065 | FfxFloat32x4 ffxApproximateReciprocal(FfxFloat32x4 a) |
| 1066 | { |
| 1067 | return ffxAsFloat(ffxBroadcast4(0x7ef07ebbu) - ffxAsUInt32(a)); |
| 1068 | } |
| 1069 | |
| 1070 | /// Calculate a medium-quality approximation for the reciprocal of a value. |
| 1071 | /// |
| 1072 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1073 | /// presentation materials: |
| 1074 | /// |
| 1075 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1076 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1077 | /// |
| 1078 | /// @param [in] value The value to calculate an approximate to the reciprocal for. |
| 1079 | /// |
| 1080 | /// @returns |
| 1081 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1082 | /// |
| 1083 | /// @ingroup GPU |
| 1084 | FfxFloat32x4 ffxApproximateReciprocalMedium(FfxFloat32x4 a) |
| 1085 | { |
| 1086 | FfxFloat32x4 b = ffxAsFloat(ffxBroadcast4(0x7ef19fffu) - ffxAsUInt32(a)); |
| 1087 | return b * (-b * a + ffxBroadcast4(2.0f)); |
| 1088 | } |
| 1089 | |
| 1090 | /// Calculate a low-quality approximation for the square root of a value. |
| 1091 | /// |
| 1092 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1093 | /// presentation materials: |
| 1094 | /// |
| 1095 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1096 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1097 | /// |
| 1098 | /// @param [in] value The value to calculate an approximate to the square root for. |
| 1099 | /// |
| 1100 | /// @returns |
| 1101 | /// An approximation of the square root, estimated to low quality. |
| 1102 | /// |
| 1103 | /// @ingroup GPU |
| 1104 | FfxFloat32x4 ffxApproximateReciprocalSquareRoot(FfxFloat32x4 a) |
| 1105 | { |
| 1106 | return ffxAsFloat(ffxBroadcast4(0x5f347d74u) - (ffxAsUInt32(a) >> ffxBroadcast4(1u))); |
| 1107 | } |
| 1108 | |
| 1109 | /// Calculate dot product of 'a' and 'b'. |
| 1110 | /// |
| 1111 | /// @param [in] a First vector input. |
| 1112 | /// @param [in] b Second vector input. |
| 1113 | /// |
| 1114 | /// @returns |
| 1115 | /// The value of <c><i>a</i></c> dot <c><i>b</i></c>. |
| 1116 | /// |
| 1117 | /// @ingroup GPU |
| 1118 | FfxFloat32 ffxDot2(FfxFloat32x2 a, FfxFloat32x2 b) |
| 1119 | { |
| 1120 | return dot(a, b); |
| 1121 | } |
| 1122 | |
| 1123 | /// Calculate dot product of 'a' and 'b'. |
| 1124 | /// |
| 1125 | /// @param [in] a First vector input. |
| 1126 | /// @param [in] b Second vector input. |
| 1127 | /// |
| 1128 | /// @returns |
| 1129 | /// The value of <c><i>a</i></c> dot <c><i>b</i></c>. |
| 1130 | /// |
| 1131 | /// @ingroup GPU |
| 1132 | FfxFloat32 ffxDot3(FfxFloat32x3 a, FfxFloat32x3 b) |
| 1133 | { |
| 1134 | return dot(a, b); |
| 1135 | } |
| 1136 | |
| 1137 | /// Calculate dot product of 'a' and 'b'. |
| 1138 | /// |
| 1139 | /// @param [in] a First vector input. |
| 1140 | /// @param [in] b Second vector input. |
| 1141 | /// |
| 1142 | /// @returns |
| 1143 | /// The value of <c><i>a</i></c> dot <c><i>b</i></c>. |
| 1144 | /// |
| 1145 | /// @ingroup GPU |
| 1146 | FfxFloat32 ffxDot4(FfxFloat32x4 a, FfxFloat32x4 b) |
| 1147 | { |
| 1148 | return dot(a, b); |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | /// Compute an approximate conversion from PQ to Gamma2 space. |
| 1153 | /// |
| 1154 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1155 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1156 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1157 | /// |
| 1158 | /// @param a The value to convert between PQ and Gamma2. |
| 1159 | /// |
| 1160 | /// @returns |
| 1161 | /// The value <c><i>a</i></c> converted into Gamma2. |
| 1162 | /// |
| 1163 | /// @ingroup GPU |
| 1164 | FfxFloat32 ffxApproximatePQToGamma2Medium(FfxFloat32 a) |
| 1165 | { |
| 1166 | return a * a * a * a; |
| 1167 | } |
| 1168 | |
| 1169 | /// Compute an approximate conversion from PQ to linear space. |
| 1170 | /// |
| 1171 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1172 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1173 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1174 | /// |
| 1175 | /// @param a The value to convert between PQ and linear. |
| 1176 | /// |
| 1177 | /// @returns |
| 1178 | /// The value <c><i>a</i></c> converted into linear. |
| 1179 | /// |
| 1180 | /// @ingroup GPU |
| 1181 | FfxFloat32 ffxApproximatePQToLinear(FfxFloat32 a) |
| 1182 | { |
| 1183 | return a * a * a * a * a * a * a * a; |
| 1184 | } |
| 1185 | |
| 1186 | /// Compute an approximate conversion from gamma2 to PQ space. |
| 1187 | /// |
| 1188 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1189 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1190 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1191 | /// |
| 1192 | /// @param a The value to convert between gamma2 and PQ. |
| 1193 | /// |
| 1194 | /// @returns |
| 1195 | /// The value <c><i>a</i></c> converted into PQ. |
| 1196 | /// |
| 1197 | /// @ingroup GPU |
| 1198 | FfxFloat32 ffxApproximateGamma2ToPQ(FfxFloat32 a) |
| 1199 | { |
| 1200 | return ffxAsFloat((ffxAsUInt32(a) >> FfxUInt32(2)) + FfxUInt32(0x2F9A4E46)); |
| 1201 | } |
| 1202 | |
| 1203 | /// Compute a more accurate approximate conversion from gamma2 to PQ space. |
| 1204 | /// |
| 1205 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1206 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1207 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1208 | /// |
| 1209 | /// @param a The value to convert between gamma2 and PQ. |
| 1210 | /// |
| 1211 | /// @returns |
| 1212 | /// The value <c><i>a</i></c> converted into PQ. |
| 1213 | /// |
| 1214 | /// @ingroup GPU |
| 1215 | FfxFloat32 ffxApproximateGamma2ToPQMedium(FfxFloat32 a) |
| 1216 | { |
| 1217 | FfxFloat32 b = ffxAsFloat((ffxAsUInt32(a) >> FfxUInt32(2)) + FfxUInt32(0x2F9A4E46)); |
| 1218 | FfxFloat32 b4 = b * b * b * b; |
| 1219 | return b - b * (b4 - a) / (FfxFloat32(4.0) * b4); |
| 1220 | } |
| 1221 | |
| 1222 | /// Compute a high accuracy approximate conversion from gamma2 to PQ space. |
| 1223 | /// |
| 1224 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1225 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1226 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1227 | /// |
| 1228 | /// @param a The value to convert between gamma2 and PQ. |
| 1229 | /// |
| 1230 | /// @returns |
| 1231 | /// The value <c><i>a</i></c> converted into PQ. |
| 1232 | /// |
| 1233 | /// @ingroup GPU |
| 1234 | FfxFloat32 ffxApproximateGamma2ToPQHigh(FfxFloat32 a) |
| 1235 | { |
| 1236 | return ffxSqrt(ffxSqrt(a)); |
| 1237 | } |
| 1238 | |
| 1239 | /// Compute an approximate conversion from linear to PQ space. |
| 1240 | /// |
| 1241 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1242 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1243 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1244 | /// |
| 1245 | /// @param a The value to convert between linear and PQ. |
| 1246 | /// |
| 1247 | /// @returns |
| 1248 | /// The value <c><i>a</i></c> converted into PQ. |
| 1249 | /// |
| 1250 | /// @ingroup GPU |
| 1251 | FfxFloat32 ffxApproximateLinearToPQ(FfxFloat32 a) |
| 1252 | { |
| 1253 | return ffxAsFloat((ffxAsUInt32(a) >> FfxUInt32(3)) + FfxUInt32(0x378D8723)); |
| 1254 | } |
| 1255 | |
| 1256 | /// Compute a more accurate approximate conversion from linear to PQ space. |
| 1257 | /// |
| 1258 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1259 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1260 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1261 | /// |
| 1262 | /// @param a The value to convert between linear and PQ. |
| 1263 | /// |
| 1264 | /// @returns |
| 1265 | /// The value <c><i>a</i></c> converted into PQ. |
| 1266 | /// |
| 1267 | /// @ingroup GPU |
| 1268 | FfxFloat32 ffxApproximateLinearToPQMedium(FfxFloat32 a) |
| 1269 | { |
| 1270 | FfxFloat32 b = ffxAsFloat((ffxAsUInt32(a) >> FfxUInt32(3)) + FfxUInt32(0x378D8723)); |
| 1271 | FfxFloat32 b8 = b * b * b * b * b * b * b * b; |
| 1272 | return b - b * (b8 - a) / (FfxFloat32(8.0) * b8); |
| 1273 | } |
| 1274 | |
| 1275 | /// Compute a very accurate approximate conversion from linear to PQ space. |
| 1276 | /// |
| 1277 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1278 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1279 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1280 | /// |
| 1281 | /// @param a The value to convert between linear and PQ. |
| 1282 | /// |
| 1283 | /// @returns |
| 1284 | /// The value <c><i>a</i></c> converted into PQ. |
| 1285 | /// |
| 1286 | /// @ingroup GPU |
| 1287 | FfxFloat32 ffxApproximateLinearToPQHigh(FfxFloat32 a) |
| 1288 | { |
| 1289 | return ffxSqrt(ffxSqrt(ffxSqrt(a))); |
| 1290 | } |
| 1291 | |
| 1292 | /// Compute an approximate conversion from PQ to Gamma2 space. |
| 1293 | /// |
| 1294 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1295 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1296 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1297 | /// |
| 1298 | /// @param a The value to convert between PQ and Gamma2. |
| 1299 | /// |
| 1300 | /// @returns |
| 1301 | /// The value <c><i>a</i></c> converted into Gamma2. |
| 1302 | /// |
| 1303 | /// @ingroup GPU |
| 1304 | FfxFloat32x2 ffxApproximatePQToGamma2Medium(FfxFloat32x2 a) |
| 1305 | { |
| 1306 | return a * a * a * a; |
| 1307 | } |
| 1308 | |
| 1309 | /// Compute an approximate conversion from PQ to linear space. |
| 1310 | /// |
| 1311 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1312 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1313 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1314 | /// |
| 1315 | /// @param a The value to convert between PQ and linear. |
| 1316 | /// |
| 1317 | /// @returns |
| 1318 | /// The value <c><i>a</i></c> converted into linear. |
| 1319 | /// |
| 1320 | /// @ingroup GPU |
| 1321 | FfxFloat32x2 ffxApproximatePQToLinear(FfxFloat32x2 a) |
| 1322 | { |
| 1323 | return a * a * a * a * a * a * a * a; |
| 1324 | } |
| 1325 | |
| 1326 | /// Compute an approximate conversion from gamma2 to PQ space. |
| 1327 | /// |
| 1328 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1329 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1330 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1331 | /// |
| 1332 | /// @param a The value to convert between gamma2 and PQ. |
| 1333 | /// |
| 1334 | /// @returns |
| 1335 | /// The value <c><i>a</i></c> converted into PQ. |
| 1336 | /// |
| 1337 | /// @ingroup GPU |
| 1338 | FfxFloat32x2 ffxApproximateGamma2ToPQ(FfxFloat32x2 a) |
| 1339 | { |
| 1340 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast2(2u)) + ffxBroadcast2(0x2F9A4E46u)); |
| 1341 | } |
| 1342 | |
| 1343 | /// Compute a more accurate approximate conversion from gamma2 to PQ space. |
| 1344 | /// |
| 1345 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1346 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1347 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1348 | /// |
| 1349 | /// @param a The value to convert between gamma2 and PQ. |
| 1350 | /// |
| 1351 | /// @returns |
| 1352 | /// The value <c><i>a</i></c> converted into PQ. |
| 1353 | /// |
| 1354 | /// @ingroup GPU |
| 1355 | FfxFloat32x2 ffxApproximateGamma2ToPQMedium(FfxFloat32x2 a) |
| 1356 | { |
| 1357 | FfxFloat32x2 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast2(2u)) + ffxBroadcast2(0x2F9A4E46u)); |
| 1358 | FfxFloat32x2 b4 = b * b * b * b; |
| 1359 | return b - b * (b4 - a) / (FfxFloat32(4.0) * b4); |
| 1360 | } |
| 1361 | |
| 1362 | /// Compute a high accuracy approximate conversion from gamma2 to PQ space. |
| 1363 | /// |
| 1364 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1365 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1366 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1367 | /// |
| 1368 | /// @param a The value to convert between gamma2 and PQ. |
| 1369 | /// |
| 1370 | /// @returns |
| 1371 | /// The value <c><i>a</i></c> converted into PQ. |
| 1372 | /// |
| 1373 | /// @ingroup GPU |
| 1374 | FfxFloat32x2 ffxApproximateGamma2ToPQHigh(FfxFloat32x2 a) |
| 1375 | { |
| 1376 | return ffxSqrt(ffxSqrt(a)); |
| 1377 | } |
| 1378 | |
| 1379 | /// Compute an approximate conversion from linear to PQ space. |
| 1380 | /// |
| 1381 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1382 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1383 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1384 | /// |
| 1385 | /// @param a The value to convert between linear and PQ. |
| 1386 | /// |
| 1387 | /// @returns |
| 1388 | /// The value <c><i>a</i></c> converted into PQ. |
| 1389 | /// |
| 1390 | /// @ingroup GPU |
| 1391 | FfxFloat32x2 ffxApproximateLinearToPQ(FfxFloat32x2 a) |
| 1392 | { |
| 1393 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast2(3u)) + ffxBroadcast2(0x378D8723u)); |
| 1394 | } |
| 1395 | |
| 1396 | /// Compute a more accurate approximate conversion from linear to PQ space. |
| 1397 | /// |
| 1398 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1399 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1400 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1401 | /// |
| 1402 | /// @param a The value to convert between linear and PQ. |
| 1403 | /// |
| 1404 | /// @returns |
| 1405 | /// The value <c><i>a</i></c> converted into PQ. |
| 1406 | /// |
| 1407 | /// @ingroup GPU |
| 1408 | FfxFloat32x2 ffxApproximateLinearToPQMedium(FfxFloat32x2 a) |
| 1409 | { |
| 1410 | FfxFloat32x2 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast2(3u)) + ffxBroadcast2(0x378D8723u)); |
| 1411 | FfxFloat32x2 b8 = b * b * b * b * b * b * b * b; |
| 1412 | return b - b * (b8 - a) / (FfxFloat32(8.0) * b8); |
| 1413 | } |
| 1414 | |
| 1415 | /// Compute a very accurate approximate conversion from linear to PQ space. |
| 1416 | /// |
| 1417 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1418 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1419 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1420 | /// |
| 1421 | /// @param a The value to convert between linear and PQ. |
| 1422 | /// |
| 1423 | /// @returns |
| 1424 | /// The value <c><i>a</i></c> converted into PQ. |
| 1425 | /// |
| 1426 | /// @ingroup GPU |
| 1427 | FfxFloat32x2 ffxApproximateLinearToPQHigh(FfxFloat32x2 a) |
| 1428 | { |
| 1429 | return ffxSqrt(ffxSqrt(ffxSqrt(a))); |
| 1430 | } |
| 1431 | |
| 1432 | /// Compute an approximate conversion from PQ to Gamma2 space. |
| 1433 | /// |
| 1434 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1435 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1436 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1437 | /// |
| 1438 | /// @param a The value to convert between PQ and Gamma2. |
| 1439 | /// |
| 1440 | /// @returns |
| 1441 | /// The value <c><i>a</i></c> converted into Gamma2. |
| 1442 | /// |
| 1443 | /// @ingroup GPU |
| 1444 | FfxFloat32x3 ffxApproximatePQToGamma2Medium(FfxFloat32x3 a) |
| 1445 | { |
| 1446 | return a * a * a * a; |
| 1447 | } |
| 1448 | |
| 1449 | /// Compute an approximate conversion from PQ to linear space. |
| 1450 | /// |
| 1451 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1452 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1453 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1454 | /// |
| 1455 | /// @param a The value to convert between PQ and linear. |
| 1456 | /// |
| 1457 | /// @returns |
| 1458 | /// The value <c><i>a</i></c> converted into linear. |
| 1459 | /// |
| 1460 | /// @ingroup GPU |
| 1461 | FfxFloat32x3 ffxApproximatePQToLinear(FfxFloat32x3 a) |
| 1462 | { |
| 1463 | return a * a * a * a * a * a * a * a; |
| 1464 | } |
| 1465 | |
| 1466 | /// Compute an approximate conversion from gamma2 to PQ space. |
| 1467 | /// |
| 1468 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1469 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1470 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1471 | /// |
| 1472 | /// @param a The value to convert between gamma2 and PQ. |
| 1473 | /// |
| 1474 | /// @returns |
| 1475 | /// The value <c><i>a</i></c> converted into PQ. |
| 1476 | /// |
| 1477 | /// @ingroup GPU |
| 1478 | FfxFloat32x3 ffxApproximateGamma2ToPQ(FfxFloat32x3 a) |
| 1479 | { |
| 1480 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast3(2u)) + ffxBroadcast3(0x2F9A4E46u)); |
| 1481 | } |
| 1482 | |
| 1483 | /// Compute a more accurate approximate conversion from gamma2 to PQ space. |
| 1484 | /// |
| 1485 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1486 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1487 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1488 | /// |
| 1489 | /// @param a The value to convert between gamma2 and PQ. |
| 1490 | /// |
| 1491 | /// @returns |
| 1492 | /// The value <c><i>a</i></c> converted into PQ. |
| 1493 | /// |
| 1494 | /// @ingroup GPU |
| 1495 | FfxFloat32x3 ffxApproximateGamma2ToPQMedium(FfxFloat32x3 a) |
| 1496 | { |
| 1497 | FfxFloat32x3 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast3(2u)) + ffxBroadcast3(0x2F9A4E46u)); |
| 1498 | FfxFloat32x3 b4 = b * b * b * b; |
| 1499 | return b - b * (b4 - a) / (FfxFloat32(4.0) * b4); |
| 1500 | } |
| 1501 | |
| 1502 | /// Compute a high accuracy approximate conversion from gamma2 to PQ space. |
| 1503 | /// |
| 1504 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1505 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1506 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1507 | /// |
| 1508 | /// @param a The value to convert between gamma2 and PQ. |
| 1509 | /// |
| 1510 | /// @returns |
| 1511 | /// The value <c><i>a</i></c> converted into PQ. |
| 1512 | /// |
| 1513 | /// @ingroup GPU |
| 1514 | FfxFloat32x3 ffxApproximateGamma2ToPQHigh(FfxFloat32x3 a) |
| 1515 | { |
| 1516 | return ffxSqrt(ffxSqrt(a)); |
| 1517 | } |
| 1518 | |
| 1519 | /// Compute an approximate conversion from linear to PQ space. |
| 1520 | /// |
| 1521 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1522 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1523 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1524 | /// |
| 1525 | /// @param a The value to convert between linear and PQ. |
| 1526 | /// |
| 1527 | /// @returns |
| 1528 | /// The value <c><i>a</i></c> converted into PQ. |
| 1529 | /// |
| 1530 | /// @ingroup GPU |
| 1531 | FfxFloat32x3 ffxApproximateLinearToPQ(FfxFloat32x3 a) |
| 1532 | { |
| 1533 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast3(3u)) + ffxBroadcast3(0x378D8723u)); |
| 1534 | } |
| 1535 | |
| 1536 | /// Compute a more accurate approximate conversion from linear to PQ space. |
| 1537 | /// |
| 1538 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1539 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1540 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1541 | /// |
| 1542 | /// @param a The value to convert between linear and PQ. |
| 1543 | /// |
| 1544 | /// @returns |
| 1545 | /// The value <c><i>a</i></c> converted into PQ. |
| 1546 | /// |
| 1547 | /// @ingroup GPU |
| 1548 | FfxFloat32x3 ffxApproximateLinearToPQMedium(FfxFloat32x3 a) |
| 1549 | { |
| 1550 | FfxFloat32x3 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast3(3u)) + ffxBroadcast3(0x378D8723u)); |
| 1551 | FfxFloat32x3 b8 = b * b * b * b * b * b * b * b; |
| 1552 | return b - b * (b8 - a) / (FfxFloat32(8.0) * b8); |
| 1553 | } |
| 1554 | |
| 1555 | /// Compute a very accurate approximate conversion from linear to PQ space. |
| 1556 | /// |
| 1557 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1558 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1559 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1560 | /// |
| 1561 | /// @param a The value to convert between linear and PQ. |
| 1562 | /// |
| 1563 | /// @returns |
| 1564 | /// The value <c><i>a</i></c> converted into PQ. |
| 1565 | /// |
| 1566 | /// @ingroup GPU |
| 1567 | FfxFloat32x3 ffxApproximateLinearToPQHigh(FfxFloat32x3 a) |
| 1568 | { |
| 1569 | return ffxSqrt(ffxSqrt(ffxSqrt(a))); |
| 1570 | } |
| 1571 | |
| 1572 | /// Compute an approximate conversion from PQ to Gamma2 space. |
| 1573 | /// |
| 1574 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1575 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1576 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1577 | /// |
| 1578 | /// @param a The value to convert between PQ and Gamma2. |
| 1579 | /// |
| 1580 | /// @returns |
| 1581 | /// The value <c><i>a</i></c> converted into Gamma2. |
| 1582 | /// |
| 1583 | /// @ingroup GPU |
| 1584 | FfxFloat32x4 ffxApproximatePQToGamma2Medium(FfxFloat32x4 a) |
| 1585 | { |
| 1586 | return a * a * a * a; |
| 1587 | } |
| 1588 | |
| 1589 | /// Compute an approximate conversion from PQ to linear space. |
| 1590 | /// |
| 1591 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1592 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1593 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1594 | /// |
| 1595 | /// @param a The value to convert between PQ and linear. |
| 1596 | /// |
| 1597 | /// @returns |
| 1598 | /// The value <c><i>a</i></c> converted into linear. |
| 1599 | /// |
| 1600 | /// @ingroup GPU |
| 1601 | FfxFloat32x4 ffxApproximatePQToLinear(FfxFloat32x4 a) |
| 1602 | { |
| 1603 | return a * a * a * a * a * a * a * a; |
| 1604 | } |
| 1605 | |
| 1606 | /// Compute an approximate conversion from gamma2 to PQ space. |
| 1607 | /// |
| 1608 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1609 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1610 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1611 | /// |
| 1612 | /// @param a The value to convert between gamma2 and PQ. |
| 1613 | /// |
| 1614 | /// @returns |
| 1615 | /// The value <c><i>a</i></c> converted into PQ. |
| 1616 | /// |
| 1617 | /// @ingroup GPU |
| 1618 | FfxFloat32x4 ffxApproximateGamma2ToPQ(FfxFloat32x4 a) |
| 1619 | { |
| 1620 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast4(2u)) + ffxBroadcast4(0x2F9A4E46u)); |
| 1621 | } |
| 1622 | |
| 1623 | /// Compute a more accurate approximate conversion from gamma2 to PQ space. |
| 1624 | /// |
| 1625 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1626 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1627 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1628 | /// |
| 1629 | /// @param a The value to convert between gamma2 and PQ. |
| 1630 | /// |
| 1631 | /// @returns |
| 1632 | /// The value <c><i>a</i></c> converted into PQ. |
| 1633 | /// |
| 1634 | /// @ingroup GPU |
| 1635 | FfxFloat32x4 ffxApproximateGamma2ToPQMedium(FfxFloat32x4 a) |
| 1636 | { |
| 1637 | FfxFloat32x4 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast4(2u)) + ffxBroadcast4(0x2F9A4E46u)); |
| 1638 | FfxFloat32x4 b4 = b * b * b * b * b * b * b * b; |
| 1639 | return b - b * (b4 - a) / (FfxFloat32(4.0) * b4); |
| 1640 | } |
| 1641 | |
| 1642 | /// Compute a high accuracy approximate conversion from gamma2 to PQ space. |
| 1643 | /// |
| 1644 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1645 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1646 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1647 | /// |
| 1648 | /// @param a The value to convert between gamma2 and PQ. |
| 1649 | /// |
| 1650 | /// @returns |
| 1651 | /// The value <c><i>a</i></c> converted into PQ. |
| 1652 | /// |
| 1653 | /// @ingroup GPU |
| 1654 | FfxFloat32x4 ffxApproximateGamma2ToPQHigh(FfxFloat32x4 a) |
| 1655 | { |
| 1656 | return ffxSqrt(ffxSqrt(a)); |
| 1657 | } |
| 1658 | |
| 1659 | /// Compute an approximate conversion from linear to PQ space. |
| 1660 | /// |
| 1661 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1662 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1663 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1664 | /// |
| 1665 | /// @param a The value to convert between linear and PQ. |
| 1666 | /// |
| 1667 | /// @returns |
| 1668 | /// The value <c><i>a</i></c> converted into PQ. |
| 1669 | /// |
| 1670 | /// @ingroup GPU |
| 1671 | FfxFloat32x4 ffxApproximateLinearToPQ(FfxFloat32x4 a) |
| 1672 | { |
| 1673 | return ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast4(3u)) + ffxBroadcast4(0x378D8723u)); |
| 1674 | } |
| 1675 | |
| 1676 | /// Compute a more accurate approximate conversion from linear to PQ space. |
| 1677 | /// |
| 1678 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1679 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1680 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1681 | /// |
| 1682 | /// @param a The value to convert between linear and PQ. |
| 1683 | /// |
| 1684 | /// @returns |
| 1685 | /// The value <c><i>a</i></c> converted into PQ. |
| 1686 | /// |
| 1687 | /// @ingroup GPU |
| 1688 | FfxFloat32x4 ffxApproximateLinearToPQMedium(FfxFloat32x4 a) |
| 1689 | { |
| 1690 | FfxFloat32x4 b = ffxAsFloat((ffxAsUInt32(a) >> ffxBroadcast4(3u)) + ffxBroadcast4(0x378D8723u)); |
| 1691 | FfxFloat32x4 b8 = b * b * b * b * b * b * b * b; |
| 1692 | return b - b * (b8 - a) / (FfxFloat32(8.0) * b8); |
| 1693 | } |
| 1694 | |
| 1695 | /// Compute a very accurate approximate conversion from linear to PQ space. |
| 1696 | /// |
| 1697 | /// PQ is very close to x^(1/8). The functions below Use the fast FfxFloat32 approximation method to do |
| 1698 | /// PQ conversions to and from Gamma2 (4th power and fast 4th root), and PQ to and from Linear |
| 1699 | /// (8th power and fast 8th root). The maximum error is approximately 0.2%. |
| 1700 | /// |
| 1701 | /// @param a The value to convert between linear and PQ. |
| 1702 | /// |
| 1703 | /// @returns |
| 1704 | /// The value <c><i>a</i></c> converted into PQ. |
| 1705 | /// |
| 1706 | /// @ingroup GPU |
| 1707 | FfxFloat32x4 ffxApproximateLinearToPQHigh(FfxFloat32x4 a) |
| 1708 | { |
| 1709 | return ffxSqrt(ffxSqrt(ffxSqrt(a))); |
| 1710 | } |
| 1711 | |
| 1712 | // An approximation of sine. |
| 1713 | // |
| 1714 | // Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1715 | // is {-1/4 to 1/4} representing {-1 to 1}. |
| 1716 | // |
| 1717 | // @param [in] value The value to calculate approximate sine for. |
| 1718 | // |
| 1719 | // @returns |
| 1720 | // The approximate sine of <c><i>value</i></c>. |
| 1721 | FfxFloat32 ffxParabolicSin(FfxFloat32 value) |
| 1722 | { |
| 1723 | return value * abs(value) - value; |
| 1724 | } |
| 1725 | |
| 1726 | // An approximation of sine. |
| 1727 | // |
| 1728 | // Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1729 | // is {-1/4 to 1/4} representing {-1 to 1}. |
| 1730 | // |
| 1731 | // @param [in] value The value to calculate approximate sine for. |
| 1732 | // |
| 1733 | // @returns |
| 1734 | // The approximate sine of <c><i>value</i></c>. |
| 1735 | FfxFloat32x2 ffxParabolicSin(FfxFloat32x2 x) |
| 1736 | { |
| 1737 | return x * abs(x) - x; |
| 1738 | } |
| 1739 | |
| 1740 | // An approximation of cosine. |
| 1741 | // |
| 1742 | // Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1743 | // is {-1/4 to 1/4} representing {-1 to 1}. |
| 1744 | // |
| 1745 | // @param [in] value The value to calculate approximate cosine for. |
| 1746 | // |
| 1747 | // @returns |
| 1748 | // The approximate cosine of <c><i>value</i></c>. |
| 1749 | FfxFloat32 ffxParabolicCos(FfxFloat32 x) |
| 1750 | { |
| 1751 | x = ffxFract(x * FfxFloat32(0.5) + FfxFloat32(0.75)); |
| 1752 | x = x * FfxFloat32(2.0) - FfxFloat32(1.0); |
| 1753 | return ffxParabolicSin(x); |
| 1754 | } |
| 1755 | |
| 1756 | // An approximation of cosine. |
| 1757 | // |
| 1758 | // Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1759 | // is {-1/4 to 1/4} representing {-1 to 1}. |
| 1760 | // |
| 1761 | // @param [in] value The value to calculate approximate cosine for. |
| 1762 | // |
| 1763 | // @returns |
| 1764 | // The approximate cosine of <c><i>value</i></c>. |
| 1765 | FfxFloat32x2 ffxParabolicCos(FfxFloat32x2 x) |
| 1766 | { |
| 1767 | x = ffxFract(x * ffxBroadcast2(0.5f) + ffxBroadcast2(0.75f)); |
| 1768 | x = x * ffxBroadcast2(2.0f) - ffxBroadcast2(1.0f); |
| 1769 | return ffxParabolicSin(x); |
| 1770 | } |
| 1771 | |
| 1772 | // An approximation of both sine and cosine. |
| 1773 | // |
| 1774 | // Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1775 | // is {-1/4 to 1/4} representing {-1 to 1}. |
| 1776 | // |
| 1777 | // @param [in] value The value to calculate approximate cosine for. |
| 1778 | // |
| 1779 | // @returns |
| 1780 | // A <c><i>FfxFloat32x2</i></c> containing approximations of both sine and cosine of <c><i>value</i></c>. |
| 1781 | FfxFloat32x2 ffxParabolicSinCos(FfxFloat32 x) |
| 1782 | { |
| 1783 | FfxFloat32 y = ffxFract(x * FfxFloat32(0.5) + FfxFloat32(0.75)); |
| 1784 | y = y * FfxFloat32(2.0) - FfxFloat32(1.0); |
| 1785 | return ffxParabolicSin(FfxFloat32x2(x, y)); |
| 1786 | } |
| 1787 | |
| 1788 | /// Conditional free logic AND operation using values. |
| 1789 | /// |
| 1790 | /// @param [in] x The first value to be fed into the AND operator. |
| 1791 | /// @param [in] y The second value to be fed into the AND operator. |
| 1792 | /// |
| 1793 | /// @returns |
| 1794 | /// Result of the AND operation. |
| 1795 | /// |
| 1796 | /// @ingroup GPU |
| 1797 | FfxUInt32 ffxZeroOneAnd(FfxUInt32 x, FfxUInt32 y) |
| 1798 | { |
| 1799 | return min(x, y); |
| 1800 | } |
| 1801 | |
| 1802 | /// Conditional free logic AND operation using two values. |
| 1803 | /// |
| 1804 | /// @param [in] x The first value to be fed into the AND operator. |
| 1805 | /// @param [in] y The second value to be fed into the AND operator. |
| 1806 | /// |
| 1807 | /// @returns |
| 1808 | /// Result of the AND operation. |
| 1809 | /// |
| 1810 | /// @ingroup GPU |
| 1811 | FfxUInt32x2 ffxZeroOneAnd(FfxUInt32x2 x, FfxUInt32x2 y) |
| 1812 | { |
| 1813 | return min(x, y); |
| 1814 | } |
| 1815 | |
| 1816 | /// Conditional free logic AND operation using two values. |
| 1817 | /// |
| 1818 | /// @param [in] x The first value to be fed into the AND operator. |
| 1819 | /// @param [in] y The second value to be fed into the AND operator. |
| 1820 | /// |
| 1821 | /// @returns |
| 1822 | /// Result of the AND operation. |
| 1823 | /// |
| 1824 | /// @ingroup GPU |
| 1825 | FfxUInt32x3 ffxZeroOneAnd(FfxUInt32x3 x, FfxUInt32x3 y) |
| 1826 | { |
| 1827 | return min(x, y); |
| 1828 | } |
| 1829 | |
| 1830 | /// Conditional free logic AND operation using two values. |
| 1831 | /// |
| 1832 | /// @param [in] x The first value to be fed into the AND operator. |
| 1833 | /// @param [in] y The second value to be fed into the AND operator. |
| 1834 | /// |
| 1835 | /// @returns |
| 1836 | /// Result of the AND operation. |
| 1837 | /// |
| 1838 | /// @ingroup GPU |
| 1839 | FfxUInt32x4 ffxZeroOneAnd(FfxUInt32x4 x, FfxUInt32x4 y) |
| 1840 | { |
| 1841 | return min(x, y); |
| 1842 | } |
| 1843 | |
| 1844 | /// Conditional free logic NOT operation using two values. |
| 1845 | /// |
| 1846 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1847 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1848 | /// |
| 1849 | /// @returns |
| 1850 | /// Result of the NOT operation. |
| 1851 | /// |
| 1852 | /// @ingroup GPU |
| 1853 | FfxUInt32 ffxZeroOneAnd(FfxUInt32 x) |
| 1854 | { |
| 1855 | return x ^ FfxUInt32(1); |
| 1856 | } |
| 1857 | |
| 1858 | /// Conditional free logic NOT operation using two values. |
| 1859 | /// |
| 1860 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1861 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1862 | /// |
| 1863 | /// @returns |
| 1864 | /// Result of the NOT operation. |
| 1865 | /// |
| 1866 | /// @ingroup GPU |
| 1867 | FfxUInt32x2 ffxZeroOneAnd(FfxUInt32x2 x) |
| 1868 | { |
| 1869 | return x ^ ffxBroadcast2(1u); |
| 1870 | } |
| 1871 | |
| 1872 | /// Conditional free logic NOT operation using two values. |
| 1873 | /// |
| 1874 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1875 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1876 | /// |
| 1877 | /// @returns |
| 1878 | /// Result of the NOT operation. |
| 1879 | /// |
| 1880 | /// @ingroup GPU |
| 1881 | FfxUInt32x3 ffxZeroOneAnd(FfxUInt32x3 x) |
| 1882 | { |
| 1883 | return x ^ ffxBroadcast3(1u); |
| 1884 | } |
| 1885 | |
| 1886 | /// Conditional free logic NOT operation using two values. |
| 1887 | /// |
| 1888 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1889 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1890 | /// |
| 1891 | /// @returns |
| 1892 | /// Result of the NOT operation. |
| 1893 | /// |
| 1894 | /// @ingroup GPU |
| 1895 | FfxUInt32x4 ffxZeroOneAnd(FfxUInt32x4 x) |
| 1896 | { |
| 1897 | return x ^ ffxBroadcast4(1u); |
| 1898 | } |
| 1899 | |
| 1900 | /// Conditional free logic OR operation using two values. |
| 1901 | /// |
| 1902 | /// @param [in] x The first value to be fed into the OR operator. |
| 1903 | /// @param [in] y The second value to be fed into the OR operator. |
| 1904 | /// |
| 1905 | /// @returns |
| 1906 | /// Result of the OR operation. |
| 1907 | /// |
| 1908 | /// @ingroup GPU |
| 1909 | FfxUInt32 ffxZeroOneOr(FfxUInt32 x, FfxUInt32 y) |
| 1910 | { |
| 1911 | return max(x, y); |
| 1912 | } |
| 1913 | |
| 1914 | /// Conditional free logic OR operation using two values. |
| 1915 | /// |
| 1916 | /// @param [in] x The first value to be fed into the OR operator. |
| 1917 | /// @param [in] y The second value to be fed into the OR operator. |
| 1918 | /// |
| 1919 | /// @returns |
| 1920 | /// Result of the OR operation. |
| 1921 | /// |
| 1922 | /// @ingroup GPU |
| 1923 | FfxUInt32x2 ffxZeroOneOr(FfxUInt32x2 x, FfxUInt32x2 y) |
| 1924 | { |
| 1925 | return max(x, y); |
| 1926 | } |
| 1927 | |
| 1928 | /// Conditional free logic OR operation using two values. |
| 1929 | /// |
| 1930 | /// @param [in] x The first value to be fed into the OR operator. |
| 1931 | /// @param [in] y The second value to be fed into the OR operator. |
| 1932 | /// |
| 1933 | /// @returns |
| 1934 | /// Result of the OR operation. |
| 1935 | /// |
| 1936 | /// @ingroup GPU |
| 1937 | FfxUInt32x3 ffxZeroOneOr(FfxUInt32x3 x, FfxUInt32x3 y) |
| 1938 | { |
| 1939 | return max(x, y); |
| 1940 | } |
| 1941 | |
| 1942 | /// Conditional free logic OR operation using two values. |
| 1943 | /// |
| 1944 | /// @param [in] x The first value to be fed into the OR operator. |
| 1945 | /// @param [in] y The second value to be fed into the OR operator. |
| 1946 | /// |
| 1947 | /// @returns |
| 1948 | /// Result of the OR operation. |
| 1949 | /// |
| 1950 | /// @ingroup GPU |
| 1951 | FfxUInt32x4 ffxZeroOneOr(FfxUInt32x4 x, FfxUInt32x4 y) |
| 1952 | { |
| 1953 | return max(x, y); |
| 1954 | } |
| 1955 | |
| 1956 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 1957 | /// |
| 1958 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 1959 | /// |
| 1960 | /// @returns |
| 1961 | /// Result of the AND OR operation. |
| 1962 | /// |
| 1963 | /// @ingroup GPU |
| 1964 | FfxUInt32 ffxZeroOneAndToU1(FfxFloat32 x) |
| 1965 | { |
| 1966 | return FfxUInt32(FfxFloat32(1.0) - x); |
| 1967 | } |
| 1968 | |
| 1969 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 1970 | /// |
| 1971 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 1972 | /// |
| 1973 | /// @returns |
| 1974 | /// Result of the AND OR operation. |
| 1975 | /// |
| 1976 | /// @ingroup GPU |
| 1977 | FfxUInt32x2 ffxZeroOneAndToU2(FfxFloat32x2 x) |
| 1978 | { |
| 1979 | return FfxUInt32x2(ffxBroadcast2(1.0) - x); |
| 1980 | } |
| 1981 | |
| 1982 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 1983 | /// |
| 1984 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 1985 | /// |
| 1986 | /// @returns |
| 1987 | /// Result of the AND OR operation. |
| 1988 | /// |
| 1989 | /// @ingroup GPU |
| 1990 | FfxUInt32x3 ffxZeroOneAndToU3(FfxFloat32x3 x) |
| 1991 | { |
| 1992 | return FfxUInt32x3(ffxBroadcast3(1.0) - x); |
| 1993 | } |
| 1994 | |
| 1995 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 1996 | /// |
| 1997 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 1998 | /// |
| 1999 | /// @returns |
| 2000 | /// Result of the AND OR operation. |
| 2001 | /// |
| 2002 | /// @ingroup GPU |
| 2003 | FfxUInt32x4 ffxZeroOneAndToU4(FfxFloat32x4 x) |
| 2004 | { |
| 2005 | return FfxUInt32x4(ffxBroadcast4(1.0) - x); |
| 2006 | } |
| 2007 | |
| 2008 | /// Conditional free logic AND operation using two values followed by a NOT operation |
| 2009 | /// using the resulting value and a third value. |
| 2010 | /// |
| 2011 | /// @param [in] x The first value to be fed into the AND operator. |
| 2012 | /// @param [in] y The second value to be fed into the AND operator. |
| 2013 | /// @param [in] z The second value to be fed into the OR operator. |
| 2014 | /// |
| 2015 | /// @returns |
| 2016 | /// Result of the AND OR operation. |
| 2017 | /// |
| 2018 | /// @ingroup GPU |
| 2019 | FfxFloat32 ffxZeroOneAndOr(FfxFloat32 x, FfxFloat32 y, FfxFloat32 z) |
| 2020 | { |
| 2021 | return ffxSaturate(x * y + z); |
| 2022 | } |
| 2023 | |
| 2024 | /// Conditional free logic AND operation using two values followed by a NOT operation |
| 2025 | /// using the resulting value and a third value. |
| 2026 | /// |
| 2027 | /// @param [in] x The first value to be fed into the AND operator. |
| 2028 | /// @param [in] y The second value to be fed into the AND operator. |
| 2029 | /// @param [in] z The second value to be fed into the OR operator. |
| 2030 | /// |
| 2031 | /// @returns |
| 2032 | /// Result of the AND OR operation. |
| 2033 | /// |
| 2034 | /// @ingroup GPU |
| 2035 | FfxFloat32x2 ffxZeroOneAndOr(FfxFloat32x2 x, FfxFloat32x2 y, FfxFloat32x2 z) |
| 2036 | { |
| 2037 | return ffxSaturate(x * y + z); |
| 2038 | } |
| 2039 | |
| 2040 | /// Conditional free logic AND operation using two values followed by a NOT operation |
| 2041 | /// using the resulting value and a third value. |
| 2042 | /// |
| 2043 | /// @param [in] x The first value to be fed into the AND operator. |
| 2044 | /// @param [in] y The second value to be fed into the AND operator. |
| 2045 | /// @param [in] z The second value to be fed into the OR operator. |
| 2046 | /// |
| 2047 | /// @returns |
| 2048 | /// Result of the AND OR operation. |
| 2049 | /// |
| 2050 | /// @ingroup GPU |
| 2051 | FfxFloat32x3 ffxZeroOneAndOr(FfxFloat32x3 x, FfxFloat32x3 y, FfxFloat32x3 z) |
| 2052 | { |
| 2053 | return ffxSaturate(x * y + z); |
| 2054 | } |
| 2055 | |
| 2056 | /// Conditional free logic AND operation using two values followed by a NOT operation |
| 2057 | /// using the resulting value and a third value. |
| 2058 | /// |
| 2059 | /// @param [in] x The first value to be fed into the AND operator. |
| 2060 | /// @param [in] y The second value to be fed into the AND operator. |
| 2061 | /// @param [in] z The second value to be fed into the OR operator. |
| 2062 | /// |
| 2063 | /// @returns |
| 2064 | /// Result of the AND OR operation. |
| 2065 | /// |
| 2066 | /// @ingroup GPU |
| 2067 | FfxFloat32x4 ffxZeroOneAndOr(FfxFloat32x4 x, FfxFloat32x4 y, FfxFloat32x4 z) |
| 2068 | { |
| 2069 | return ffxSaturate(x * y + z); |
| 2070 | } |
| 2071 | |
| 2072 | /// Given a value, returns 1.0 if greater than zero and 0.0 if not. |
| 2073 | /// |
| 2074 | /// @param [in] x The value to be compared. |
| 2075 | /// |
| 2076 | /// @returns |
| 2077 | /// Result of the greater than zero comparison. |
| 2078 | /// |
| 2079 | /// @ingroup GPU |
| 2080 | FfxFloat32 ffxZeroOneIsGreaterThanZero(FfxFloat32 x) |
| 2081 | { |
| 2082 | return ffxSaturate(x * FfxFloat32(FFX_POSITIVE_INFINITY_FLOAT)); |
| 2083 | } |
| 2084 | |
| 2085 | /// Given a value, returns 1.0 if greater than zero and 0.0 if not. |
| 2086 | /// |
| 2087 | /// @param [in] x The value to be compared. |
| 2088 | /// |
| 2089 | /// @returns |
| 2090 | /// Result of the greater than zero comparison. |
| 2091 | /// |
| 2092 | /// @ingroup GPU |
| 2093 | FfxFloat32x2 ffxZeroOneIsGreaterThanZero(FfxFloat32x2 x) |
| 2094 | { |
| 2095 | return ffxSaturate(x * ffxBroadcast2(FFX_POSITIVE_INFINITY_FLOAT)); |
| 2096 | } |
| 2097 | |
| 2098 | /// Given a value, returns 1.0 if greater than zero and 0.0 if not. |
| 2099 | /// |
| 2100 | /// @param [in] x The value to be compared. |
| 2101 | /// |
| 2102 | /// @returns |
| 2103 | /// Result of the greater than zero comparison. |
| 2104 | /// |
| 2105 | /// @ingroup GPU |
| 2106 | FfxFloat32x3 ffxZeroOneIsGreaterThanZero(FfxFloat32x3 x) |
| 2107 | { |
| 2108 | return ffxSaturate(x * ffxBroadcast3(FFX_POSITIVE_INFINITY_FLOAT)); |
| 2109 | } |
| 2110 | |
| 2111 | /// Given a value, returns 1.0 if greater than zero and 0.0 if not. |
| 2112 | /// |
| 2113 | /// @param [in] x The value to be compared. |
| 2114 | /// |
| 2115 | /// @returns |
| 2116 | /// Result of the greater than zero comparison. |
| 2117 | /// |
| 2118 | /// @ingroup GPU |
| 2119 | FfxFloat32x4 ffxZeroOneIsGreaterThanZero(FfxFloat32x4 x) |
| 2120 | { |
| 2121 | return ffxSaturate(x * ffxBroadcast4(FFX_POSITIVE_INFINITY_FLOAT)); |
| 2122 | } |
| 2123 | |
| 2124 | /// Conditional free logic signed NOT operation using two FfxFloat32 values. |
| 2125 | /// |
| 2126 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2127 | /// |
| 2128 | /// @returns |
| 2129 | /// Result of the AND OR operation. |
| 2130 | /// |
| 2131 | /// @ingroup GPU |
| 2132 | FfxFloat32 ffxZeroOneAnd(FfxFloat32 x) |
| 2133 | { |
| 2134 | return FfxFloat32(1.0) - x; |
| 2135 | } |
| 2136 | |
| 2137 | /// Conditional free logic signed NOT operation using two FfxFloat32 values. |
| 2138 | /// |
| 2139 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2140 | /// |
| 2141 | /// @returns |
| 2142 | /// Result of the AND OR operation. |
| 2143 | /// |
| 2144 | /// @ingroup GPU |
| 2145 | FfxFloat32x2 ffxZeroOneAnd(FfxFloat32x2 x) |
| 2146 | { |
| 2147 | return ffxBroadcast2(1.0) - x; |
| 2148 | } |
| 2149 | |
| 2150 | /// Conditional free logic signed NOT operation using two FfxFloat32 values. |
| 2151 | /// |
| 2152 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2153 | /// |
| 2154 | /// @returns |
| 2155 | /// Result of the AND OR operation. |
| 2156 | /// |
| 2157 | /// @ingroup GPU |
| 2158 | FfxFloat32x3 ffxZeroOneAnd(FfxFloat32x3 x) |
| 2159 | { |
| 2160 | return ffxBroadcast3(1.0) - x; |
| 2161 | } |
| 2162 | |
| 2163 | /// Conditional free logic signed NOT operation using two FfxFloat32 values. |
| 2164 | /// |
| 2165 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2166 | /// |
| 2167 | /// @returns |
| 2168 | /// Result of the AND OR operation. |
| 2169 | /// |
| 2170 | /// @ingroup GPU |
| 2171 | FfxFloat32x4 ffxZeroOneAnd(FfxFloat32x4 x) |
| 2172 | { |
| 2173 | return ffxBroadcast4(1.0) - x; |
| 2174 | } |
| 2175 | |
| 2176 | /// Conditional free logic OR operation using two FfxFloat32 values. |
| 2177 | /// |
| 2178 | /// @param [in] x The first value to be fed into the OR operator. |
| 2179 | /// @param [in] y The second value to be fed into the OR operator. |
| 2180 | /// |
| 2181 | /// @returns |
| 2182 | /// Result of the OR operation. |
| 2183 | /// |
| 2184 | /// @ingroup GPU |
| 2185 | FfxFloat32 ffxZeroOneOr(FfxFloat32 x, FfxFloat32 y) |
| 2186 | { |
| 2187 | return max(x, y); |
| 2188 | } |
| 2189 | |
| 2190 | /// Conditional free logic OR operation using two FfxFloat32 values. |
| 2191 | /// |
| 2192 | /// @param [in] x The first value to be fed into the OR operator. |
| 2193 | /// @param [in] y The second value to be fed into the OR operator. |
| 2194 | /// |
| 2195 | /// @returns |
| 2196 | /// Result of the OR operation. |
| 2197 | /// |
| 2198 | /// @ingroup GPU |
| 2199 | FfxFloat32x2 ffxZeroOneOr(FfxFloat32x2 x, FfxFloat32x2 y) |
| 2200 | { |
| 2201 | return max(x, y); |
| 2202 | } |
| 2203 | |
| 2204 | /// Conditional free logic OR operation using two FfxFloat32 values. |
| 2205 | /// |
| 2206 | /// @param [in] x The first value to be fed into the OR operator. |
| 2207 | /// @param [in] y The second value to be fed into the OR operator. |
| 2208 | /// |
| 2209 | /// @returns |
| 2210 | /// Result of the OR operation. |
| 2211 | /// |
| 2212 | /// @ingroup GPU |
| 2213 | FfxFloat32x3 ffxZeroOneOr(FfxFloat32x3 x, FfxFloat32x3 y) |
| 2214 | { |
| 2215 | return max(x, y); |
| 2216 | } |
| 2217 | |
| 2218 | /// Conditional free logic OR operation using two FfxFloat32 values. |
| 2219 | /// |
| 2220 | /// @param [in] x The first value to be fed into the OR operator. |
| 2221 | /// @param [in] y The second value to be fed into the OR operator. |
| 2222 | /// |
| 2223 | /// @returns |
| 2224 | /// Result of the OR operation. |
| 2225 | /// |
| 2226 | /// @ingroup GPU |
| 2227 | FfxFloat32x4 ffxZeroOneOr(FfxFloat32x4 x, FfxFloat32x4 y) |
| 2228 | { |
| 2229 | return max(x, y); |
| 2230 | } |
| 2231 | |
| 2232 | /// Choose between two FfxFloat32 values if the first paramter is greater than zero. |
| 2233 | /// |
| 2234 | /// @param [in] x The value to compare against zero. |
| 2235 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2236 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2237 | /// |
| 2238 | /// @returns |
| 2239 | /// The selected value. |
| 2240 | /// |
| 2241 | /// @ingroup GPU |
| 2242 | FfxFloat32 ffxZeroOneSelect(FfxFloat32 x, FfxFloat32 y, FfxFloat32 z) |
| 2243 | { |
| 2244 | FfxFloat32 r = (-x) * z + z; |
| 2245 | return x * y + r; |
| 2246 | } |
| 2247 | |
| 2248 | /// Choose between two FfxFloat32 values if the first paramter is greater than zero. |
| 2249 | /// |
| 2250 | /// @param [in] x The value to compare against zero. |
| 2251 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2252 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2253 | /// |
| 2254 | /// @returns |
| 2255 | /// The selected value. |
| 2256 | /// |
| 2257 | /// @ingroup GPU |
| 2258 | FfxFloat32x2 ffxZeroOneSelect(FfxFloat32x2 x, FfxFloat32x2 y, FfxFloat32x2 z) |
| 2259 | { |
| 2260 | FfxFloat32x2 r = (-x) * z + z; |
| 2261 | return x * y + r; |
| 2262 | } |
| 2263 | |
| 2264 | /// Choose between two FfxFloat32 values if the first paramter is greater than zero. |
| 2265 | /// |
| 2266 | /// @param [in] x The value to compare against zero. |
| 2267 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2268 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2269 | /// |
| 2270 | /// @returns |
| 2271 | /// The selected value. |
| 2272 | /// |
| 2273 | /// @ingroup GPU |
| 2274 | FfxFloat32x3 ffxZeroOneSelect(FfxFloat32x3 x, FfxFloat32x3 y, FfxFloat32x3 z) |
| 2275 | { |
| 2276 | FfxFloat32x3 r = (-x) * z + z; |
| 2277 | return x * y + r; |
| 2278 | } |
| 2279 | |
| 2280 | /// Choose between two FfxFloat32 values if the first paramter is greater than zero. |
| 2281 | /// |
| 2282 | /// @param [in] x The value to compare against zero. |
| 2283 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2284 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2285 | /// |
| 2286 | /// @returns |
| 2287 | /// The selected value. |
| 2288 | /// |
| 2289 | /// @ingroup GPU |
| 2290 | FfxFloat32x4 ffxZeroOneSelect(FfxFloat32x4 x, FfxFloat32x4 y, FfxFloat32x4 z) |
| 2291 | { |
| 2292 | FfxFloat32x4 r = (-x) * z + z; |
| 2293 | return x * y + r; |
| 2294 | } |
| 2295 | |
| 2296 | /// Given a value, returns 1.0 if less than zero and 0.0 if not. |
| 2297 | /// |
| 2298 | /// @param [in] x The value to be compared. |
| 2299 | /// |
| 2300 | /// @returns |
| 2301 | /// Result of the sign value. |
| 2302 | /// |
| 2303 | /// @ingroup GPU |
| 2304 | FfxFloat32 ffxZeroOneIsSigned(FfxFloat32 x) |
| 2305 | { |
| 2306 | return ffxSaturate(x * FfxFloat32(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 2307 | } |
| 2308 | |
| 2309 | /// Given a value, returns 1.0 if less than zero and 0.0 if not. |
| 2310 | /// |
| 2311 | /// @param [in] x The value to be compared. |
| 2312 | /// |
| 2313 | /// @returns |
| 2314 | /// Result of the sign value. |
| 2315 | /// |
| 2316 | /// @ingroup GPU |
| 2317 | FfxFloat32x2 ffxZeroOneIsSigned(FfxFloat32x2 x) |
| 2318 | { |
| 2319 | return ffxSaturate(x * ffxBroadcast2(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 2320 | } |
| 2321 | |
| 2322 | /// Given a value, returns 1.0 if less than zero and 0.0 if not. |
| 2323 | /// |
| 2324 | /// @param [in] x The value to be compared. |
| 2325 | /// |
| 2326 | /// @returns |
| 2327 | /// Result of the sign value. |
| 2328 | /// |
| 2329 | /// @ingroup GPU |
| 2330 | FfxFloat32x3 ffxZeroOneIsSigned(FfxFloat32x3 x) |
| 2331 | { |
| 2332 | return ffxSaturate(x * ffxBroadcast3(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 2333 | } |
| 2334 | |
| 2335 | /// Given a value, returns 1.0 if less than zero and 0.0 if not. |
| 2336 | /// |
| 2337 | /// @param [in] x The value to be compared. |
| 2338 | /// |
| 2339 | /// @returns |
| 2340 | /// Result of the sign value. |
| 2341 | /// |
| 2342 | /// @ingroup GPU |
| 2343 | FfxFloat32x4 ffxZeroOneIsSigned(FfxFloat32x4 x) |
| 2344 | { |
| 2345 | return ffxSaturate(x * ffxBroadcast4(FFX_NEGATIVE_INFINITY_FLOAT)); |
| 2346 | } |
| 2347 | |
| 2348 | /// Compute a Rec.709 color space. |
| 2349 | /// |
| 2350 | /// Rec.709 is used for some HDTVs. |
| 2351 | /// |
| 2352 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2353 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2354 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2355 | /// |
| 2356 | /// @param [in] color The color to convert to Rec. 709. |
| 2357 | /// |
| 2358 | /// @returns |
| 2359 | /// The <c><i>color</i></c> in linear space. |
| 2360 | /// |
| 2361 | /// @ingroup GPU |
| 2362 | FfxFloat32 ffxRec709FromLinear(FfxFloat32 color) |
| 2363 | { |
| 2364 | FfxFloat32x3 j = FfxFloat32x3(0.018 * 4.5, 4.5, 0.45); |
| 2365 | FfxFloat32x2 k = FfxFloat32x2(1.099, -0.099); |
| 2366 | return clamp(j.x, color * j.y, pow(color, j.z) * k.x + k.y); |
| 2367 | } |
| 2368 | |
| 2369 | /// Compute a Rec.709 color space. |
| 2370 | /// |
| 2371 | /// Rec.709 is used for some HDTVs. |
| 2372 | /// |
| 2373 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2374 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2375 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2376 | /// |
| 2377 | /// @param [in] color The color to convert to Rec. 709. |
| 2378 | /// |
| 2379 | /// @returns |
| 2380 | /// The <c><i>color</i></c> in linear space. |
| 2381 | /// |
| 2382 | /// @ingroup GPU |
| 2383 | FfxFloat32x2 ffxRec709FromLinear(FfxFloat32x2 color) |
| 2384 | { |
| 2385 | FfxFloat32x3 j = FfxFloat32x3(0.018 * 4.5, 4.5, 0.45); |
| 2386 | FfxFloat32x2 k = FfxFloat32x2(1.099, -0.099); |
| 2387 | return clamp(j.xx, color * j.yy, pow(color, j.zz) * k.xx + k.yy); |
| 2388 | } |
| 2389 | |
| 2390 | /// Compute a Rec.709 color space. |
| 2391 | /// |
| 2392 | /// Rec.709 is used for some HDTVs. |
| 2393 | /// |
| 2394 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2395 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2396 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2397 | /// |
| 2398 | /// @param [in] color The color to convert to Rec. 709. |
| 2399 | /// |
| 2400 | /// @returns |
| 2401 | /// The <c><i>color</i></c> in linear space. |
| 2402 | /// |
| 2403 | /// @ingroup GPU |
| 2404 | FfxFloat32x3 ffxRec709FromLinear(FfxFloat32x3 color) |
| 2405 | { |
| 2406 | FfxFloat32x3 j = FfxFloat32x3(0.018 * 4.5, 4.5, 0.45); |
| 2407 | FfxFloat32x2 k = FfxFloat32x2(1.099, -0.099); |
| 2408 | return clamp(j.xxx, color * j.yyy, pow(color, j.zzz) * k.xxx + k.yyy); |
| 2409 | } |
| 2410 | |
| 2411 | /// Compute a gamma value from a linear value. |
| 2412 | /// |
| 2413 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2414 | /// |
| 2415 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGamma</i></c>. |
| 2416 | /// |
| 2417 | /// @param [in] value The value to convert to gamma space from linear. |
| 2418 | /// @param [in] power The reciprocal of power value used for the gamma curve. |
| 2419 | /// |
| 2420 | /// @returns |
| 2421 | /// A value in gamma space. |
| 2422 | /// |
| 2423 | /// @ingroup GPU |
| 2424 | FfxFloat32 ffxGammaFromLinear(FfxFloat32 color, FfxFloat32 rcpX) |
| 2425 | { |
| 2426 | return pow(color, FfxFloat32(rcpX)); |
| 2427 | } |
| 2428 | |
| 2429 | /// Compute a gamma value from a linear value. |
| 2430 | /// |
| 2431 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2432 | /// |
| 2433 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGamma</i></c>. |
| 2434 | /// |
| 2435 | /// @param [in] value The value to convert to gamma space from linear. |
| 2436 | /// @param [in] power The reciprocal of power value used for the gamma curve. |
| 2437 | /// |
| 2438 | /// @returns |
| 2439 | /// A value in gamma space. |
| 2440 | /// |
| 2441 | /// @ingroup GPU |
| 2442 | FfxFloat32x2 ffxGammaFromLinear(FfxFloat32x2 color, FfxFloat32 rcpX) |
| 2443 | { |
| 2444 | return pow(color, ffxBroadcast2(rcpX)); |
| 2445 | } |
| 2446 | |
| 2447 | /// Compute a gamma value from a linear value. |
| 2448 | /// |
| 2449 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2450 | /// |
| 2451 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGamma</i></c>. |
| 2452 | /// |
| 2453 | /// @param [in] value The value to convert to gamma space from linear. |
| 2454 | /// @param [in] power The reciprocal of power value used for the gamma curve. |
| 2455 | /// |
| 2456 | /// @returns |
| 2457 | /// A value in gamma space. |
| 2458 | /// |
| 2459 | /// @ingroup GPU |
| 2460 | FfxFloat32x3 ffxGammaFromLinear(FfxFloat32x3 color, FfxFloat32 rcpX) |
| 2461 | { |
| 2462 | return pow(color, ffxBroadcast3(rcpX)); |
| 2463 | } |
| 2464 | |
| 2465 | /// Compute a PQ value from a linear value. |
| 2466 | /// |
| 2467 | /// @param [in] value The value to convert to PQ from linear. |
| 2468 | /// |
| 2469 | /// @returns |
| 2470 | /// A value in linear space. |
| 2471 | /// |
| 2472 | /// @ingroup GPU |
| 2473 | FfxFloat32 ffxPQToLinear(FfxFloat32 x) |
| 2474 | { |
| 2475 | FfxFloat32 p = pow(x, FfxFloat32(0.159302)); |
| 2476 | return pow((FfxFloat32(0.835938) + FfxFloat32(18.8516) * p) / (FfxFloat32(1.0) + FfxFloat32(18.6875) * p), FfxFloat32(78.8438)); |
| 2477 | } |
| 2478 | |
| 2479 | /// Compute a PQ value from a linear value. |
| 2480 | /// |
| 2481 | /// @param [in] value The value to convert to PQ from linear. |
| 2482 | /// |
| 2483 | /// @returns |
| 2484 | /// A value in linear space. |
| 2485 | /// |
| 2486 | /// @ingroup GPU |
| 2487 | FfxFloat32x2 ffxPQToLinear(FfxFloat32x2 x) |
| 2488 | { |
| 2489 | FfxFloat32x2 p = pow(x, ffxBroadcast2(0.159302)); |
| 2490 | return pow((ffxBroadcast2(0.835938) + ffxBroadcast2(18.8516) * p) / (ffxBroadcast2(1.0) + ffxBroadcast2(18.6875) * p), ffxBroadcast2(78.8438)); |
| 2491 | } |
| 2492 | |
| 2493 | /// Compute a PQ value from a linear value. |
| 2494 | /// |
| 2495 | /// @param [in] value The value to convert to PQ from linear. |
| 2496 | /// |
| 2497 | /// @returns |
| 2498 | /// A value in linear space. |
| 2499 | /// |
| 2500 | /// @ingroup GPU |
| 2501 | FfxFloat32x3 ffxPQToLinear(FfxFloat32x3 x) |
| 2502 | { |
| 2503 | FfxFloat32x3 p = pow(x, ffxBroadcast3(0.159302)); |
| 2504 | return pow((ffxBroadcast3(0.835938) + ffxBroadcast3(18.8516) * p) / (ffxBroadcast3(1.0) + ffxBroadcast3(18.6875) * p), ffxBroadcast3(78.8438)); |
| 2505 | } |
| 2506 | |
| 2507 | /// Compute a linear value from a SRGB value. |
| 2508 | /// |
| 2509 | /// @param [in] value The value to convert to linear from SRGB. |
| 2510 | /// |
| 2511 | /// @returns |
| 2512 | /// A value in SRGB space. |
| 2513 | /// |
| 2514 | /// @ingroup GPU |
| 2515 | FfxFloat32 ffxSrgbToLinear(FfxFloat32 color) |
| 2516 | { |
| 2517 | FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2518 | FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055); |
| 2519 | return clamp(j.x, color * j.y, pow(color, j.z) * k.x + k.y); |
| 2520 | } |
| 2521 | |
| 2522 | /// Compute a linear value from a SRGB value. |
| 2523 | /// |
| 2524 | /// @param [in] value The value to convert to linear from SRGB. |
| 2525 | /// |
| 2526 | /// @returns |
| 2527 | /// A value in SRGB space. |
| 2528 | /// |
| 2529 | /// @ingroup GPU |
| 2530 | FfxFloat32x2 ffxSrgbToLinear(FfxFloat32x2 color) |
| 2531 | { |
| 2532 | FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2533 | FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055); |
| 2534 | return clamp(j.xx, color * j.yy, pow(color, j.zz) * k.xx + k.yy); |
| 2535 | } |
| 2536 | |
| 2537 | /// Compute a linear value from a SRGB value. |
| 2538 | /// |
| 2539 | /// @param [in] value The value to convert to linear from SRGB. |
| 2540 | /// |
| 2541 | /// @returns |
| 2542 | /// A value in SRGB space. |
| 2543 | /// |
| 2544 | /// @ingroup GPU |
| 2545 | FfxFloat32x3 ffxSrgbToLinear(FfxFloat32x3 color) |
| 2546 | { |
| 2547 | FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2548 | FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055); |
| 2549 | return clamp(j.xxx, color * j.yyy, pow(color, j.zzz) * k.xxx + k.yyy); |
| 2550 | } |
| 2551 | |
| 2552 | /// Compute a linear value from a REC.709 value. |
| 2553 | /// |
| 2554 | /// @param [in] color The value to convert to linear from REC.709. |
| 2555 | /// |
| 2556 | /// @returns |
| 2557 | /// A value in linear space. |
| 2558 | /// |
| 2559 | /// @ingroup GPU |
| 2560 | FfxFloat32 ffxLinearFromRec709(FfxFloat32 color) |
| 2561 | { |
| 2562 | FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2563 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099); |
| 2564 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.x), color * j.y, pow(color * k.x + k.y, j.z)); |
| 2565 | } |
| 2566 | |
| 2567 | /// Compute a linear value from a REC.709 value. |
| 2568 | /// |
| 2569 | /// @param [in] color The value to convert to linear from REC.709. |
| 2570 | /// |
| 2571 | /// @returns |
| 2572 | /// A value in linear space. |
| 2573 | /// |
| 2574 | /// @ingroup GPU |
| 2575 | FfxFloat32x2 ffxLinearFromRec709(FfxFloat32x2 color) |
| 2576 | { |
| 2577 | FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2578 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099); |
| 2579 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xx), color * j.yy, pow(color * k.xx + k.yy, j.zz)); |
| 2580 | } |
| 2581 | |
| 2582 | /// Compute a linear value from a REC.709 value. |
| 2583 | /// |
| 2584 | /// @param [in] color The value to convert to linear from REC.709. |
| 2585 | /// |
| 2586 | /// @returns |
| 2587 | /// A value in linear space. |
| 2588 | /// |
| 2589 | /// @ingroup GPU |
| 2590 | FfxFloat32x3 ffxLinearFromRec709(FfxFloat32x3 color) |
| 2591 | { |
| 2592 | FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2593 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099); |
| 2594 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xxx), color * j.yyy, pow(color * k.xxx + k.yyy, j.zzz)); |
| 2595 | } |
| 2596 | |
| 2597 | /// Compute a linear value from a value in a gamma space. |
| 2598 | /// |
| 2599 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2600 | /// |
| 2601 | /// @param [in] color The value to convert to linear in gamma space. |
| 2602 | /// @param [in] power The power value used for the gamma curve. |
| 2603 | /// |
| 2604 | /// @returns |
| 2605 | /// A value in linear space. |
| 2606 | /// |
| 2607 | /// @ingroup GPU |
| 2608 | FfxFloat32 ffxLinearFromGamma(FfxFloat32 color, FfxFloat32 power) |
| 2609 | { |
| 2610 | return pow(color, FfxFloat32(power)); |
| 2611 | } |
| 2612 | |
| 2613 | /// Compute a linear value from a value in a gamma space. |
| 2614 | /// |
| 2615 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2616 | /// |
| 2617 | /// @param [in] color The value to convert to linear in gamma space. |
| 2618 | /// @param [in] power The power value used for the gamma curve. |
| 2619 | /// |
| 2620 | /// @returns |
| 2621 | /// A value in linear space. |
| 2622 | /// |
| 2623 | /// @ingroup GPU |
| 2624 | FfxFloat32x2 ffxLinearFromGamma(FfxFloat32x2 color, FfxFloat32 power) |
| 2625 | { |
| 2626 | return pow(color, ffxBroadcast2(power)); |
| 2627 | } |
| 2628 | |
| 2629 | /// Compute a linear value from a value in a gamma space. |
| 2630 | /// |
| 2631 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2632 | /// |
| 2633 | /// @param [in] color The value to convert to linear in gamma space. |
| 2634 | /// @param [in] power The power value used for the gamma curve. |
| 2635 | /// |
| 2636 | /// @returns |
| 2637 | /// A value in linear space. |
| 2638 | /// |
| 2639 | /// @ingroup GPU |
| 2640 | FfxFloat32x3 ffxLinearFromGamma(FfxFloat32x3 color, FfxFloat32 power) |
| 2641 | { |
| 2642 | return pow(color, ffxBroadcast3(power)); |
| 2643 | } |
| 2644 | |
| 2645 | /// Compute a linear value from a value in a PQ space. |
| 2646 | /// |
| 2647 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2648 | /// |
| 2649 | /// @param [in] value The value to convert to linear in PQ space. |
| 2650 | /// |
| 2651 | /// @returns |
| 2652 | /// A value in linear space. |
| 2653 | /// |
| 2654 | /// @ingroup GPU |
| 2655 | FfxFloat32 ffxLinearFromPQ(FfxFloat32 x) |
| 2656 | { |
| 2657 | FfxFloat32 p = pow(x, FfxFloat32(0.0126833)); |
| 2658 | return pow(ffxSaturate(p - FfxFloat32(0.835938)) / (FfxFloat32(18.8516) - FfxFloat32(18.6875) * p), FfxFloat32(6.27739)); |
| 2659 | } |
| 2660 | |
| 2661 | /// Compute a linear value from a value in a PQ space. |
| 2662 | /// |
| 2663 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2664 | /// |
| 2665 | /// @param [in] value The value to convert to linear in PQ space. |
| 2666 | /// |
| 2667 | /// @returns |
| 2668 | /// A value in linear space. |
| 2669 | /// |
| 2670 | /// @ingroup GPU |
| 2671 | FfxFloat32x2 ffxLinearFromPQ(FfxFloat32x2 x) |
| 2672 | { |
| 2673 | FfxFloat32x2 p = pow(x, ffxBroadcast2(0.0126833)); |
| 2674 | return pow(ffxSaturate(p - ffxBroadcast2(0.835938)) / (ffxBroadcast2(18.8516) - ffxBroadcast2(18.6875) * p), ffxBroadcast2(6.27739)); |
| 2675 | } |
| 2676 | |
| 2677 | /// Compute a linear value from a value in a PQ space. |
| 2678 | /// |
| 2679 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2680 | /// |
| 2681 | /// @param [in] value The value to convert to linear in PQ space. |
| 2682 | /// |
| 2683 | /// @returns |
| 2684 | /// A value in linear space. |
| 2685 | /// |
| 2686 | /// @ingroup GPU |
| 2687 | FfxFloat32x3 ffxLinearFromPQ(FfxFloat32x3 x) |
| 2688 | { |
| 2689 | FfxFloat32x3 p = pow(x, ffxBroadcast3(0.0126833)); |
| 2690 | return pow(ffxSaturate(p - ffxBroadcast3(0.835938)) / (ffxBroadcast3(18.8516) - ffxBroadcast3(18.6875) * p), ffxBroadcast3(6.27739)); |
| 2691 | } |
| 2692 | |
| 2693 | /// Compute a linear value from a value in a SRGB space. |
| 2694 | /// |
| 2695 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2696 | /// |
| 2697 | /// @param [in] value The value to convert to linear in SRGB space. |
| 2698 | /// |
| 2699 | /// @returns |
| 2700 | /// A value in linear space. |
| 2701 | /// |
| 2702 | /// @ingroup GPU |
| 2703 | FfxFloat32 ffxLinearFromSrgb(FfxFloat32 color) |
| 2704 | { |
| 2705 | FfxFloat32x3 j = FfxFloat32x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2706 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.055, 0.055 / 1.055); |
| 2707 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.x), color * j.y, pow(color * k.x + k.y, j.z)); |
| 2708 | } |
| 2709 | |
| 2710 | /// Compute a linear value from a value in a SRGB space. |
| 2711 | /// |
| 2712 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2713 | /// |
| 2714 | /// @param [in] value The value to convert to linear in SRGB space. |
| 2715 | /// |
| 2716 | /// @returns |
| 2717 | /// A value in linear space. |
| 2718 | /// |
| 2719 | /// @ingroup GPU |
| 2720 | FfxFloat32x2 ffxLinearFromSrgb(FfxFloat32x2 color) |
| 2721 | { |
| 2722 | FfxFloat32x3 j = FfxFloat32x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2723 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.055, 0.055 / 1.055); |
| 2724 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xx), color * j.yy, pow(color * k.xx + k.yy, j.zz)); |
| 2725 | } |
| 2726 | |
| 2727 | /// Compute a linear value from a value in a SRGB space. |
| 2728 | /// |
| 2729 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2730 | /// |
| 2731 | /// @param [in] value The value to convert to linear in SRGB space. |
| 2732 | /// |
| 2733 | /// @returns |
| 2734 | /// A value in linear space. |
| 2735 | /// |
| 2736 | /// @ingroup GPU |
| 2737 | FfxFloat32x3 ffxLinearFromSrgb(FfxFloat32x3 color) |
| 2738 | { |
| 2739 | FfxFloat32x3 j = FfxFloat32x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2740 | FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.055, 0.055 / 1.055); |
| 2741 | return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xxx), color * j.yyy, pow(color * k.xxx + k.yyy, j.zzz)); |
| 2742 | } |
| 2743 | |
| 2744 | /// A remapping of 64x1 to 8x8 imposing rotated 2x2 pixel quads in quad linear. |
| 2745 | /// |
| 2746 | /// 543210 |
| 2747 | /// ====== |
| 2748 | /// ..xxx. |
| 2749 | /// yy...y |
| 2750 | /// |
| 2751 | /// @param [in] a The input 1D coordinates to remap. |
| 2752 | /// |
| 2753 | /// @returns |
| 2754 | /// The remapped 2D coordinates. |
| 2755 | /// |
| 2756 | /// @ingroup GPU |
| 2757 | FfxUInt32x2 ffxRemapForQuad(FfxUInt32 a) |
| 2758 | { |
| 2759 | return FfxUInt32x2(bitfieldExtract(a, 1u, 3u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), a, 1u)); |
| 2760 | } |
| 2761 | |
| 2762 | /// A helper function performing a remap 64x1 to 8x8 remapping which is necessary for 2D wave reductions. |
| 2763 | /// |
| 2764 | /// The 64-wide lane indices to 8x8 remapping is performed as follows: |
| 2765 | /// |
| 2766 | /// 00 01 08 09 10 11 18 19 |
| 2767 | /// 02 03 0a 0b 12 13 1a 1b |
| 2768 | /// 04 05 0c 0d 14 15 1c 1d |
| 2769 | /// 06 07 0e 0f 16 17 1e 1f |
| 2770 | /// 20 21 28 29 30 31 38 39 |
| 2771 | /// 22 23 2a 2b 32 33 3a 3b |
| 2772 | /// 24 25 2c 2d 34 35 3c 3d |
| 2773 | /// 26 27 2e 2f 36 37 3e 3f |
| 2774 | /// |
| 2775 | /// @param [in] a The input 1D coordinate to remap. |
| 2776 | /// |
| 2777 | /// @returns |
| 2778 | /// The remapped 2D coordinates. |
| 2779 | /// |
| 2780 | /// @ingroup GPU |
| 2781 | FfxUInt32x2 ffxRemapForWaveReduction(FfxUInt32 a) |
| 2782 | { |
| 2783 | return FfxUInt32x2(bitfieldInsertMask(bitfieldExtract(a, 2u, 3u), a, 1u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), bitfieldExtract(a, 1u, 2u), 2u)); |
| 2784 | } |