|
|
|
|
|
|
bool shadows = ShadowPass(visibleLights, ref context, ref lightData); |
|
|
|
|
|
|
|
FrameRenderingConfiguration frameRenderingConfiguration; |
|
|
|
SetupFrameRenderingConfiguration(out frameRenderingConfiguration, shadows, stereoEnabled); |
|
|
|
SetupFrameRenderingConfiguration(out frameRenderingConfiguration, shadows, stereoEnabled, sceneViewCamera); |
|
|
|
SetupIntermediateResources(frameRenderingConfiguration, ref context); |
|
|
|
|
|
|
|
// SetupCameraProperties does the following:
|
|
|
|
|
|
|
ShadowCollectPass(visibleLights, ref context, ref lightData); |
|
|
|
} |
|
|
|
|
|
|
|
if (!shadows) |
|
|
|
{ |
|
|
|
var setRT = CommandBufferPool.Get("Generate Small Shadow Buffer"); |
|
|
|
setRT.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, 4, 4, 0, FilterMode.Bilinear, RenderTextureFormat.R8); |
|
|
|
setRT.Blit(Texture2D.whiteTexture, m_ScreenSpaceShadowMapRT); |
|
|
|
context.ExecuteCommandBuffer(setRT); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
if (sceneViewCamera) |
|
|
|
CopyTexture(cmd, CameraRenderTargetID.depth, BuiltinRenderTextureType.CameraTarget, m_CopyDepthMaterial, true); |
|
|
|
#endif
|
|
|
|
cmd.ReleaseTemporaryRT(m_ShadowMapRTID); |
|
|
|
cmd.ReleaseTemporaryRT(m_ScreenSpaceShadowMapRTID); |
|
|
|
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy); |
|
|
|
|
|
|
// There's no way to map shadow light indices. We need to pass in the original unsorted index.
|
|
|
|
// If no additional lights then no light sorting is performed and the indices match.
|
|
|
|
int shadowOriginalIndex = (lightData.totalAdditionalLightsCount > 0) ? GetLightUnsortedIndex(lightData.mainLightIndex) : lightData.mainLightIndex; |
|
|
|
bool shadowsRendered = RenderShadows(ref m_CullResults, ref mainLight, |
|
|
|
shadowOriginalIndex, ref context); |
|
|
|
bool shadowsRendered = RenderShadows(ref m_CullResults, ref mainLight, shadowOriginalIndex, ref context); |
|
|
|
if (shadowsRendered) |
|
|
|
{ |
|
|
|
lightData.shadowMapSampleType = (m_Asset.ShadowSetting != ShadowType.SOFT_SHADOWS) |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void SetupFrameRenderingConfiguration(out FrameRenderingConfiguration configuration, bool shadows, bool stereoEnabled) |
|
|
|
private void SetupFrameRenderingConfiguration(out FrameRenderingConfiguration configuration, bool shadows, bool stereoEnabled, bool sceneViewCamera) |
|
|
|
{ |
|
|
|
configuration = (stereoEnabled) ? FrameRenderingConfiguration.Stereo : FrameRenderingConfiguration.None; |
|
|
|
if (stereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray) |
|
|
|
|
|
|
m_RequireCopyColor = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (sceneViewCamera) |
|
|
|
m_RequireDepthTexture = true; |
|
|
|
|
|
|
|
if (shadows) |
|
|
|
{ |
|
|
|
|
|
|
int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount; |
|
|
|
|
|
|
|
int mainLightIndex = lightData.mainLightIndex; |
|
|
|
//TIM: Not used in shader for V1 to reduce keywords
|
|
|
|
//TIM: Not used in shader for V1 to reduce keywords
|
|
|
|
|
|
|
|
//TIM: Not used in shader for V1 to reduce keywords
|
|
|
|
|
|
|
|
//TIM: Not used in shader for V1 to reduce keywords
|
|
|
|
|
|
|
|
CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0); |
|
|
|
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive); |
|
|
|
CoreUtils.SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightsCount > 0); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CopyTexture(CommandBuffer cmd, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material copyMaterial) |
|
|
|
private void CopyTexture(CommandBuffer cmd, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material copyMaterial, bool forceBlit = false) |
|
|
|
if (m_CopyTextureSupport != CopyTextureSupport.None) |
|
|
|
if (m_CopyTextureSupport != CopyTextureSupport.None && !forceBlit) |
|
|
|
cmd.CopyTexture(sourceRT, destRT); |
|
|
|
else |
|
|
|
cmd.Blit(sourceRT, destRT, copyMaterial); |
|
|
|