This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cmath> | |
#include <vector> | |
// inverting piecewise linear functions | |
float InverseLinear(float yStart, float yEnd, float y) | |
{ | |
return (y - yStart) / (yEnd - yStart); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sorts an array in ascending order (arraySize muste be a power of two) | |
void BitonicSort(uint32_t *array, uint32_t arraySize) | |
{ | |
for (uint32_t d2 = 1u; d2 < arraySize; d2*= 2u) { | |
for (uint32_t d1 = d2; d1 >= 1u; d1/= 2u) { | |
const uint32_t mask = (0xFFFFFFFEu * d1); | |
#pragma omp parallel for | |
for (uint32_t i = 0; i < (arraySize / 2); ++i) { | |
const uint32_t i1 = ((i << 1) & mask) | (i & ~(mask >> 1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Helper function: sample the visible hemisphere from a spherical cap | |
vec3 SampleVndf_Hemisphere(vec2 u, vec3 wi) | |
{ | |
// sample a spherical cap in (-wi.z, 1] | |
float phi = 2.0f * M_PI * u.x; | |
float z = fma((1.0f - u.y), (1.0f + wi.z), -wi.z); | |
float sinTheta = sqrt(clamp(1.0f - z * z, 0.0f, 1.0f)); | |
float x = sinTheta * cos(phi); | |
float y = sinTheta * sin(phi); | |
vec3 c = vec3(x, y, z); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t BitReverse(uint8_t x) | |
{ | |
x = ((x & 0x0F) << 4) | ((x & 0xF0) >> 4); | |
x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2); | |
x = ((x & 0x55) << 1) | ((x & 0xAA) >> 1); | |
return x; | |
} | |
uint16_t BitReverse(uint16_t x) |