|
|
|
|
|
|
private RenderTargetIdentifier m_CopyDepth; |
|
|
|
private RenderTargetIdentifier m_Color; |
|
|
|
|
|
|
|
private float m_RenderScale; |
|
|
|
|
|
|
|
private bool m_IntermediateTextureArray; |
|
|
|
private bool m_RequireDepthTexture; |
|
|
|
private bool m_RequireCopyColor; |
|
|
|
|
|
|
foreach (Camera camera in cameras) |
|
|
|
{ |
|
|
|
RenderPipeline.BeginCameraRendering(camera); |
|
|
|
m_CurrCamera = camera; |
|
|
|
bool sceneViewCamera = camera.cameraType == CameraType.SceneView; |
|
|
|
bool stereoEnabled = XRSettings.isDeviceActive && !sceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both); |
|
|
|
m_CurrCamera = camera; |
|
|
|
bool sceneViewCamera = m_CurrCamera.cameraType == CameraType.SceneView; |
|
|
|
bool stereoEnabled = IsStereoEnabled(m_CurrCamera); |
|
|
|
|
|
|
|
// XR has it's own scaling mechanism.
|
|
|
|
m_RenderScale = (m_CurrCamera.cameraType == CameraType.Game && !stereoEnabled) ? m_Asset.RenderScale : 1.0f; |
|
|
|
m_IsOffscreenCamera = m_CurrCamera.targetTexture != null && m_CurrCamera.cameraType != CameraType.SceneView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrameRenderingConfiguration frameRenderingConfiguration; |
|
|
|
SetupFrameRenderingConfiguration(out frameRenderingConfiguration, shadows, stereoEnabled, sceneViewCamera); |
|
|
|
SetupIntermediateResources(frameRenderingConfiguration, ref context); |
|
|
|
SetupIntermediateResources(frameRenderingConfiguration, shadows, ref context); |
|
|
|
|
|
|
|
// SetupCameraProperties does the following:
|
|
|
|
// Setup Camera RenderTarget and Viewport
|
|
|
|
|
|
|
|
|
|
|
SetShadowCollectPassKeywords(cmd, visibleLights[lightData.mainLightIndex], ref lightData); |
|
|
|
|
|
|
|
// 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 = m_ShadowSettings.screenspaceShadowmapTextureFormat; |
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, desc, FilterMode.Bilinear); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, m_ShadowSettings.screenspaceShadowmapTextureFormat); |
|
|
|
} |
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
bool hdrEnabled = m_Asset.SupportsHDR && m_CurrCamera.allowHDR; |
|
|
|
bool intermediateTexture = m_CurrCamera.targetTexture != null || m_CurrCamera.cameraType == CameraType.SceneView || |
|
|
|
m_Asset.RenderScale < 1.0f || hdrEnabled; |
|
|
|
GetRenderScale() < 1.0f || hdrEnabled; |
|
|
|
|
|
|
|
m_ColorFormat = hdrEnabled ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default; |
|
|
|
m_RequireCopyColor = false; |
|
|
|
|
|
|
configuration |= FrameRenderingConfiguration.IntermediateTexture; |
|
|
|
} |
|
|
|
|
|
|
|
private void SetupIntermediateResources(FrameRenderingConfiguration renderingConfig, ref ScriptableRenderContext context) |
|
|
|
private void SetupIntermediateResources(FrameRenderingConfiguration renderingConfig, bool shadows, ref ScriptableRenderContext context) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("Setup Intermediate Resources"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture) || m_RequireDepthTexture) |
|
|
|
SetupIntermediateRenderTextures(cmd, renderingConfig, msaaSamples); |
|
|
|
SetupIntermediateRenderTextures(cmd, renderingConfig, shadows, msaaSamples); |
|
|
|
private void SetupIntermediateRenderTextures(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, int msaaSamples) |
|
|
|
private void SetupIntermediateRenderTextures(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, bool shadows, int msaaSamples) |
|
|
|
{ |
|
|
|
RenderTextureDescriptor baseDesc; |
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo)) |
|
|
|
|
|
|
|
|
|
|
float renderScale = (m_CurrCamera.cameraType == CameraType.Game) ? m_Asset.RenderScale : 1.0f; |
|
|
|
float renderScale = GetRenderScale(); |
|
|
|
// TODO: Might be worth caching baseDesc for allocation of other targets (Screen-space Shadow Map?)
|
|
|
|
|
|
|
|
if (m_RequireDepthTexture) |
|
|
|
{ |
|
|
|
var depthRTDesc = baseDesc; |
|
|
|
|
|
|
|
|
|
|
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthCopy)) |
|
|
|
cmd.GetTemporaryRT(CameraRenderTargetID.depthCopy, depthRTDesc, FilterMode.Bilinear); |
|
|
|
|
|
|
|
if (shadows && m_ShadowSettings.screenSpace) |
|
|
|
{ |
|
|
|
var screenspaceShadowmapDesc = baseDesc; |
|
|
|
screenspaceShadowmapDesc.depthBufferBits = 0; |
|
|
|
screenspaceShadowmapDesc.colorFormat = m_ShadowSettings.screenspaceShadowmapTextureFormat; |
|
|
|
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, screenspaceShadowmapDesc, FilterMode.Bilinear); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var colorRTDesc = baseDesc; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
RendererConfiguration GetRendererSettings(ref LightData lightData) |
|
|
|
private bool IsStereoEnabled(Camera camera) |
|
|
|
{ |
|
|
|
bool isSceneViewCamera = camera.cameraType == CameraType.SceneView; |
|
|
|
return XRSettings.isDeviceActive && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both); |
|
|
|
} |
|
|
|
|
|
|
|
private float GetRenderScale() |
|
|
|
{ |
|
|
|
return m_RenderScale; |
|
|
|
} |
|
|
|
|
|
|
|
private RendererConfiguration GetRendererSettings(ref LightData lightData) |
|
|
|
{ |
|
|
|
RendererConfiguration settings = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe; |
|
|
|
if (lightData.totalAdditionalLightsCount > 0) |
|
|
|