浏览代码

Fix the raw depth from the depth offset

/Branch_Batching2
Evgenii Golubev 7 年前
当前提交
ea306870
共有 3 个文件被更改,包括 16 次插入7 次删除
  1. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  2. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
  3. 10
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord);
#ifdef _DEPTHOFFSET_ON
ApplyDepthOffsetPositionInput(V, depthOffset, _ViewProjMatrix, posInput);
float3 camDirWS = GetCameraForwardDirInWorldSpace();
ApplyDepthOffsetPositionInput(camDirWS, depthOffset, _ViewProjMatrix, posInput);
#endif
// We perform the conversion to world of the normalTS outside of the GetSurfaceData

float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord);
#ifdef _DEPTHOFFSET_ON
ApplyDepthOffsetPositionInput(V, depthOffset, _ViewProjMatrix, posInput);
float3 camDirWS = GetCameraForwardDirInWorldSpace();
ApplyDepthOffsetPositionInput(camDirWS, depthOffset, _ViewProjMatrix, posInput);
#endif
SurfaceData surfaceData0, surfaceData1, surfaceData2, surfaceData3;

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


return normalize(V);
}
// Returns the forward direction of the current camera in world space.
float3 GetCameraForwardDirInWorldSpace()
{
float4x4 viewMat = GetWorldToViewMatrix();
return -viewMat[2].xyz;
}
float3x3 CreateWorldToTangent(float3 normal, float3 tangent, float flipSign)
{
// For odd-negative scale transforms we need to flip the sign

10
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


// For information. In Unity Depth is always in range 0..1 (even on OpenGL) but can be reversed.
// It may be necessary to flip the Y axis as the origin of the screen-space coordinate system
// of Direct3D is at the top left corner of the screen, with the Y axis pointing downwards.
void UpdatePositionInput(float depthRaw, float4x4 invViewProjMatrix, float4x4 ViewProjMatrix,
void UpdatePositionInput(float depthRaw, float4x4 invViewProjMatrix, float4x4 viewProjMatrix,
inout PositionInputs posInput, bool flipY = false)
{
posInput.depthRaw = depthRaw;

posInput.positionWS = hpositionWS.xyz / hpositionWS.w;
// The compiler should optimize this (less expensive than reconstruct depth VS from depth buffer)
posInput.depthVS = mul(ViewProjMatrix, float4(posInput.positionWS, 1.0)).w;
posInput.depthVS = mul(viewProjMatrix, float4(posInput.positionWS, 1.0)).w;
}
// It may be necessary to flip the Y axis as the origin of the screen-space coordinate system

return positionVS.xyz / positionVS.w;
}
// 'depthOffsetVS' is in the opposite direction of the view vector 'V', e.i. away from the camera.
void ApplyDepthOffsetPositionInput(float3 V, float depthOffsetVS, float4x4 viewProjMatrix, inout PositionInputs posInput)
// 'depthOffsetVS' is always along the forward direction 'camDirWS' pointing away from the camera.
void ApplyDepthOffsetPositionInput(float3 camDirWS, float depthOffsetVS, float4x4 viewProjMatrix, inout PositionInputs posInput)
posInput.positionWS += depthOffsetVS * -V; // opposite to V
posInput.positionWS += depthOffsetVS * camDirWS;
float4 positionCS = mul(viewProjMatrix, float4(posInput.positionWS, 1.0));
posInput.depthRaw = positionCS.z / positionCS.w;

正在加载...
取消
保存