Skip to content

Instantly share code, notes, and snippets.

@h3r
Created May 23, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3r/bcbbf0ec7dc1a920f26d7eab51057875 to your computer and use it in GitHub Desktop.
Save h3r/bcbbf0ec7dc1a920f26d7eab51057875 to your computer and use it in GitHub Desktop.
HLSL Sequence Generators
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