浏览代码

Update TEMPLATE_X_REAL macro to use FLT and HALF

/feature-ReflectionProbeFit
sebastienlagarde 7 年前
当前提交
ee86a903
共有 3 个文件被更改,包括 47 次插入39 次删除
  1. 24
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  2. 20
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonLighting.hlsl
  3. 42
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Macros.hlsl

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


#define REAL_MIN HALF_MIN
#define REAL_MAX HALF_MAX
#define TEMPLATE_1_REAL TEMPLATE_1_HALF
#define TEMPLATE_2_REAL TEMPLATE_2_HALF
#define TEMPLATE_3_REAL TEMPLATE_3_HALF
#else

#define REAL_MIN FLT_MIN
#define REAL_MAX FLT_MAX
#define TEMPLATE_1_REAL TEMPLATE_1_FLT
#define TEMPLATE_2_REAL TEMPLATE_2_FLT
#define TEMPLATE_3_REAL TEMPLATE_3_FLT
#endif
#endif // SHADER_API_MOBILE
#endif // #ifndef real
// Include language header
#if defined(SHADER_API_D3D11)

#ifndef INTRINSIC_WAVEREADFIRSTLANE
// Warning: for correctness, the argument must have the same value across the wave!
TEMPLATE_1_FLT(WaveReadFirstLane, scalarValue, return scalarValue)
TEMPLATE_1_REAL(WaveReadFirstLane, scalarValue, return scalarValue)
TEMPLATE_1_INT(WaveReadFirstLane, scalarValue, return scalarValue)
#endif

#endif // INTRINSIC_MAD24
#ifndef INTRINSIC_MINMAX3
TEMPLATE_3_FLT(Min3, a, b, c, return min(min(a, b), c))
TEMPLATE_3_REAL(Min3, a, b, c, return min(min(a, b), c))
TEMPLATE_3_FLT(Max3, a, b, c, return max(max(a, b), c))
TEMPLATE_3_REAL(Max3, a, b, c, return max(max(a, b), c))
TEMPLATE_3_INT(Max3, a, b, c, return max(max(a, b), c))
#endif // INTRINSIC_MINMAX3

}
// Square functions for cleaner code
TEMPLATE_1_FLT(Sq, x, return x * x)
TEMPLATE_1_REAL(Sq, x, return x * x)
TEMPLATE_1_INT(Sq, x, return x * x)
// Input [0, 1] and output [0, PI/2]

// 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"
// 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))
TEMPLATE_2_REAL(PositivePow, base, power, return pow(max(abs(base), FLT_EPS), power))
// Computes (FastSign(s) * x) using 2x VALU.
// See the comment about FastSign() below.

{
uint negZero = 0x80000000u;
uint signBit = negZero & asuint(s);
return asfloat(signBit ^ asuint(float(x))); // Does not work work with half, so have to cast
return asfloat(signBit ^ asuint(x));
}
#else
return (s >= 0) ? x : -x;

posInput.positionNDC = positionSS;
#if SHADER_STAGE_COMPUTE
// In case of compute shader an extra offset is added to the screenPos to shift the integer position to pixel center.
// In case of compute shader an extra half offset is added to the screenPos to shift the integer position to pixel center.
posInput.positionNDC.xy += float2(0.5, 0.5);
#endif
posInput.positionNDC *= invScreenSize;

20
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonLighting.hlsl


#define UNITY_COMMON_LIGHTING_INCLUDED
// These clamping function to max of floating point 16 bit are use to prevent INF in code in case of extreme value
real ClampToFloat16Max(real value)
{
return min(value, HALF_MAX);
}
real2 ClampToFloat16Max(real2 value)
{
return min(value, HALF_MAX);
}
real3 ClampToFloat16Max(real3 value)
{
return min(value, HALF_MAX);
}
real4 ClampToFloat16Max(real4 value)
{
return min(value, HALF_MAX);
}
TEMPLATE_1_FLT(ClampToFloat16Max, value, min(value, HALF_MAX))
// Ligthing convention
// Light direction is oriented backward (-Z). i.e in shader code, light direction is -lightData.forward

42
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Macros.hlsl


