浏览代码

Add ConstructFloat(int m)

/feature-ReflectionProbeFit
Evgenii Golubev 7 年前
当前提交
0f37cb98
共有 1 个文件被更改,包括 14 次插入9 次删除
  1. 23
      ScriptableRenderPipeline/Core/ShaderLibrary/Random.hlsl

23
ScriptableRenderPipeline/Core/ShaderLibrary/Random.hlsl


return JenkinsHash(v.x ^ JenkinsHash(v.y) ^ JenkinsHash(v.z) ^ JenkinsHash(v.w));
}
// Construct a float with half-open range [0:1] using low 23 bits.
// Construct a float with half-open range [0, 1) using low 23 bits.
float ConstructFloat(uint m) {
const uint ieeeMantissa = 0x007FFFFFu; // Binary FP32 mantissa bitmask
const uint ieeeOne = 0x3F800000u; // 1.0 in FP32 IEEE
float ConstructFloat(int m) {
const int ieeeMantissa = 0x007FFFFF; // Binary FP32 mantissa bitmask
const int ieeeOne = 0x3F800000; // 1.0 in FP32 IEEE
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
float f = asfloat(m); // Range [1, 2)
return f - 1; // Range [0, 1)
}
float f = asfloat(m); // Range [1:2]
return f - 1; // Range [0:1]
float ConstructFloat(uint m)
{
return ConstructFloat(asint(m));
// Pseudo-random value in half-open range [0:1]. The distribution is reasonably uniform.
// Pseudo-random value in half-open range [0, 1). The distribution is reasonably uniform.
// Ref: https://stackoverflow.com/a/17479300
float GenerateHashedRandomFloat(uint x)
{

正在加载...
取消
保存