浏览代码

PR feedback.

Renamed zbias function and cleaned up previous frame normal transformation
/main
Raymond Graham 7 年前
当前提交
9cb6a586
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 20
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl

20
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl


#define VARYINGS_NEED_PASS
#include "VertMesh.hlsl"
void PositionZBias(VaryingsToPS input)
// Transforms normal from object to world space
float3 TransformPreviousObjectToWorldNormal(float3 normalOS)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return normalize(mul((float3x3)unity_MatrixPreviousM, normalOS));
#else
// Normal need to be multiply by inverse transpose
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(normalOS, (float3x3)unity_MatrixPreviousMI));
#endif
}
void VelocityPositionZBias(VaryingsToPS input)
{
#if defined(UNITY_REVERSED_Z)
input.vmesh.positionCS.z -= unity_MotionVectorsParams.z * input.vmesh.positionCS.w;

varyingsType.vmesh = VertMesh(inputMesh);
#if !defined(TESSELLATION_ON)
PositionZBias(varyingsType);
VelocityPositionZBias(varyingsType);
#endif
// It is not possible to correctly generate the motion vector for tesselated geometry as tessellation parameters can change

//Need to apply any vertex animation to the previous worldspace position, if we want it to show up in the velocity buffer
float3 previousPositionWS = mul(unity_MatrixPreviousM, unity_MotionVectorsParams.x ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)).xyz;
#ifdef ATTRIBUTES_NEED_NORMAL
float3 normalWS = normalize(mul(inputMesh.normalOS, (float3x3)unity_MatrixPreviousMI));
float3 normalWS = TransformPreviousObjectToWorldNormal(inputMesh.normalOS);
#else
float3 normalWS = float3(0.0, 0.0, 0.0);
#endif

output.vmesh = VertMeshTesselation(input.vmesh);
PositionZBias(output);
VelocityPositionZBias(output);
output.vpass.positionCS = input.vpass.positionCS;
output.vpass.previousPositionCS = input.vpass.previousPositionCS;

正在加载...
取消
保存