|
|
|
|
|
|
return (x < 1.0) ? poly : HALF_PI - poly; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: this intrinsic is unavailable outside compute. This is a Unity shader compiler bug. |
|
|
|
#if (SHADER_TARGET >= 50) && (SHADER_STAGE_COMPUTE != 0) |
|
|
|
uint FastLog2(uint x) |
|
|
|
{ |
|
|
|
return firstbithigh(x) – 1u; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// 4 VGPR, 16 FR (12 FR, 1 QR), 2 scalar |
|
|
|
// input [-infinity, infinity] and output [-PI/2, PI/2] |
|
|
|
float FastATan(float x) |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Same as smoothstep except it assume 0, 1 interval for x |
|
|
|
float Smoothstep01(float x) |
|
|
|
{ |
|
|
|
return x * x * (3.0 - (2.0 * x)); |
|
|
|
} |
|
|
|
|
|
|
|
static const float3x3 k_identity3x3 = {1.0, 0.0, 0.0, |
|
|
|
0.0, 1.0, 0.0, |
|
|
|
0.0, 0.0, 1.0}; |
|
|
|
|
|
|
|
static const float4x4 k_identity4x4 = {1.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 1.0, 0.0, 0.0, |
|
|
|
0.0, 0.0, 1.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0}; |
|
|
|
|
|
|
|
// Using pow often result to a warning like this |
|
|
|
// "pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them" |
|
|
|
|
|
|
float3 Orthonormalize(float3 tangent, float3 normal) |
|
|
|
{ |
|
|
|
return normalize(tangent - dot(tangent, normal) * normal); |
|
|
|
} |
|
|
|
|
|
|
|
// Same as smoothstep except it assume 0, 1 interval for x |
|
|
|
float Smoothstep01(float x) |
|
|
|
{ |
|
|
|
return x * x * (3.0 - (2.0 * x)); |
|
|
|
} |
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------- |
|
|
|
|
|
|
// ---------------------------------------------------------------------------- |
|
|
|
// Space transformations |
|
|
|
// ---------------------------------------------------------------------------- |
|
|
|
|
|
|
|
static const float3x3 k_identity3x3 = {1, 0, 0, |
|
|
|
0, 1, 0, |
|
|
|
0, 0, 1}; |
|
|
|
|
|
|
|
static const float4x4 k_identity4x4 = {1, 0, 0, 0, |
|
|
|
0, 1, 0, 0, |
|
|
|
0, 0, 1, 0, |
|
|
|
0, 0, 0, 1}; |
|
|
|
|
|
|
|
// Use case examples: |
|
|
|
// (position = positionCS) => (clipSpaceTransform = use default) |
|
|
|