浏览代码

Remove code for Motion vectors in GBuffer as it don't fit our need (and don't work)

- Remove ShaderConfig.s_VelocityInGbuffer
- Remove all code for velocity in GBuffer
- added enableObjectMotionVectors in FrameSettings
- Update unity_MotionVectorsParams.y (ForceNoMotion) usage
/feature-ReflectionProbeFit
sebastienlagarde 7 年前
当前提交
f3665ff6
共有 9 个文件被更改,包括 44 次插入100 次删除
  1. 6
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 42
      ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/FrameSettings.cs
  6. 13
      ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs
  7. 1
      ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
  9. 51
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl

6
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


SerializedProperty m_SpotCookieSize;
SerializedProperty m_PointCookieSize;
SerializedProperty m_ReflectionCubemapSize;
SerializedProperty m_ReflectionCacheCompressed;
// Commented out until we have proper realtime BC6H compression
//SerializedProperty m_ReflectionCacheCompressed;
// FrameSettings
// LightLoop settings

m_SpotCookieSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.spotCookieSize);
m_PointCookieSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.pointCookieSize);
m_ReflectionCubemapSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCubemapSize);
m_ReflectionCacheCompressed = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCacheCompressed);
// Commented out until we have proper realtime BC6H compression
//m_ReflectionCacheCompressed = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCacheCompressed);
// FrameSettings
// LightLoop settings

19
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


cmd.GetTemporaryRT(HDShaderIDs._ShadowMaskTexture, width, height, 0, FilterMode.Point, Builtin.GetShadowMaskBufferFormat(), Builtin.GetShadowMaskBufferReadWrite());
m_RTIDs[gbufferCount++] = new RenderTargetIdentifier(HDShaderIDs._ShadowMaskTexture);
}
if (ShaderConfig.s_VelocityInGbuffer == 1)
{
// If velocity is in GBuffer then it is in the last RT. Assign a different name to it.
cmd.ReleaseTemporaryRT(HDShaderIDs._VelocityTexture);
cmd.GetTemporaryRT(HDShaderIDs._VelocityTexture, width, height, 0, FilterMode.Point, Builtin.GetVelocityBufferFormat(), Builtin.GetVelocityBufferReadWrite());
m_RTIDs[gbufferCount++] = new RenderTargetIdentifier(HDShaderIDs._VelocityTexture);
}
}
public RenderTargetIdentifier[] GetGBuffers()

void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.renderSettings.enableMotionVectors)
if (!m_FrameSettings.renderSettings.enableMotionVectors || !m_FrameSettings.renderSettings.enableObjectMotionVectors)
// If opaque velocity have been render during GBuffer no need to render it here
// TODO: Currently we can't render velocity vector into GBuffer, neither during forward pass (in case of forward opaque), so it is always a separate pass
// Note that we if we have forward only opaque with deferred rendering, it must also support the rendering of velocity vector to be correct with following test.
if ((ShaderConfig.s_VelocityInGbuffer == 1))
{
Debug.LogWarning("Velocity in Gbuffer is currently not supported");
return;
}
// These flags are still required in SRP or the engine won't compute previous model matrices...
// If the flag hasn't been set yet on this camera, motion vectors will skip a frame.
hdcam.camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;

42
ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl


#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target2
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target3
#endif
#else
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target2
#endif
#endif
#elif GBUFFERMATERIAL_COUNT == 3

#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target3
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target4
#endif
#else
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target3
#endif
#endif
#elif GBUFFERMATERIAL_COUNT == 4

#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target4
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target5
#endif
#else
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target4
#endif
#endif
#elif GBUFFERMATERIAL_COUNT == 5

#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target5
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target6
#endif
#else
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target5
#endif
#endif
#elif GBUFFERMATERIAL_COUNT == 6

#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target6
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target7
#endif
#else
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target6
#endif
#endif
#endif

#else
#define OUTPUT_GBUFFER_SHADOWMASK(NAME)
#define ENCODE_SHADOWMASK_INTO_GBUFFER(SHADOWMASK, NAME)
#endif
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define ENCODE_VELOCITY_INTO_GBUFFER(VELOCITY, NAME) EncodeVelocity(VELOCITY, NAME)
#else
#define OUTPUT_GBUFFER_VELOCITY(NAME)
#define ENCODE_VELOCITY_INTO_GBUFFER(VELOCITY, NAME)
#endif
#endif // #ifdef GBUFFERMATERIAL_COUNT

