浏览代码

Optimize DecodeLogarithmicDepthGeneralized()

/main
Evgenii Golubev 7 年前
当前提交
b587ca91
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 6
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
  2. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs

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


// saturate(d) to clamp the output of the function to the [n, f] range.
// z = 1/c * (pow(c * (f - n) + 1, d) - 1) + n
// = 1/c * pow(c * (f - n) + 1, d) + n - 1/c
// = L * pow(M, d) + N
// = 1/c * exp2(d * log2(c * (f - n) + 1)) + (n - 1/c)
// = L * exp2(d * M) + N
// Use abs() to avoid the compiler warning.
return decodingParams.x * pow(abs(decodingParams.y), d) + decodingParams.z;
return decodingParams.x * exp2(d * decodingParams.y) + decodingParams.z;
}
// 'z' is the view-space Z position (linear depth).

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


// Since a single voxel corresponds to a tile (e.g. 8x8) of pixels,
// the VBuffer can potentially extend past the boundaries of the viewport.
// The function returns the fraction of the {width, height} of the VBuffer visible on screen.
// Note: for performance reasons, scale is unused (implicitly 1). The error is typically under 1%.
// Note: for performance reasons, the scale is unused (implicitly 1). The error is typically under 1%.
static Vector2 ComputeVBufferResolutionAndScale(VolumetricLightingPreset preset,
int screenWidth, int screenHeight,
ref int w, ref int h, ref int d)

float n = nearPlane;
float f = farPlane;
depthParams.x = Mathf.Log(c, 2) * (1.0f / Mathf.Log(c * (f - n) + 1, 2));
depthParams.x = Mathf.Log(c, 2) * depthParams.y;
depthParams.z = n - 1.0f / c; // Same
depthParams.w = 0.0f;

float f = farPlane;
depthParams.x = 1.0f / c;
depthParams.y = c * (f - n) + 1;
depthParams.y = Mathf.Log(c * (f - n) + 1, 2);
depthParams.z = n - 1.0f / c; // Same
depthParams.w = 0.0f;

正在加载...
取消
保存