|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|