浏览代码

Add stencil test + split object and camera velocity

/feature-ReflectionProbeFit
sebastienlagarde 7 年前
当前提交
f10a2a97
共有 3 个文件被更改,包括 52 次插入8 次删除
  1. 40
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  3. 12
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader

40
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


public enum StencilBitMask
{
Clear = 0, // 0x0
Lighting = 3, // 0x3 - 2 bit
Lighting = 7, // 0x7 - 3 bit
ObjectVelocity = 128, // 1 bit
All = 255 // 0xFF - 8 bit
}

RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, true);
RenderVelocity(m_CullResults, hdCamera, renderContext, cmd);
RenderObjectsVelocity(m_CullResults, hdCamera, renderContext, cmd);
RenderDBuffer(hdCamera.cameraPos, renderContext, cmd);

CopyDepthBufferIfNeeded(cmd);
RenderCameraVelocity(m_CullResults, hdCamera, renderContext, cmd);
// Depth texture is now ready, bind it.
cmd.SetGlobalTexture(HDShaderIDs._MainDepthTexture, GetDepthTexture());

}
}
void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
void RenderObjectsVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.enableMotionVectors || !m_FrameSettings.enableObjectMotionVectors)
return;

int w = (int)hdcam.screenSize.x;
int h = (int)hdcam.screenSize.y;
cmd.SetRenderTarget(m_VelocityBufferRT, m_CameraDepthStencilBufferRT);
RenderOpaqueRenderList(cullResults, hdcam.camera, renderContext, cmd, HDShaderPassNames.s_MotionVectorsName, RendererConfiguration.PerObjectMotionVectors);
}
}
void RenderCameraVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.enableMotionVectors)
return;
using (new ProfilingSample(cmd, "Velocity", GetSampler(CustomSamplerId.Velocity)))
{
// 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;
int w = (int)hdcam.screenSize.x;
int h = (int)hdcam.screenSize.y;
// TODO: This is not safe ? as we don't use cmd buffer we can have a dealy no ?
cmd.SetRenderTarget(m_VelocityBufferRT, m_CameraDepthStencilBufferRT);
RenderOpaqueRenderList(cullResults, hdcam.camera, renderContext, cmd, HDShaderPassNames.s_MotionVectorsName, RendererConfiguration.PerObjectMotionVectors);
PushFullScreenDebugTexture(cmd, m_VelocityBuffer, hdcam.camera, renderContext, FullScreenDebugMode.MotionVectors);
}

}
m_DbufferManager.InitDBuffers(w, h, cmd);
if (m_FrameSettings.enableMotionVectors || m_FrameSettings.enableObjectMotionVectors)
{
// Note: We don't need to clear this buffer, it will be fill entirely by the rendering into the velocity buffer
cmd.ReleaseTemporaryRT(m_VelocityBuffer);
cmd.GetTemporaryRT(m_VelocityBuffer, w, h, 0, FilterMode.Point, Builtin.GetVelocityBufferFormat(), Builtin.GetVelocityBufferReadWrite());
}
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Depth);
}

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


Name "Motion Vectors"
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)
// If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
Stencil
{
Ref 128 // StencilBitMask.ObjectVelocity
Comp Always
Pass Replace
}
Cull[_CullMode]
ZWrite Off // TODO: Test Z equal here.

12
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader


SubShader
{
Cull Off ZWrite Off ZTest Always
// We will perform camera motion velocity only where there is no object velocity
Stencil
{
Ref 128 // StencilBitMask.ObjectVelocity
Comp NotEqual
Pass Keep
}
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex Vert

正在加载...
取消
保存