浏览代码

Replace FastMulBySignOf() with CopySign()

/feature-ReflectionProbeFit
Evgenii Golubev 7 年前
当前提交
2403166d
共有 3 个文件被更改,包括 8 次插入8 次删除
  1. 12
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  2. 2
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl
  3. 2
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl

12
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl


// PositivePow remove this warning when you know the value is positive and avoid inf/NAN.
TEMPLATE_2_REAL(PositivePow, base, power, return pow(max(abs(base), FLT_EPS), power))
// Computes (FastSign(s) * x) using 2x VALU.
// Composes a floating point value with the magnitude of 'x' and the sign of 's'.
float FastMulBySignOf(float s, float x, bool ignoreNegZero = true)
float CopySign(float x, float s, bool ignoreNegZero = true)
return (s >= 0) ? x : -x;
return (s >= 0) ? abs(x) : -abs(x);
return asfloat(signBit ^ asuint(x));
return asfloat(signBit | asuint(abs(x)));
return (s >= 0) ? x : -x;
return (s >= 0) ? abs(x) : -abs(x);
#endif
}

// Note that the sign() function in HLSL implements signum, which returns 0 for 0.
float FastSign(float s, bool ignoreNegZero = true)
{
return FastMulBySignOf(s, 1.0, ignoreNegZero);
return CopySign(1.0, s, ignoreNegZero);
}
// Orthonormalizes the tangent frame using the Gram-Schmidt process.

2
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl


bool SolveQuadraticEquation(float a, float b, float c, out float2 roots)
{
float d = b * b - 4 * a * c;
float q = -0.5 * (b + FastMulBySignOf(b, sqrt(d)));
float q = -0.5 * (b + CopySign(sqrt(d), b));
roots = float2(q / a, c / q);
return (d >= 0);

2
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl


// Left side of the 2:1 rectangle for the negative hemisphere, right otherwise.
// We also correct the aspect ratio from 2:1 to 1:1.
real s = (p.z >= 0) ? 0.5 : -0.5;
real s = CopySign(0.5, p.z);
return real2(s * r, g);
}

正在加载...
取消
保存