public bool shadowsRendered ;
}
public enum MixedLightingSetup
{
None = 0 ,
ShadowMask ,
Subtractive ,
} ;
public static class CameraRenderTargetID
{
// Camera color target. Not used when camera is rendering to backbuffer or camera
private readonly LightweightPipelineAsset m_Asset ;
// Maximum amount of visible lights the shader can process. This controls the constant global light buffer size.
// It must match the MAX_VISIBLE_LIGHTS in LightweightCore.cginc
private static readonly int kMaxVisibleAdditionalLights = 1 6 ;
// It must match the MAX_VISIBLE_LIGHTS in LightweightInput.cginc
private static readonly int kMaxVisibleLights = 1 6 ;
// Lights are culled per-object. This holds the maximum amount of additional lights that can shade each object.
// Lights are culled per-object. This holds the maximum amount of lights that can be shaded per-object.
private static readonly int kMaxPerObjectAdditionalLights = 8 ;
private static readonly int kMaxPerObjectLights = 8 ;
private static readonly int kMaxVertexLights = 4 ;
private Vector4 [ ] m_LightPositions = new Vector4 [ kMaxVisibleAdditionalLights ] ;
private Vector4 [ ] m_LightColors = new Vector4 [ kMaxVisibleAdditionalLights ] ;
private Vector4 [ ] m_LightDistanceAttenuations = new Vector4 [ kMaxVisibleAdditionalLights ] ;
private Vector4 [ ] m_LightSpotDirections = new Vector4 [ kMaxVisibleAdditionalLights ] ;
private Vector4 [ ] m_LightSpotAttenuations = new Vector4 [ kMaxVisibleAdditionalLights ] ;
private Vector4 [ ] m_LightPositions = new Vector4 [ kMaxVisibleLights ] ;
private Vector4 [ ] m_LightColors = new Vector4 [ kMaxVisibleLights ] ;
private Vector4 [ ] m_LightDistanceAttenuations = new Vector4 [ kMaxVisibleLights ] ;
private Vector4 [ ] m_LightSpotDirections = new Vector4 [ kMaxVisibleLights ] ;
private Vector4 [ ] m_LightSpotAttenuations = new Vector4 [ kMaxVisibleLights ] ;
private Camera m_CurrCamera = null ;
private Camera m_CurrCamera ;
private static readonly int kMaxCascades = 4 ;
private int m_ShadowCasterCascadesCount = kMaxCascades ;
private RenderTargetIdentifier m_CopyDepth ;
private RenderTargetIdentifier m_Color ;
private bool m_IntermediateTextureArray = false ;
private bool m_RequiredDepth = false ;
private bool m_IntermediateTextureArray ;
private bool m_RequiredDepth ;
private MixedLightingSetup m_MixedLightingSetup ;
private const int kShadowDepthBufferBits = 1 6 ;
private const int kCameraDepthBufferBits = 3 2 ;
BuildShadowSettings ( ) ;
PerFrameBuffer . _GlossyEnvironmentColor = Shader . PropertyToID ( "_GlossyEnvironmentColor" ) ;
PerFrameBuffer . _SubtractiveShadowColor = Shader . PropertyToID ( "_SubtractiveShadowColor" ) ;
// Lights are culled per-camera. Therefore we need to reset light buffers on each camera render
PerCameraBuffer . _MainLightPosition = Shader . PropertyToID ( "_MainLightPosition" ) ;
Shader . globalRenderPipeline = "LightweightPipeline" ;
m_BlitQuad = LightweightUtils . CreateQuadMesh ( false ) ;
m_BlitMaterial = new Material ( m_Asset . BlitShader )
{
hideFlags = HideFlags . HideAndDontSave
} ;
m_CopyDepthMaterial = new Material ( m_Asset . CopyDepthShader )
{
hideFlags = HideFlags . HideAndDontSave
} ;
m_BlitMaterial = CoreUtils . CreateEngineMaterial ( m_Asset . BlitShader ) ;
m_CopyDepthMaterial = CoreUtils . CreateEngineMaterial ( m_Asset . CopyDepthShader ) ;
}
public override void Dispose ( )
// instead this should be forced when using SRP, since all SRP use linear lighting.
GraphicsSettings . lightsUseLinearIntensity = true ;
SetupPerFrameShaderConstants ( ref context ) ;
SetupPerFrameShaderConstants ( ) ;
// Sort cameras array by camera depth
Array . Sort ( cameras , m_CameraComparer ) ;
private void DepthPass ( ref ScriptableRenderContext context )
{
CommandBuffer cmd = CommandBufferPool . Get ( "Depth Prepass" ) ;
cmd . SetRenderTarget ( m_DepthRT ) ;
SetRenderTarget ( cmd , m_DepthRT ) ;
context . ExecuteCommandBuffer ( cmd ) ;
CommandBufferPool . Release ( cmd ) ;
} ;
context . DrawRenderers ( m_CullResults . visibleRenderers , ref opaqueDrawSettings , opaqueFilterSettings ) ;
context . DrawSkybox ( m_CurrCamera ) ;
if ( m_CurrCamera . clearFlags = = CameraClearFlags . Skybox )
context . DrawSkybox ( m_CurrCamera ) ;
}
private void AfterOpaque ( ref ScriptableRenderContext context , FrameRenderingConfiguration config )
{
RenderTargetIdentifier colorRT = ( m_IsOffscreenCamera ) ? BuiltinRenderTextureType . CameraTarget : m_ColorRT ;
CopyTexture ( cmd , m_DepthRT , m_CopyDepth , m_CopyDepthMaterial ) ;
Setup RenderTargets ( cmd , colorRT , m_CopyDepth ) ;
SetRenderTarget ( cmd , colorRT , m_CopyDepth ) ;
}
context . ExecuteCommandBuffer ( cmd ) ;
if ( msaaEnabled )
{
configuration | = FrameRenderingConfiguration . Msaa ;
intermediateTexture = ! LightweightUtils . PlatformSupportsMSAABackBuffer ( ) ;
intermediateTexture = intermediateTexture | | ! LightweightUtils . PlatformSupportsMSAABackBuffer ( ) ;
}
Rect cameraRect = m_CurrCamera . rect ;
if ( m_RequiredDepth )
{
cmd . GetTemporaryRT ( CameraRenderTargetID . depth , rtWidth , rtHeight , kCameraDepthBufferBits , FilterMode . Bilinear , RenderTextureFormat . Depth ) ;
RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor ( rtWidth , rtHeight , RenderTextureFormat . Depth , kCameraDepthBufferBits ) ;
cmd . GetTemporaryRT ( CameraRenderTargetID . depth , depthRTDesc , FilterMode . Bilinear ) ;
cmd . GetTemporaryRT ( CameraRenderTargetID . depthCopy , rtWidth , rtHeight , kCameraDepthBufferBits , FilterMode . Bilinear , RenderTextureFormat . Depth ) ;
cmd . GetTemporaryRT ( CameraRenderTargetID . depthCopy , depthRTDesc , FilterMode . Bilinear ) ;
RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor ( rtWidth , rtHeight , m_ColorFormat , kCameraDepthBufferBits ) ;
colorRTDesc . msaaSamples = msaaSamples ;
colorRTDesc . enableRandomWrite = false ;
cmd . GetTemporaryRT ( CameraRenderTargetID . color , rtWidth , rtHeight , kCameraDepthBufferBits ,
FilterMode . Bilinear , m_ColorFormat , RenderTextureReadWrite . Default , msaaSamples ) ;
cmd . GetTemporaryRT ( CameraRenderTargetID . color , colorRTDesc , FilterMode . Bilinear ) ;
m_CurrCameraColorRT = m_ColorRT ;
}
if ( LightweightUtils . HasFlag ( renderingConfig , FrameRenderingConfiguration . BeforeTransparentPostProcess ) )
{
cmd . GetTemporaryRT ( CameraRenderTargetID . copyColor , rtWidth , rtHeight , kCameraDepthBufferBits ,
FilterMode . Bilinear , m_ColorFormat , RenderTextureReadWrite . Default , msaaSamples ) ;
}
cmd . GetTemporaryRT ( CameraRenderTargetID . copyColor , colorRTDesc , FilterMode . Point ) ;
}
private void SetupIntermediateResourcesStereo ( CommandBuffer cmd , int msaaSamples )
private void InitializeLightData ( VisibleLight [ ] visibleLights , out LightData lightData )
{
int visibleLightsCount = visibleLights . Length ;
int visibleLightsCount = Math . Min ( visibleLights . Length , m_Asset . MaxPixelLights ) ;
m_SortedLightIndexMap . Clear ( ) ;
lightData . shadowsRendered = false ;
lightData . mainLightIndex = SortLights ( visibleLights ) ;
// If we have a main light we don't shade it in the per-object light loop. We also remove it from the per-object cull list
int additionalLightsCount = ( lightData . mainLightIndex > 0 ) ? visibleLightsCount - 1 : visibleLightsCount ;
additionalLightsCount = Math . Min ( additionalLightsCount , kMaxPerObjectAdditionalLights ) ;
int mainLightPresent = ( lightData . mainLightIndex > = 0 ) ? 1 : 0 ;
int additionalPixelLightsCount = visibleLightsCount - mainLightPresent ;
int vertexLightCount = ( m_Asset . SupportsVertexLight ) ? Math . Min ( visibleLights . Length , kMaxPerObjectLights ) - additionalPixelLightsCount : 0 ;
vertexLightCount = Math . Min ( vertexLightCount , kMaxVertexLights ) ;
int pixelLightsCount = Math . Min ( additionalLightsCount , m_Asset . MaxAdditionalPixelLights ) ;
int vertexLightCount = ( m_Asset . SupportsVertexLight ) ? additionalLightsCount - pixelLightsCount : 0 ;
lightData . pixelAdditionalLightsCount = additionalPixelLightsCount ;
lightData . totalAdditionalLightsCount = additionalPixelLightsCount + vertexLightCount ;
lightData . pixelAdditionalLightsCount = pixelLightsCount ;
lightData . totalAdditionalLightsCount = pixelLightsCount + vertexLightCount ;
m_MixedLightingSetup = MixedLightingSetup . None ;
}
private int SortLights ( VisibleLight [ ] visibleLights )
int totalVisibleLights = visibleLights . Length ;
bool shadowsEnabled = m_Asset . AreShadowsEnabled ( ) ;
if ( totalVisibleLights = = 0 )
if ( totalVisibleLights = = 0 | | m_Asset . MaxPixelLights = = 0 )
return - 1 ;
int brighestDirectionalIndex = - 1 ;
private void InitializeLightConstants ( VisibleLight [ ] lights , int lightIndex , out Vector4 lightPos , out Vector4 lightColor , out Vector4 lightDistanceAttenuation , out Vector4 lightSpotDir ,
out Vector4 lightSpotAttenuation )
{
float directContributionNotBaked = 1.0f ;
lightDistanceAttenuation = new Vector4 ( 0.0f , 1.0f , 0.0f , 0.0f ) ;
lightDistanceAttenuation = new Vector4 ( 0.0f , 1.0f , 0.0f , directContributionNotBaked ) ;
lightSpotDir = new Vector4 ( 0.0f , 0.0f , 1.0f , 0.0f ) ;
lightSpotAttenuation = new Vector4 ( 0.0f , 1.0f , 0.0f , 0.0f ) ;
return ;
VisibleLight light = lights [ lightIndex ] ;
if ( light . lightType = = LightType . Directional )
VisibleLight lightData = lights [ lightIndex ] ;
if ( lightData . lightType = = LightType . Directional )
Vector4 dir = - light . localToWorld . GetColumn ( 2 ) ;
Vector4 dir = - lightData . localToWorld . GetColumn ( 2 ) ;
Vector4 pos = light . localToWorld . GetColumn ( 3 ) ;
Vector4 pos = lightData . localToWorld . GetColumn ( 3 ) ;
lightColor = light . finalColor ;
lightColor = lightData . finalColor ;
if ( light . lightType ! = LightType . Directional )
if ( lightData . lightType ! = LightType . Directional )
{
// Light attenuation in lightweight matches the unity vanilla one.
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
// with one MAD instruction
// smoothFactor = distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
// distanceSqr * oneOverFadeRangeSqr + lightRangeSqrOverFadeRangeSqr
float lightRangeSqr = light . range * light . range ;
float lightRangeSqr = lightData . range * lightData . range ;
lightDistanceAttenuation = new Vector4 ( quadAtten , oneOverFadeRangeSqr , lightRangeSqrOverFadeRangeSqr , 0.0f ) ;
lightDistanceAttenuation = new Vector4 ( quadAtten , oneOverFadeRangeSqr , lightRangeSqrOverFadeRangeSqr , directContributionNotBaked ) ;
if ( light . lightType = = LightType . Spot )
if ( lightData . lightType = = LightType . Spot )
Vector4 dir = light . localToWorld . GetColumn ( 2 ) ;
Vector4 dir = lightData . localToWorld . GetColumn ( 2 ) ;
lightSpotDir = new Vector4 ( - dir . x , - dir . y , - dir . z , 0.0f ) ;
// Spot Attenuation with a linear falloff can be defined as
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
// If we precompute the terms in a MAD instruction
float spotAngle = Mathf . Deg2Rad * light . spotAngle ;
float spotAngle = Mathf . Deg2Rad * lightData . spotAngle ;
float cosOuterAngle = Mathf . Cos ( spotAngle * 0.5f ) ;
float cosInneAngle = Mathf . Cos ( spotAngle * 0.25f ) ;
float smoothAngleRange = cosInneAngle - cosOuterAngle ;
float invAngleRange = 1.0f / smoothAngleRange ;
float add = - cosOuterAngle * invAngleRange ;
lightSpotAttenuation = new Vector4 ( invAngleRange , add , 0.0f ) ;
}
Light light = lightData . light ;
if ( light . bakingOutput . lightmapBakeType = = LightmapBakeType . Mixed )
{
// TODO: Add support to shadow mask
if ( m_MixedLightingSetup = = MixedLightingSetup . None & & lightData . light . shadows ! = LightShadows . None )
{
m_MixedLightingSetup = MixedLightingSetup . Subtractive ;
lightDistanceAttenuation . w = 0.0f ;
}
private void SetupPerFrameShaderConstants ( ref ScriptableRenderContext context )
private void SetupPerFrameShaderConstants ( )
// Used when subtractive mode is selected
Shader . SetGlobalColor ( PerFrameBuffer . _SubtractiveShadowColor , RenderSettings . subtractiveShadowColor . linear ) ;
}
private void SetupShaderLightConstants ( CommandBuffer cmd , VisibleLight [ ] lights , ref LightData lightData )
Vector4 lightPos , lightColor , lightDistanceAttenuation , lightSpotDir , lightSpotAttenuation ;
InitializeLightConstants ( lights , lightIndex , out lightPos , out lightColor , out lightDistanceAttenuation , out lightSpotDir , out lightSpotAttenuation ) ;
if ( lightIndex > = 0 )
{
LightType mainLightType = lights [ lightIndex ] . lightType ;
Light mainLight = lights [ lightIndex ] . light ;
if ( LightweightUtils . IsSupportedCookieType ( mainLightType ) & & mainLight . cookie ! = null )
{
Matrix4x4 lightCookieMatrix ;
LightweightUtils . GetLightCookieMatrix ( lights [ lightIndex ] , out lightCookieMatrix ) ;
cmd . SetGlobalTexture ( PerCameraBuffer . _MainLightCookie , mainLight . cookie ) ;
cmd . SetGlobalMatrix ( PerCameraBuffer . _WorldToLight , lightCookieMatrix ) ;
}
}
if ( lightIndex > = 0 & & LightweightUtils . IsSupportedCookieType ( lights [ lightIndex ] . lightType ) & & lights [ lightIndex ] . light . cookie ! = null )
{
Matrix4x4 lightCookieMatrix ;
LightweightUtils . GetLightCookieMatrix ( lights [ lightIndex ] , out lightCookieMatrix ) ;
cmd . SetGlobalTexture ( PerCameraBuffer . _MainLightCookie , lights [ lightIndex ] . light . cookie ) ;
cmd . SetGlobalMatrix ( PerCameraBuffer . _WorldToLight , lightCookieMatrix ) ;
}
}
private void SetupAdditionalListConstants ( CommandBuffer cmd , VisibleLight [ ] lights , ref LightData lightData )
for ( int i = 0 ; i < lights . Length ; + + i )
perObjectLightIndexMap [ i ] = - 1 ;
for ( int i = 0 ; i < lights . Length & & additionalLightIndex < kMaxVisibleAdditional Lights ; + + i )
for ( int i = 0 ; i < lights . Length & & additionalLightIndex < kMaxVisibleLights ; + + i )
{
if ( i ! = lightData . mainLightIndex )
{
}
m_CullResults . SetLightIndexMap ( perObjectLightIndexMap ) ;
cmd . SetGlobalVector ( PerCameraBuffer . _AdditionalLightCount , new Vector4 ( lightData . pixelAdditionalLightsCount ,
cmd . SetGlobalVector ( PerCameraBuffer . _AdditionalLightCount , new Vector4 ( lightData . pixelAdditionalLightsCount ,
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightPosition , m_LightPositions ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightColor , m_LightColors ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightDistanceAttenuation , m_LightDistanceAttenuations ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightSpotDir , m_LightSpotDirections ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightSpotAttenuation , m_LightSpotAttenuations ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightPosition , m_LightPositions ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightColor , m_LightColors ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightDistanceAttenuation , m_LightDistanceAttenuations ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightSpotDir , m_LightSpotDirections ) ;
cmd . SetGlobalVectorArray ( PerCameraBuffer . _AdditionalLightSpotAttenuation , m_LightSpotAttenuations ) ;
float strength = 1.0f - light . shadowStrength ;
float nearPlane = light . shadowNearPlane ;
float shadowResolution = m_ShadowSlices [ 0 ] . shadowResolution ;
const int maxShadowCascades = 4 ;
cmd . SetGlobalMatrixArray ( "_WorldToShadow" , shadowMatrices ) ;
cmd . SetGlobalVectorArray ( "_DirShadowSplitSpheres" , m_DirectionalShadowSplitDistances ) ;
cmd . SetGlobalVector ( "_ShadowData" , new Vector4 ( 0.0f , bias , normalBias , 0.0f ) ) ;
cmd . SetGlobalVector ( "_ShadowData" , new Vector4 ( strength , bias , normalBias , nearPlane ) ) ;
cmd . SetGlobalFloatArray ( "_PCFKernel" , pcfKernel ) ;
}
LightweightUtils . SetKeyword ( cmd , "_VERTEX_LIGHTS" , vertexLightsCount > 0 ) ;
CoreUtils . SetKeyword ( cmd , "_VERTEX_LIGHTS" , vertexLightsCount > 0 ) ;
// Currently only directional light cookie is supported
LightweightUtils . SetKeyword ( cmd , "_MAIN_LIGHT_COOKIE" , mainLightIndex ! = - 1 & & LightweightUtils . IsSupportedCookieType ( visibleLights [ mainLightIndex ] . lightType ) & & visibleLights [ mainLightIndex ] . light . cookie ! = null ) ;
LightweightUtils . SetKeyword ( cmd , "_MAIN_DIRECTIONAL_LIGHT" , mainLightIndex = = - 1 | | visibleLights [ mainLightIndex ] . lightType = = LightType . Directional ) ;
LightweightUtils . SetKeyword ( cmd , "_MAIN_SPOT_LIGHT" , mainLightIndex ! = - 1 & & visibleLights [ mainLightIndex ] . lightType = = LightType . Spot ) ;
LightweightUtils . SetKeyword ( cmd , "_MAIN_POINT_LIGHT" , mainLightIndex ! = - 1 & & visibleLights [ mainLightIndex ] . lightType = = LightType . Point ) ;
LightweightUtils . SetKeyword ( cmd , "_ADDITIONAL_LIGHTS" , lightData . totalAdditionalLightsCount > 0 ) ;
CoreUtils . SetKeyword ( cmd , "_MAIN_LIGHT_COOKIE" , mainLightIndex ! = - 1 & & LightweightUtils . IsSupportedCookieType ( visibleLights [ mainLightIndex ] . lightType ) & & visibleLights [ mainLightIndex ] . light . cookie ! = null ) ;
CoreUtils . SetKeyword ( cmd , "_MAIN_DIRECTIONAL_LIGHT" , mainLightIndex = = - 1 | | visibleLights [ mainLightIndex ] . lightType = = LightType . Directional ) ;
CoreUtils . SetKeyword ( cmd , "_MAIN_SPOT_LIGHT" , mainLightIndex ! = - 1 & & visibleLights [ mainLightIndex ] . lightType = = LightType . Spot ) ;
CoreUtils . SetKeyword ( cmd , "_ADDITIONAL_LIGHTS" , lightData . totalAdditionalLightsCount > 0 ) ;
CoreUtils . SetKeyword ( cmd , "_MIXED_LIGHTING_SHADOWMASK" , m_MixedLightingSetup = = MixedLightingSetup . ShadowMask ) ;
CoreUtils . SetKeyword ( cmd , "_MIXED_LIGHTING_SUBTRACTIVE" , m_MixedLightingSetup = = MixedLightingSetup . Subtractive ) ;
string [ ] shadowKeywords = new string [ ] { "_HARD_SHADOWS" , "_SOFT_SHADOWS" , "_HARD_SHADOWS_CASCADES" , "_SOFT_SHADOWS_CASCADES" } ;
for ( int i = 0 ; i < shadowKeywords . Length ; + + i )
cmd . EnableShaderKeyword ( shadowKeywords [ keywordIndex ] ) ;
}
Lightweight Utils. SetKeyword ( cmd , "SOFTPARTICLES_ON" , m_Asset . SupportsSoftParticles ) ;
Core Utils. SetKeyword ( cmd , "SOFTPARTICLES_ON" , m_Asset . SupportsSoftParticles ) ;
}
private bool RenderShadows ( ref CullResults cullResults , ref VisibleLight shadowLight , int shadowLightIndex , ref ScriptableRenderContext context )
if ( ! cullResults . GetShadowCasterBounds ( shadowLightIndex , out bounds ) )
return false ;
var setRenderTargetCommandBuffer = CommandBufferPool . Get ( ) ;
setRenderTargetCommandBuffer . name = "Render packed shadows" ;
setRenderTargetCommandBuffer . GetTemporaryRT ( m_ShadowMapRTID , m_ShadowSettings . shadowAtlasWidth ,
var cmd = CommandBufferPool . Get ( ) ;
cmd . name = "Render packed shadows" ;
cmd . GetTemporaryRT ( m_ShadowMapRTID , m_ShadowSettings . shadowAtlasWidth ,
setRenderTargetCommandBuffer . SetRenderTarget ( m_ShadowMapRT ) ;
setRenderTargetCommandBuffer . ClearRenderTarget ( true , true , Color . black ) ;
context . ExecuteCommandBuffer ( setRenderTargetCommandBuffer ) ;
CommandBufferPool . Release ( setRenderTargetCommandBuffer ) ;
SetRenderTarget ( cmd , m_ShadowMapRT , ClearFlag . All ) ;
context . ExecuteCommandBuffer ( cmd ) ;
CommandBufferPool . Release ( cmd ) ;
float shadowNearPlane = m_Asset . ShadowNearOffset ;
Vector3 splitRatio = m_ShadowSettings . directionalLightCascades ;
depthRT = m_DepthRT ;
}
SetupRenderTargets ( cmd , colorRT , depthRT ) ;
// Clear RenderTarget to avoid tile initialization on mobile GPUs
// https://community.arm.com/graphics/b/blog/posts/mali-performance-2-how-to-correctly-handle-framebuffers
if ( m_CurrCamera . clearFlags ! = CameraClearFlags . Nothing )
if ( ForceClear ( ) )
bool clearDepth = ( m_CurrCamera . clearFlags ! = CameraClearFlags . Nothing ) ;
bool clearColor = ( m_CurrCamera . clearFlags = = CameraClearFlags . Color | | m_CurrCamera . clearFlags = = CameraClearFlags . Skybox ) ;
cmd . ClearRenderTarget ( clearDepth , clearColor , m_CurrCamera . backgroundColor . linear ) ;
SetRenderTarget ( cmd , colorRT , depthRT , ClearFlag . All ) ;
}
else
{
ClearFlag clearFlag = ClearFlag . None ;
CameraClearFlags cameraClearFlags = m_CurrCamera . clearFlags ;
if ( cameraClearFlags ! = CameraClearFlags . Nothing )
{
clearFlag | = ClearFlag . Depth ;
if ( cameraClearFlags = = CameraClearFlags . Color | | cameraClearFlags = = CameraClearFlags . Skybox )
clearFlag | = ClearFlag . Color ;
}
SetRenderTarget ( cmd , colorRT , depthRT , clearFlag ) ;
}
context . ExecuteCommandBuffer ( cmd ) ;
var cmd = CommandBufferPool . Get ( "Blit" ) ;
if ( m_IntermediateTextureArray )
{
cmd . SetRenderTarget ( BuiltinRenderTextureType . CameraTarget , 0 , CubemapFace . Unknown , - 1 ) ;
SetRenderTarget ( cmd , BuiltinRenderTextureType . CameraTarget ) ;
cmd . Blit ( m_CurrCameraColorRT , BuiltinRenderTextureType . CurrentActive ) ;
}
else if ( LightweightUtils . HasFlag ( renderingConfig , FrameRenderingConfiguration . IntermediateTexture ) )
Blit ( cmd , renderingConfig , BuiltinRenderTextureType . CurrentActive , BuiltinRenderTextureType . CameraTarget ) ;
}
Setup RenderTargets ( cmd , BuiltinRenderTextureType . CameraTarget , BuiltinRenderTextureType . None ) ;
SetRenderTarget ( cmd , BuiltinRenderTextureType . CameraTarget ) ;
context . ExecuteCommandBuffer ( cmd ) ;
CommandBufferPool . Release ( cmd ) ;
return settings ;
}
private void SetupRenderTargets ( CommandBuffer cmd , RenderTargetIdentifier colorRT , RenderTargetIdentifier depthRT )
private void SetRenderTarget ( CommandBuffer cmd , RenderTargetIdentifier colorRT , ClearFlag clearFlag = ClearFlag . None )
if ( depthRT ! = BuiltinRenderTextureType . None )
cmd . SetRenderTarget ( colorRT , depthRT , 0 , CubemapFace . Unknown , depthSlice ) ;
else
cmd . SetRenderTarget ( colorRT , 0 , CubemapFace . Unknown , depthSlice ) ;
CoreUtils . SetRenderTarget ( cmd , colorRT , clearFlag , m_CurrCamera . backgroundColor . linear , 0 , CubemapFace . Unknown , depthSlice ) ;
}
private void SetRenderTarget ( CommandBuffer cmd , RenderTargetIdentifier colorRT , RenderTargetIdentifier depthRT , ClearFlag clearFlag = ClearFlag . None )
{
if ( depthRT = = BuiltinRenderTextureType . None )
{
SetRenderTarget ( cmd , colorRT , clearFlag ) ;
return ;
}
int depthSlice = ( m_IntermediateTextureArray ) ? - 1 : 0 ;
CoreUtils . SetRenderTarget ( cmd , colorRT , depthRT , clearFlag , m_CurrCamera . backgroundColor . linear , 0 , CubemapFace . Unknown , depthSlice ) ;
}
private void RenderPostProcess ( CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier dest , bool opaqueOnly )
return ( index < m_SortedLightIndexMap . Count ) ? m_SortedLightIndexMap [ index ] : index ;
}
private bool ForceClear ( )
{
// Clear RenderTarget to avoid tile initialization on mobile GPUs
// https://community.arm.com/graphics/b/blog/posts/mali-performance-2-how-to-correctly-handle-framebuffers
return ( Application . platform = = RuntimePlatform . Android | | Application . platform = = RuntimePlatform . IPhonePlayer ) ;
}
private void Blit ( CommandBuffer cmd , FrameRenderingConfiguration renderingConfig , RenderTargetIdentifier sourceRT , RenderTargetIdentifier destRT , Material material = null )
{
if ( LightweightUtils . HasFlag ( renderingConfig , FrameRenderingConfiguration . DefaultViewport ) )
m_BlitQuad = LightweightUtils . CreateQuadMesh ( false ) ;
cmd . SetGlobalTexture ( m_BlitTexID , sourceRT ) ;
cmd . SetRenderTarget ( destRT ) ;
SetRenderTarget ( cmd , destRT ) ;
cmd . SetViewport ( m_CurrCamera . pixelRect ) ;
cmd . DrawMesh ( m_BlitQuad , Matrix4x4 . identity , m_BlitMaterial ) ;
}