4
ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl


{
// This test on define is required to remove warning of divide by 0 when initializing empty struct
// TODO: Add forward opaque MRT case...
#if (SHADERPASS == SHADERPASS_VELOCITY) || (SHADERPASS == SHADERPASS_GBUFFER && SHADEROPTIONS_VELOCITY_IN_GBUFFER)
#if (SHADERPASS == SHADERPASS_VELOCITY)
return (positionCS.xy - previousPositionCS.xy) * unity_MotionVectorsParams.y;
return (positionCS.xy - previousPositionCS.xy);
#else
return float2(0.0, 0.0);
#endif

6
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/FrameSettings.cs


public bool enableAlphaTestOnlyInDeferredPrepass = false;
public bool enableTransparentPrePass = true;
public bool enableMotionVectors = true;
public bool enableMotionVectors = true; // Enable/disable whole motion vectors pass (Camera + Object).
public bool enableObjectMotionVectors = true;
public bool enableDBuffer = true;
public bool enableAtmosphericScattering = true;
public bool enableRoughRefraction = true; // Depends on DepthPyramid - If not enable, just do a copy of the scene color (?) - how to disable rough refraction ?

frameSettings.renderSettings.enableTransparentPrePass = this.renderSettings.enableTransparentPrePass;
frameSettings.renderSettings.enableMotionVectors = this.renderSettings.enableMotionVectors;
frameSettings.renderSettings.enableObjectMotionVectors = this.renderSettings.enableObjectMotionVectors;
frameSettings.renderSettings.enableDBuffer = this.renderSettings.enableDBuffer;
frameSettings.renderSettings.enableAtmosphericScattering = this.renderSettings.enableAtmosphericScattering;
frameSettings.renderSettings.enableRoughRefraction = this.renderSettings.enableRoughRefraction;

aggregate.renderSettings.enableTransparentPrePass = frameSettings.renderSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = camera.cameraType == CameraType.Reflection ? false : frameSettings.renderSettings.enableMotionVectors;
aggregate.renderSettings.enableObjectMotionVectors = camera.cameraType == CameraType.Reflection ? false : frameSettings.renderSettings.enableObjectMotionVectors;
aggregate.renderSettings.enableDBuffer = frameSettings.renderSettings.enableDBuffer && globalFrameSettings.renderSettings.supportDBuffer;
aggregate.renderSettings.enableAtmosphericScattering = frameSettings.renderSettings.enableAtmosphericScattering;
aggregate.renderSettings.enableRoughRefraction = frameSettings.renderSettings.enableRoughRefraction;

DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Transparent Prepass", () => frameSettings.renderSettings.enableTransparentPrePass, (value) => frameSettings.renderSettings.enableTransparentPrePass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Motion Vectors", () => frameSettings.renderSettings.enableMotionVectors, (value) => frameSettings.renderSettings.enableMotionVectors = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Object Motion Vectors", () => frameSettings.renderSettings.enableObjectMotionVectors, (value) => frameSettings.renderSettings.enableObjectMotionVectors = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable DBuffer", () => frameSettings.renderSettings.enableDBuffer, (value) => frameSettings.renderSettings.enableDBuffer = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Atmospheric Scattering", () => frameSettings.renderSettings.enableAtmosphericScattering, (value) => frameSettings.renderSettings.enableAtmosphericScattering = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Rough Refraction", () => frameSettings.renderSettings.enableRoughRefraction, (value) => frameSettings.renderSettings.enableRoughRefraction = (bool)value);

13
ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs


[GenerateHLSL(PackingRules.Exact)]
public enum ShaderOptions
{
// TODO: It is not possible to use VelocityInGBuffer feature yet. This feature allow to render motion vectors during Gbuffer pass. However Unity have limitation today that forbid to do that.
// 1) Currently previousPositionCS is provide to the vertex shader with a hard coded NORMAL semantic (in the vertex declaration - See MeshRenderingData.cpp "pSecondaryFormat = gMotionVectorRenderFormat.GetVertexFormat();") mean it will overwrite the normal
// 2) All current available semantic (see ShaderChannelMask) are used in our Lit shader. Mean just changing the semantic is not enough, Unity need to unlock other Texcoord semantic
// 3) When this is solve (i.e move previousPositionCS to a free attribute semantic), Unity only support one pSecondaryFormat. Mean if we ahve a vertex color instance stream and motion vector, motion vector will overwrite vertex color stream. See MeshRenderingData.cpp
// All this could be fix we a new Mesh API not ready yet. Note that this feature only affect animated mesh (vertex or skin) as others use depth reprojection.
VelocityInGBuffer = 0, // Change to 1 to enable the feature, then regenerate hlsl headers.
CameraRelativeRendering = 1 // Rendering sets the origin of the world to the position of the primary (scene view) camera
};

