|
|
|
|
|
|
private RenderTargetIdentifier m_CurrCameraColorRT; |
|
|
|
private RenderTargetIdentifier m_ShadowMapRT; |
|
|
|
private RenderTargetIdentifier m_ScreenSpaceShadowMapRT; |
|
|
|
private RenderTargetIdentifier m_AmbientOcclusionRT; |
|
|
|
private RenderTargetIdentifier m_ColorRT; |
|
|
|
private RenderTargetIdentifier m_CopyColorRT; |
|
|
|
private RenderTargetIdentifier m_DepthRT; |
|
|
|
|
|
|
PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation"); |
|
|
|
PerCameraBuffer._AdditionalLightSpotDir = Shader.PropertyToID("_AdditionalLightSpotDir"); |
|
|
|
PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation"); |
|
|
|
PerCameraBuffer._AmbientOcclusionBuffer = Shader.PropertyToID("_AmbientOcclusion"); |
|
|
|
PerCameraBuffer._AmbientOcclusionParam = Shader.PropertyToID("_AmbientOcclusionParam"); |
|
|
|
|
|
|
|
ShadowConstantBuffer._WorldToShadow = Shader.PropertyToID("_WorldToShadow"); |
|
|
|
ShadowConstantBuffer._ShadowData = Shader.PropertyToID("_ShadowData"); |
|
|
|
|
|
|
m_CopyDepth = new RenderTargetIdentifier(CameraRenderTargetID.depthCopy); |
|
|
|
m_PostProcessRenderContext = new PostProcessRenderContext(); |
|
|
|
|
|
|
|
m_AmbientOcclusionRT = new RenderTargetIdentifier(PerCameraBuffer._AmbientOcclusionBuffer); |
|
|
|
|
|
|
|
m_CopyTextureSupport = SystemInfo.copyTextureSupport; |
|
|
|
|
|
|
|
for (int i = 0; i < kMaxCascades; ++i) |
|
|
|
|
|
|
{ |
|
|
|
DepthPass(ref context, frameRenderingConfiguration); |
|
|
|
|
|
|
|
RenderSSAO(m_CurrCamera, context, m_CameraPostProcessLayer); |
|
|
|
|
|
|
|
// Only screen space shadowmap mode is supported.
|
|
|
|
if (shadows) |
|
|
|
ShadowCollectPass(visibleLights, ref context, ref lightData, frameRenderingConfiguration); |
|
|
|
|
|
|
context.DrawRenderers(m_CullResults.visibleRenderers, ref debugViewDrawSettings, debugViewFilterSettings); |
|
|
|
|
|
|
|
EndForwardRendering(ref context, frameRenderingConfiguration); |
|
|
|
} |
|
|
|
|
|
|
|
private void RenderSSAO(Camera camera, ScriptableRenderContext context, PostProcessLayer postProcessLayer) |
|
|
|
{ |
|
|
|
CommandBuffer cmd = CommandBufferPool.Get("Render SSAO"); |
|
|
|
|
|
|
|
if(postProcessLayer != null && postProcessLayer.enabled) |
|
|
|
{ |
|
|
|
var settings = postProcessLayer.GetSettings<AmbientOcclusion>(); |
|
|
|
if(settings.IsEnabledAndSupported(null)) |
|
|
|
{ |
|
|
|
cmd.GetTemporaryRT(PerCameraBuffer._AmbientOcclusionBuffer, |
|
|
|
camera.pixelWidth, camera.pixelHeight, 0, |
|
|
|
FilterMode.Bilinear, RenderTextureFormat.R8); |
|
|
|
|
|
|
|
postProcessLayer.BakeMSVOMap(cmd, camera, m_AmbientOcclusionRT, m_DepthRT, true); |
|
|
|
|
|
|
|
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, m_AmbientOcclusionRT); |
|
|
|
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, new Vector4(settings.color.value.r, |
|
|
|
settings.color.value.g, |
|
|
|
settings.color.value.b, |
|
|
|
settings.directLightingStrength.value)); |
|
|
|
|
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cmd.SetGlobalTexture(PerCameraBuffer._AmbientOcclusionBuffer, RuntimeUtilities.blackTexture); |
|
|
|
cmd.SetGlobalVector(PerCameraBuffer._AmbientOcclusionParam, Vector4.zero); |
|
|
|
|
|
|
|
context.ExecuteCommandBuffer(cmd); |
|
|
|
CommandBufferPool.Release(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
private void ForwardPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled) |
|
|
|