浏览代码

Slightly faster octahedron packing and ViewReflectionNormal

/feature-ReflectionProbeFit
runes 7 年前
当前提交
ba207379
共有 2 个文件被更改,包括 14 次插入8 次删除
  1. 3
      ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl
  2. 19
      ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl

3
ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl


NdotV = dot(N, V);
N = (NdotV >= 0.0) ? N : (N - 2.0 * NdotV * V);
// N = (NdotV >= 0.0) ? N : (N - 2.0 * NdotV * V);
N += (2.0 * saturate(-NdotV)) * V;
NdotV = abs(NdotV);
return N;

19
ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl


// Ref: http://jcgt.org/published/0003/02/01/paper.pdf
// Encode with Oct, this function work with any size of output
// return float between [-1, 1]
float2 PackNormalOctEncode(float3 n)
{
float l1norm = dot(abs(n), 1.0);
float2 res0 = n.xy * (1.0 / l1norm);
float2 val = 1.0 - abs(res0.yx);
return (n.zz < float2(0.0, 0.0) ? (res0 >= 0.0 ? val : -val) : res0);
float2 PackNormalOctEncode(float3 n)
{
//float l1norm = dot(abs(n), 1.0);
//float2 res0 = n.xy * (1.0 / l1norm);
//float2 val = 1.0 - abs(res0.yx);
//return (n.zz < float2(0.0, 0.0) ? (res0 >= 0.0 ? val : -val) : res0);
// Optimized version of above code:
n *= rcp(dot(abs(n), 1.0));
float t = saturate(-n.z);
return n.xy + (n.xy >= 0.0 ? t : -t);
}
float3 UnpackNormalOctEncode(float2 f)

正在加载...
取消
保存