Files
Test/Library/PackageCache/com.unity.render-pipelines.core@13460d8ea9e5/Runtime/Sampling/PseudoRandom.hlsl
T
2026-11-01 23:39:55 +02:00

72 lines
1.4 KiB
HLSL

#ifndef _SAMPLING_PSEUDORANDOM_HLSL_
#define _SAMPLING_PSEUDORANDOM_HLSL_
#include "Common.hlsl"
#include "Hashes.hlsl"
// Xor shift PRNG
struct QrngXorShift
{
uint state;
void Init(uint2 pixelCoord, uint startSampleIndex)
{
state = PixelHash(pixelCoord, startSampleIndex);
}
void Init(uint seed, uint startSampleIndex)
{
state = seed;
}
float GetSample()
{
state = XorShift32(state);
return UintToFloat01(state);
}
float2 GetSample(uint dimension)
{
return float2(GetSample(), GetSample());
}
void NextSample()
{
}
};
// From paper: "Hash Functions for GPU Rendering" by Jarzynski & Olano)
struct QrngPcg4D
{
uint4 state;
void Init(uint2 pixelCoord, uint startSampleIndex)
{
// Seed for PCG uses a sequential sample number in 4th channel, which increments on every RNG call and starts from 0
state = uint4(pixelCoord, startSampleIndex, 0);
}
void Init(uint seed, uint startSampleIndex)
{
state = uint4(seed, 1, startSampleIndex, 0);
}
float GetSample()
{
state.w++;
return UintToFloat01(Pcg4d(state).x);
}
float2 GetSample(uint dimension)
{
return float2(GetSample(), GetSample());
}
void NextSample()
{
state.z++;
}
};
#endif // _SAMPLING_PSEUDORANDOM_HLSL_