|
|
|
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass)) |
|
|
|
{ |
|
|
|
DepthPass(ref context); |
|
|
|
DepthPass(ref context, frameRenderingConfiguration); |
|
|
|
ShadowCollectPass(visibleLights, ref context, ref lightData); |
|
|
|
ShadowCollectPass(visibleLights, ref context, ref lightData, frameRenderingConfiguration); |
|
|
|
} |
|
|
|
|
|
|
|
if (!shadows) |
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private void ShadowCollectPass(List<VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData) |
|
|
|
private void ShadowCollectPass(List<VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData, FrameRenderingConfiguration frameRenderingConfiguration) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows"); |
|
|
|
|
|
|
|
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8); |
|
|
|
cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial); |
|
|
|
|
|
|
|
// TODO: Support RenderScale for the SSSM target. Should probably move allocation elsewhere, or at
|
|
|
|
// least propogate RenderTextureDescriptor generation
|
|
|
|
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.Stereo)) |
|
|
|
{ |
|
|
|
var desc = XRSettings.eyeTextureDesc; |
|
|
|
desc.depthBufferBits = 0; |
|
|
|
desc.colorFormat = RenderTextureFormat.R8; |
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, desc, FilterMode.Bilinear); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8); |
|
|
|
} |
|
|
|
|
|
|
|
// Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that
|
|
|
|
// doesn't like null sources when trying to determine a stereo-ized blit. So for proper
|
|
|
|
// stereo functionality, we use the screen-space shadow map as the source (until we have
|
|
|
|
// a better solution).
|
|
|
|
// An alternative would be DrawProcedural, but that would require further changes in the shader.
|
|
|
|
cmd.Blit(m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial); |
|
|
|
|
|
|
|
StartStereoRendering(ref context, frameRenderingConfiguration); |
|
|
|
|
|
|
|
StopStereoRendering(ref context, frameRenderingConfiguration); |
|
|
|
|
|
|
|
private void DepthPass(ref ScriptableRenderContext context) |
|
|
|
private void DepthPass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("Depth Prepass"); |
|
|
|
SetRenderTarget(cmd, m_DepthRT, ClearFlag.Depth); |
|
|
|
|
|
|
renderQueueRange = RenderQueueRange.opaque |
|
|
|
}; |
|
|
|
|
|
|
|
StartStereoRendering(ref context, frameRenderingConfiguration); |
|
|
|
|
|
|
|
|
|
|
|
StopStereoRendering(ref context, frameRenderingConfiguration); |
|
|
|
} |
|
|
|
|
|
|
|
private void ForwardPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled) |
|
|
|
|
|
|
m_CurrCameraColorRT = BuiltinRenderTextureType.CameraTarget; |
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture)) |
|
|
|
{ |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
SetupIntermediateResourcesStereo(cmd, msaaSamples); |
|
|
|
else |
|
|
|
SetupIntermediateResourcesSingle(cmd, renderingConfig, msaaSamples); |
|
|
|
} |
|
|
|
SetupIntermediateRenderTextures(cmd, renderingConfig, msaaSamples); |
|
|
|
private void SetupIntermediateResourcesSingle(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, int msaaSamples) |
|
|
|
private void SetupIntermediateRenderTextures(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, int msaaSamples) |
|
|
|
RenderTextureDescriptor baseDesc; |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
baseDesc = XRSettings.eyeTextureDesc; |
|
|
|
else |
|
|
|
baseDesc = new RenderTextureDescriptor(m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight); |
|
|
|
|
|
|
|
int rtWidth = (int)((float)m_CurrCamera.pixelWidth * renderScale); |
|
|
|
int rtHeight = (int)((float)m_CurrCamera.pixelHeight * renderScale); |
|
|
|
baseDesc.width = (int)((float)baseDesc.width * renderScale); |
|
|
|
baseDesc.height = (int)((float)baseDesc.height * renderScale); |
|
|
|
|
|
|
|
// TODO: Might be worth caching baseDesc for allocation of other targets (Screen-space Shadow Map?)
|
|
|
|
RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(rtWidth, rtHeight, RenderTextureFormat.Depth, kDepthStencilBufferBits); |
|
|
|
var depthRTDesc = baseDesc; |
|
|
|
depthRTDesc.colorFormat = RenderTextureFormat.Depth; |
|
|
|
depthRTDesc.depthBufferBits = kDepthStencilBufferBits; |
|
|
|
|
|
|
|
cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Bilinear); |
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthCopy)) |
|
|
|
|
|
|
RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(rtWidth, rtHeight, m_ColorFormat, kDepthStencilBufferBits); |
|
|
|
var colorRTDesc = baseDesc; |
|
|
|
colorRTDesc.colorFormat = m_ColorFormat; |
|
|
|
colorRTDesc.depthBufferBits = kDepthStencilBufferBits; // TODO: does the color RT always need depth?
|
|
|
|
colorRTDesc.sRGB = true; |
|
|
|
colorRTDesc.msaaSamples = msaaSamples; |
|
|
|
colorRTDesc.enableRandomWrite = false; |
|
|
|
|
|
|
// color RT to blit the effect.
|
|
|
|
if (m_RequireCopyColor) |
|
|
|
cmd.GetTemporaryRT(CameraRenderTargetID.copyColor, colorRTDesc, FilterMode.Point); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetupIntermediateResourcesStereo(CommandBuffer cmd, int msaaSamples) |
|
|
|
{ |
|
|
|
RenderTextureDescriptor rtDesc = new RenderTextureDescriptor(); |
|
|
|
rtDesc = XRSettings.eyeTextureDesc; |
|
|
|
rtDesc.colorFormat = m_ColorFormat; |
|
|
|
rtDesc.msaaSamples = msaaSamples; |
|
|
|
|
|
|
|
cmd.GetTemporaryRT(CameraRenderTargetID.color, rtDesc, FilterMode.Bilinear); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetupShaderConstants(List<VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData) |
|
|
|
|
|
|
var cmd = CommandBufferPool.Get("Prepare Shadowmap"); |
|
|
|
cmd.GetTemporaryRT(m_ShadowMapRTID, m_ShadowSettings.shadowAtlasWidth, |
|
|
|
m_ShadowSettings.shadowAtlasHeight, kDepthStencilBufferBits, FilterMode.Bilinear, m_ShadowSettings.renderTextureFormat); |
|
|
|
SetRenderTarget(cmd, m_ShadowMapRT, ClearFlag.Depth); |
|
|
|
// LightweightPipeline.SetRenderTarget is meant to be used with camera targets, not shadowmaps
|
|
|
|
CoreUtils.SetRenderTarget(cmd, m_ShadowMapRT, ClearFlag.Depth, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor)); |
|
|
|
|
|
|
|
if (shadowLight.lightType == LightType.Spot) |
|
|
|
{ |
|
|
|
|
|
|
RenderTargetIdentifier colorRT = BuiltinRenderTextureType.CameraTarget; |
|
|
|
RenderTargetIdentifier depthRT = BuiltinRenderTextureType.None; |
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
context.StartMultiEye(m_CurrCamera); |
|
|
|
StartStereoRendering(ref context, renderingConfig); |
|
|
|
bool intermeaditeTexture = LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture); |
|
|
|
if (intermeaditeTexture) |
|
|
|
bool intermediateTexture = LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture); |
|
|
|
if (intermediateTexture) |
|
|
|
{ |
|
|
|
if (!m_IsOffscreenCamera) |
|
|
|
colorRT = m_CurrCameraColorRT; |
|
|
|
|
|
|
|
|
|
|
// If rendering to an intermediate RT we resolve viewport on blit due to offset not being supported
|
|
|
|
// while rendering to a RT.
|
|
|
|
if (!intermeaditeTexture && !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport)) |
|
|
|
if (!intermediateTexture && !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport)) |
|
|
|
cmd.SetViewport(m_CurrCamera.pixelRect); |
|
|
|
|
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
|
|
|
cmd.CopyTexture(sourceRT, destRT); |
|
|
|
else |
|
|
|
cmd.Blit(sourceRT, destRT, copyMaterial); |
|
|
|
} |
|
|
|
|
|
|
|
private void StartStereoRendering(ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration) |
|
|
|
{ |
|
|
|
if (LightweightUtils.HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo)) |
|
|
|
context.StartMultiEye(m_CurrCamera); |
|
|
|
} |
|
|
|
|
|
|
|
private void StopStereoRendering(ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration) |
|
|
|
{ |
|
|
|
if (LightweightUtils.HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo)) |
|
|
|
context.StopMultiEye(m_CurrCamera); |
|
|
|
} |
|
|
|
} |
|
|
|
} |