private static readonly int kMaxVertexLights = 4 ;
private static readonly float kRenderScaleThreshold = 0.05f ;
private bool m_IsOffscreenCamera ;
private Vector4 kDefaultLightPosition = new Vector4 ( 0.0f , 0.0f , 1.0f , 0.0f ) ;
private RenderTargetIdentifier m_CopyDepth ;
private RenderTargetIdentifier m_Color ;
private float m_RenderScale ;
private bool m_IntermediateTextureArray ;
private bool m_RequireDepthTexture ;
private bool m_RequireCopyColor ;
PerCameraBuffer . _AdditionalLightDistanceAttenuation = Shader . PropertyToID ( "_AdditionalLightDistanceAttenuation" ) ;
PerCameraBuffer . _AdditionalLightSpotDir = Shader . PropertyToID ( "_AdditionalLightSpotDir" ) ;
PerCameraBuffer . _AdditionalLightSpotAttenuation = Shader . PropertyToID ( "_AdditionalLightSpotAttenuation" ) ;
PerCameraBuffer . _ScaledScreenParams = Shader . PropertyToID ( "_ScaledScreenParams" ) ;
ShadowConstantBuffer . _WorldToShadow = Shader . PropertyToID ( "_WorldToShadow" ) ;
ShadowConstantBuffer . _ShadowData = Shader . PropertyToID ( "_ShadowData" ) ;
Array . Sort ( cameras , m_CameraComparer ) ;
foreach ( Camera camera in cameras )
{
RenderPipeline . BeginCameraRendering ( camera ) ;
m_CurrCamera = camera ;
bool sceneViewCamera = m_CurrCamera . cameraType = = CameraType . SceneView ;
bool stereoEnabled = IsStereoEnabled ( m_CurrCamera ) ;
// Disregard variations around kRenderScaleThreshold.
m_RenderScale = ( Mathf . Abs ( 1.0f - m_Asset . RenderScale ) < kRenderScaleThreshold ) ? 1.0f : m_Asset . RenderScale ;
bool sceneViewCamera = camera . cameraType = = CameraType . SceneView ;
bool stereoEnabled = XRSettings . isDeviceActive & & ! sceneViewCamera & & ( camera . stereoTargetEye = = StereoTargetEyeMask . Both ) ;
m_CurrCamera = camera ;
// XR has it's own scaling mechanism.
m_RenderScale = ( m_CurrCamera . cameraType = = CameraType . Game & & ! stereoEnabled ) ? m_RenderScale : 1.0f ;
SetupPerCameraShaderConstants ( ) ;
RenderPipeline . BeginCameraRendering ( m_CurrCamera ) ;
ScriptableCullingParameters cullingParameters ;
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
m_IntermediateTextureArray = false ;
bool hdrEnabled = m_Asset . SupportsHDR & & m_CurrCamera . allowHDR ;
bool defaultRenderScale = Mathf . Approximately ( GetRenderScale ( ) , 1.0f ) ;
m_Asset . RenderScale < 1.0f | | hdrEnabled ;
! defaultRenderScale | | 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 ;
// Used when subtractive mode is selected
Shader . SetGlobalVector ( PerFrameBuffer . _SubtractiveShadowColor , CoreUtils . ConvertSRGBToActiveColorSpace ( RenderSettings . subtractiveShadowColor ) ) ;
}
private void SetupPerCameraShaderConstants ( )
{
float cameraWidth = GetScaledCameraWidth ( m_CurrCamera ) ;
float cameraHeight = GetScaledCameraHeight ( m_CurrCamera ) ;
Shader . SetGlobalVector ( PerCameraBuffer . _ScaledScreenParams , new Vector4 ( cameraWidth , cameraHeight , 1.0f + 1.0f / cameraWidth , 1.0f + 1.0f / cameraHeight ) ) ;
}
private void SetupShaderLightConstants ( CommandBuffer cmd , List < VisibleLight > lights , ref LightData lightData )
}
}
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 float GetScaledCameraWidth ( Camera camera )
{
return ( float ) camera . pixelWidth * GetRenderScale ( ) ;
}
private float GetScaledCameraHeight ( Camera camera )
{
return ( float ) camera . pixelHeight * GetRenderScale ( ) ;
}
private RendererConfiguration GetRendererSettings ( ref LightData lightData )
{
RendererConfiguration settings = RendererConfiguration . PerObjectReflectionProbes | RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbe ;
if ( lightData . totalAdditionalLightsCount > 0 )