{
// const variable produce warning like this one: warning CS0162: Unreachable code detected
// If we want to avoid them we can add #pragma warning disable 162, however doing that make the debugger shift his line count when debugging which is really annoying
// so here we decalare two kind of variable, one const that can be use in enum init and one static so the compiler doesn't complain. It mean that the conditional code will stay
// but it is usually small, so we are fine with it (until someone at microsoft fix the debuggger).
public const int k_VelocityInGbuffer = (int)ShaderOptions.VelocityInGBuffer;
public static int s_VelocityInGbuffer = (int)ShaderOptions.VelocityInGBuffer;
public const int k_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
}

1
ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs.hlsl


//
// UnityEngine.Experimental.Rendering.HDPipeline.ShaderOptions: static fields
//
#define SHADEROPTIONS_VELOCITY_IN_GBUFFER (0)
#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)

2
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl


void Frag( PackedVaryingsToPS packedInput,
OUTPUT_GBUFFER(outGBuffer)
OUTPUT_GBUFFER_SHADOWMASK(outShadowMaskBuffer)
OUTPUT_GBUFFER_VELOCITY(outVelocityBuffer)
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif

ENCODE_INTO_GBUFFER(surfaceData, bakeDiffuseLighting, posInput.positionSS, outGBuffer);
ENCODE_SHADOWMASK_INTO_GBUFFER(float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3), outShadowMaskBuffer);
ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outVelocityBuffer);
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;

51
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl


void VelocityPositionZBias(VaryingsToPS input)
{
#if defined(UNITY_REVERSED_Z)
input.vmesh.positionCS.z -= unity_MotionVectorsParams.z * input.vmesh.positionCS.w;
#else
input.vmesh.positionCS.z += unity_MotionVectorsParams.z * input.vmesh.positionCS.w;
#endif
#if defined(UNITY_REVERSED_Z)
input.vmesh.positionCS.z -= unity_MotionVectorsParams.z * input.vmesh.positionCS.w;
#else
input.vmesh.positionCS.z += unity_MotionVectorsParams.z * input.vmesh.positionCS.w;
#endif
}
PackedVaryingsType Vert(AttributesMesh inputMesh,

// So motion vetor will be based on interpolate previous position at vertex level instead.
varyingsType.vpass.positionCS = mul(_NonJitteredViewProjMatrix, float4(varyingsType.vmesh.positionWS, 1.0));
//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
bool forceNoMotion = unity_MotionVectorsParams.y > 0.0;
if (forceNoMotion)
{
varyingsType.vpass.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0);
}
else
{
bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target
//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, hasDeformation ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)).xyz;
#ifdef ATTRIBUTES_NEED_NORMAL
#else
float3 normalWS = float3(0.0, 0.0, 0.0);
#endif
#if defined(HAVE_VERTEX_MODIFICATION)
#else
float3 normalWS = float3(0.0, 0.0, 0.0);
#endif
#if defined(HAVE_VERTEX_MODIFICATION)
#endif
//Need this since we are using the current position from VertMesh()
previousPositionWS = GetCameraRelativePositionWS(previousPositionWS);
varyingsType.vpass.previousPositionCS = mul(_PrevViewProjMatrix, float4(previousPositionWS, 1.0));
#endif
//Need this since we are using the current position from VertMesh()
previousPositionWS = GetCameraRelativePositionWS(previousPositionWS);
varyingsType.vpass.previousPositionCS = mul(_PrevViewProjMatrix, float4(previousPositionWS, 1.0));
}
return PackVaryingsType(varyingsType);
}

float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
{
bool forceNoMotion = unity_MotionVectorsParams.y > 0.0;
if (forceNoMotion)
return float4(0.0, 0.0, 0.0, 0.0);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.positionSS is SV_Position

正在加载...
取消
保存