Created
May 23, 2020 12:44
-
-
Save h3r/bcbbf0ec7dc1a920f26d7eab51057875 to your computer and use it in GitHub Desktop.
HLSL Sequence Generators
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
float2 hammersley(uint index) { | |
// Compute Hammersley sequence | |
// TODO: these should come from uniforms | |
// TODO: we should do this with logical bit operations | |
const uint numSamples = uint(IBL_INTEGRATION_IMPORTANCE_SAMPLING_COUNT); | |
const uint numSampleBits = uint(log2(float(numSamples))); | |
const float invNumSamples = 1.0 / float(numSamples); | |
uint i = uint(index); | |
uint t = i; | |
uint bits = 0u; | |
for (uint j = 0u; j < numSampleBits; j++) { | |
bits = bits * 2u + (t - (2u * (t / 2u))); | |
t /= 2u; | |
} | |
return float2(float(i), float(bits)) * invNumSamples; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment