浏览代码

Update FastSign() and implement FastMulBySignOf()

/main
Evgenii Golubev 7 年前
当前提交
f62c83f5
共有 1 个文件被更改,包括 14 次插入4 次删除
  1. 18
      ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl

18
ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl


// PositivePow remove this warning when you know the value is positive and avoid inf/NAN.
TEMPLATE_2_FLT(PositivePow, base, power, return pow(max(abs(base), FLT_EPS), power))
// Ref: https://twitter.com/SebAaltonen/status/878250919879639040
// 2 mads (mad_sat and mad), faster than regular sign
float FastSign(float x)
// Returns -1 for negative numbers and -0, 1 for positive numbers and +0.
// This behavior is different from the Signum function sign(), which returns 0 for 0.
// 2x VALU.
float FastSign(float s)
return saturate(x * FLT_MAX) * 2.0 - 1.0;
uint negZero = 0x80000000u;
uint signBit = negZero & asuint(s);
return asfloat(signBit | asuint(1.0));
}
// Multiplies 'x' by the sign of 's'. Treats -0 as 0.
// 2x VALU compared to 3x VALU of (x * FastSign(s)).
float FastMulBySignOf(float x, float s)
{
return (s >= 0) ? x : -x;
}
// Orthonormalizes the tangent frame using the Gram-Schmidt process.

正在加载...
取消
保存