浏览代码

Save 2x VALU

Optimize ComputeNormalizedDeviceCoordinates() and ComputeClipSpacePosition()
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
01cf9986
共有 1 个文件被更改,包括 13 次插入5 次删除
  1. 18
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl

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


float2 ComputeNormalizedDeviceCoordinates(float3 position, float4x4 clipSpaceTransform = k_identity4x4)
{
float4 positionCS = mul(clipSpaceTransform, float4(position, 1.0));
float2 positionNDC = positionCS.xy * (rcp(positionCS.w) * 0.5) + 0.5;
positionNDC.y = 1.0 - positionNDC.y;
// Our clip space is correct, but the NDC is flipped.
// Conceptually, it should be (positionNDC.y = 1.0 - positionNDC.y), but this is more efficient.
positionCS.y = -positionCS.y;
return positionNDC;
return positionCS.xy * (rcp(positionCS.w) * 0.5) + 0.5;
float4 positionCS = float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
positionNDC.y = 1.0 - positionNDC.y;
// Our clip space is correct, but the NDC is flipped.
// Conceptually, it should be (positionNDC.y = 1.0 - positionNDC.y), but this is more efficient.
positionCS.y = -positionCS.y;
return float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
return positionCS;
}
float3 ComputeViewSpacePosition(float2 positionNDC, float deviceDepth, float4x4 invProjMatrix)

正在加载...
取消
保存