|
|
|
|
|
|
|
|
|
|
private void ForwardPass(VisibleLight[] visibleLights, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled) |
|
|
|
{ |
|
|
|
RenderingConfiguration renderingConfig = SetupRendering(); |
|
|
|
|
|
|
|
SetupIntermediateResources(renderingConfig, ref context); |
|
|
|
|
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants"); |
|
|
|
SetupShaderLightConstants(cmd, visibleLights, ref lightData, ref m_CullResults, ref context); |
|
|
|
SetShaderKeywords(cmd, ref lightData, visibleLights); |
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
FrameRenderingConfiguration frameRenderingConfiguration; |
|
|
|
SetupFrameRendering(out frameRenderingConfiguration); |
|
|
|
SetupIntermediateResources(frameRenderingConfiguration, ref context); |
|
|
|
SetupShaderConstants(visibleLights, ref context, ref lightData); |
|
|
|
|
|
|
|
// SetupCameraProperties does the following:
|
|
|
|
// Setup Camera RenderTarget and Viewport
|
|
|
|
|
|
|
|
|
|
|
RendererConfiguration rendererSettings = GetRendererSettings(ref lightData); |
|
|
|
|
|
|
|
BeginForwardRendering(ref context, renderingConfig); |
|
|
|
BeginForwardRendering(ref context, frameRenderingConfiguration); |
|
|
|
AfterOpaque(ref context, renderingConfig); |
|
|
|
AfterOpaque(ref context, frameRenderingConfiguration); |
|
|
|
AfterTransparent(ref context, renderingConfig); |
|
|
|
EndForwardRendering(ref context, renderingConfig); |
|
|
|
AfterTransparent(ref context, frameRenderingConfiguration); |
|
|
|
EndForwardRendering(ref context, frameRenderingConfiguration); |
|
|
|
} |
|
|
|
|
|
|
|
private void RenderOpaques(ref ScriptableRenderContext context, RendererConfiguration settings) |
|
|
|
|
|
|
context.DrawSkybox(m_CurrCamera); |
|
|
|
} |
|
|
|
|
|
|
|
private void AfterOpaque(ref ScriptableRenderContext context, RenderingConfiguration settings) |
|
|
|
private void AfterOpaque(ref ScriptableRenderContext context, FrameRenderingConfiguration config) |
|
|
|
if (!LightweightUtils.HasFlag(settings, RenderingConfiguration.RequireDepth)) |
|
|
|
if (!LightweightUtils.HasFlag(config, FrameRenderingConfiguration.RequireDepth)) |
|
|
|
return; |
|
|
|
|
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("After Opaque"); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Only takes effect if custom BeforeTransparent PostProcessing effects are active
|
|
|
|
if (LightweightUtils.HasFlag(settings, RenderingConfiguration.PostProcess)) |
|
|
|
if (LightweightUtils.HasFlag(config, FrameRenderingConfiguration.PostProcess)) |
|
|
|
RenderPostProcess(cmd , true); |
|
|
|
|
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
|
|
|
private void AfterTransparent(ref ScriptableRenderContext context, RenderingConfiguration settings) |
|
|
|
private void AfterTransparent(ref ScriptableRenderContext context, FrameRenderingConfiguration config) |
|
|
|
if (!LightweightUtils.HasFlag(settings, RenderingConfiguration.PostProcess)) |
|
|
|
if (!LightweightUtils.HasFlag(config, FrameRenderingConfiguration.PostProcess)) |
|
|
|
return; |
|
|
|
|
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("After Transparent"); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void RenderTransparents(ref ScriptableRenderContext context, RendererConfiguration settings) |
|
|
|
private void RenderTransparents(ref ScriptableRenderContext context, RendererConfiguration config) |
|
|
|
transparentSettings.rendererConfiguration = settings; |
|
|
|
transparentSettings.rendererConfiguration = config; |
|
|
|
|
|
|
|
var transparentFilterSettings = new FilterRenderersSettings(true) |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private RenderingConfiguration SetupRendering() |
|
|
|
private void SetupFrameRendering(out FrameRenderingConfiguration configuration) |
|
|
|
RenderingConfiguration renderingConfig = (XRSettings.enabled) ? RenderingConfiguration.Stereo : RenderingConfiguration.None; |
|
|
|
configuration = (XRSettings.enabled) ? FrameRenderingConfiguration.Stereo : FrameRenderingConfiguration.None; |
|
|
|
if (XRSettings.enabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray) |
|
|
|
m_IntermediateTextureArray = true; |
|
|
|
else |
|
|
|
|
|
|
bool postProcessEnabled = m_CameraPostProcessLayer != null && m_CameraPostProcessLayer.enabled; |
|
|
|
if (postProcessEnabled || m_Asset.SupportsSoftParticles) |
|
|
|
{ |
|
|
|
renderingConfig |= RenderingConfiguration.RequireDepth; |
|
|
|
configuration |= FrameRenderingConfiguration.RequireDepth; |
|
|
|
renderingConfig |= RenderingConfiguration.PostProcess; |
|
|
|
configuration |= FrameRenderingConfiguration.PostProcess; |
|
|
|
renderingConfig |= RenderingConfiguration.Msaa; |
|
|
|
configuration |= FrameRenderingConfiguration.Msaa; |
|
|
|
intermediateTexture = !LightweightUtils.PlatformSupportsMSAABackBuffer(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
renderingConfig |= RenderingConfiguration.DefaultViewport; |
|
|
|
configuration |= FrameRenderingConfiguration.DefaultViewport; |
|
|
|
renderingConfig |= RenderingConfiguration.IntermediateTexture; |
|
|
|
|
|
|
|
return renderingConfig; |
|
|
|
configuration |= FrameRenderingConfiguration.IntermediateTexture; |
|
|
|
private void SetupIntermediateResources(RenderingConfiguration renderingConfig, ref ScriptableRenderContext context) |
|
|
|
private void SetupIntermediateResources(FrameRenderingConfiguration renderingConfig, ref ScriptableRenderContext context) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("Setup Intermediate Resources"); |
|
|
|
|
|
|
|
|
|
|
int msaaSamples = (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.Msaa)) ? m_Asset.MSAASampleCount : 1; |
|
|
|
int msaaSamples = (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Msaa)) ? m_Asset.MSAASampleCount : 1; |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.IntermediateTexture)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.Stereo)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
{ |
|
|
|
RenderTextureDescriptor rtDesc = new RenderTextureDescriptor(); |
|
|
|
rtDesc = XRSettings.eyeTextureDesc; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.RequireDepth)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.RequireDepth)) |
|
|
|
{ |
|
|
|
cmd.GetTemporaryRT(m_CameraDepthTexture, rtWidth, rtHeight, kCameraDepthBufferBits, FilterMode.Bilinear, RenderTextureFormat.Depth); |
|
|
|
if (m_Asset.SupportsSoftParticles) |
|
|
|
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetupShaderConstants(VisibleLight[] visibleLights, ref ScriptableRenderContext context, ref LightData lightData) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants"); |
|
|
|
SetupShaderLightConstants(cmd, visibleLights, ref lightData, ref m_CullResults, ref context); |
|
|
|
SetShaderKeywords(cmd, ref lightData, visibleLights); |
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
} |
|
|
|
|
|
|
return resolution; |
|
|
|
} |
|
|
|
|
|
|
|
private void BeginForwardRendering(ref ScriptableRenderContext context, RenderingConfiguration renderingConfig) |
|
|
|
private void BeginForwardRendering(ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfig) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.Stereo)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.IntermediateTexture)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.RequireDepth)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.RequireDepth)) |
|
|
|
depthRT = m_CameraDepthRT; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
private void EndForwardRendering(ref ScriptableRenderContext context, RenderingConfiguration renderingConfig) |
|
|
|
private void EndForwardRendering(ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfig) |
|
|
|
{ |
|
|
|
// No additional rendering needs to be done if this is an offscren rendering camera (unless camera is scene view)
|
|
|
|
if (m_CurrCamera.targetTexture != null && m_CurrCamera.cameraType != CameraType.SceneView) |
|
|
|
|
|
|
cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, 0, CubemapFace.Unknown, -1); |
|
|
|
cmd.Blit(m_CameraColorRT, BuiltinRenderTextureType.CurrentActive); |
|
|
|
} |
|
|
|
else if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.IntermediateTexture)) |
|
|
|
else if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture)) |
|
|
|
if (!LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.PostProcess)) |
|
|
|
if (!LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess)) |
|
|
|
Blit(cmd, renderingConfig, BuiltinRenderTextureType.CurrentActive, BuiltinRenderTextureType.CameraTarget); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.Stereo)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
{ |
|
|
|
context.StopMultiEye(m_CurrCamera); |
|
|
|
context.StereoEndRender(m_CurrCamera); |
|
|
|
|
|
|
m_CameraPostProcessLayer.Render(m_PostProcessRenderContext); |
|
|
|
} |
|
|
|
|
|
|
|
private void Blit(CommandBuffer cmd, RenderingConfiguration renderingConfig, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null) |
|
|
|
private void Blit(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, RenderingConfiguration.DefaultViewport)) |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport)) |
|
|
|
{ |
|
|
|
cmd.Blit(sourceRT, destRT, material); |
|
|
|
} |
|
|
|