#define UINT_MAX 0xFFFFFFFFu
#define TEMPLATE_1_FLT(FunctionName, Parameter1, FunctionBody) \
real FunctionName(real Parameter1) { FunctionBody; } \
real2 FunctionName(real2 Parameter1) { FunctionBody; } \
real3 FunctionName(real3 Parameter1) { FunctionBody; } \
real4 FunctionName(real4 Parameter1) { FunctionBody; }
float FunctionName(float Parameter1) { FunctionBody; } \
float2 FunctionName(float2 Parameter1) { FunctionBody; } \
float3 FunctionName(float3 Parameter1) { FunctionBody; } \
float4 FunctionName(float4 Parameter1) { FunctionBody; }
#define TEMPLATE_1_HALF(FunctionName, Parameter1, FunctionBody) \
half FunctionName(half Parameter1) { FunctionBody; } \
half2 FunctionName(half2 Parameter1) { FunctionBody; } \
half3 FunctionName(half3 Parameter1) { FunctionBody; } \
half4 FunctionName(half4 Parameter1) { FunctionBody; }
#ifdef SHADER_API_GLES
#define TEMPLATE_1_INT(FunctionName, Parameter1, FunctionBody) \

#endif
#define TEMPLATE_2_FLT(FunctionName, Parameter1, Parameter2, FunctionBody) \
real FunctionName(real Parameter1, real Parameter2) { FunctionBody; } \
real2 FunctionName(real2 Parameter1, real2 Parameter2) { FunctionBody; } \
real3 FunctionName(real3 Parameter1, real3 Parameter2) { FunctionBody; } \
real4 FunctionName(real4 Parameter1, real4 Parameter2) { FunctionBody; }
float FunctionName(float Parameter1, float Parameter2) { FunctionBody; } \
float2 FunctionName(float2 Parameter1, float2 Parameter2) { FunctionBody; } \
float3 FunctionName(float3 Parameter1, float3 Parameter2) { FunctionBody; } \
float4 FunctionName(float4 Parameter1, float4 Parameter2) { FunctionBody; }
#define TEMPLATE_2_HALF(FunctionName, Parameter1, Parameter2, FunctionBody) \
half FunctionName(half Parameter1, half Parameter2) { FunctionBody; } \
half2 FunctionName(half2 Parameter1, half2 Parameter2) { FunctionBody; } \
half3 FunctionName(half3 Parameter1, half3 Parameter2) { FunctionBody; } \
half4 FunctionName(half4 Parameter1, half4 Parameter2) { FunctionBody; }
#ifdef SHADER_API_GLES

#endif
#define TEMPLATE_3_FLT(FunctionName, Parameter1, Parameter2, Parameter3, FunctionBody) \
real FunctionName(real Parameter1, real Parameter2, real Parameter3) { FunctionBody; } \
real2 FunctionName(real2 Parameter1, real2 Parameter2, real2 Parameter3) { FunctionBody; } \
real3 FunctionName(real3 Parameter1, real3 Parameter2, real3 Parameter3) { FunctionBody; } \
real4 FunctionName(real4 Parameter1, real4 Parameter2, real4 Parameter3) { FunctionBody; }
float FunctionName(float Parameter1, float Parameter2, float Parameter3) { FunctionBody; } \
float2 FunctionName(float2 Parameter1, float2 Parameter2, float2 Parameter3) { FunctionBody; } \
float3 FunctionName(float3 Parameter1, float3 Parameter2, float3 Parameter3) { FunctionBody; } \
float4 FunctionName(float4 Parameter1, float4 Parameter2, float4 Parameter3) { FunctionBody; }
#define TEMPLATE_3_HALF(FunctionName, Parameter1, Parameter2, Parameter3, FunctionBody) \
half FunctionName(half Parameter1, half Parameter2, half Parameter3) { FunctionBody; } \
half2 FunctionName(half2 Parameter1, half2 Parameter2, half2 Parameter3) { FunctionBody; } \
half3 FunctionName(half3 Parameter1, half3 Parameter2, half3 Parameter3) { FunctionBody; } \
half4 FunctionName(half4 Parameter1, half4 Parameter2, half4 Parameter3) { FunctionBody; }
#ifdef SHADER_API_GLES
#define TEMPLATE_3_INT(FunctionName, Parameter1, Parameter2, Parameter3, FunctionBody) \

正在加载...
取消
保存