|
|
|
|
|
|
private int m_ScreenSpaceShadowMapRTID; |
|
|
|
private Matrix4x4[] m_ShadowMatrices = new Matrix4x4[kMaxCascades + 1]; |
|
|
|
private RenderTargetIdentifier m_CurrCameraColorRT; |
|
|
|
private RenderTargetIdentifier m_ShadowMapRT; |
|
|
|
private RenderTexture m_ShadowMapRT; |
|
|
|
private RenderTargetIdentifier m_ScreenSpaceShadowMapRT; |
|
|
|
private RenderTargetIdentifier m_ColorRT; |
|
|
|
private RenderTargetIdentifier m_CopyColorRT; |
|
|
|
|
|
|
if (sceneViewCamera) |
|
|
|
CopyTexture(cmd, CameraRenderTargetID.depth, BuiltinRenderTextureType.CameraTarget, m_CopyDepthMaterial, true); |
|
|
|
#endif
|
|
|
|
cmd.ReleaseTemporaryRT(m_ShadowMapRTID); |
|
|
|
if (m_ShadowMapRT) |
|
|
|
{ |
|
|
|
cmd.ReleaseTemporaryRT(m_ShadowMapRTID); |
|
|
|
m_ShadowMapRT = null; |
|
|
|
} |
|
|
|
|
|
|
|
cmd.ReleaseTemporaryRT(m_ScreenSpaceShadowMapRTID); |
|
|
|
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy); |
|
|
|
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depth); |
|
|
|
|
|
|
|
|
|
|
private bool ShadowPass(List<VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData) |
|
|
|
{ |
|
|
|
m_ShadowMapRT = null; |
|
|
|
if (m_Asset.AreShadowsEnabled() && lightData.mainLightIndex != -1) |
|
|
|
{ |
|
|
|
VisibleLight mainLight = visibleLights[lightData.mainLightIndex]; |
|
|
|
|
|
|
float invShadowResolution = 1.0f / m_Asset.ShadowAtlasResolution; |
|
|
|
float invHalfShadowResolution = 0.5f * invShadowResolution; |
|
|
|
cmd.Clear(); |
|
|
|
cmd.SetGlobalTexture(m_ShadowMapRTID, m_ShadowMapRT); |
|
|
|
cmd.SetGlobalMatrixArray(ShadowConstantBuffer._WorldToShadow, m_ShadowMatrices); |
|
|
|
cmd.SetGlobalVector(ShadowConstantBuffer._ShadowData, new Vector4(light.shadowStrength, 0.0f, 0.0f, 0.0f)); |
|
|
|
cmd.SetGlobalVectorArray(ShadowConstantBuffer._DirShadowSplitSpheres, m_DirectionalShadowSplitDistances); |
|
|
|
|
|
|
bool success = false; |
|
|
|
|
|
|
|
var cmd = CommandBufferPool.Get("Prepare Shadowmap"); |
|
|
|
cmd.GetTemporaryRT(m_ShadowMapRTID, m_ShadowSettings.shadowAtlasWidth, |
|
|
|
m_ShadowSettings.shadowAtlasHeight, kShadowBufferBits, FilterMode.Bilinear, m_ShadowSettings.shadowmapTextureFormat); |
|
|
|
RenderTextureDescriptor shadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.shadowAtlasWidth, |
|
|
|
m_ShadowSettings.shadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, kShadowBufferBits); |
|
|
|
shadowmapDescriptor.shadowSamplingMode = ShadowSamplingMode.CompareDepths; |
|
|
|
m_ShadowMapRT = RenderTexture.GetTemporary(shadowmapDescriptor); |
|
|
|
m_ShadowMapRT.filterMode = FilterMode.Bilinear; |
|
|
|
m_ShadowMapRT.wrapMode = TextureWrapMode.Clamp; |
|
|
|
|
|
|
|
// LightweightPipeline.SetRenderTarget is meant to be used with camera targets, not shadowmaps
|
|
|
|
CoreUtils.SetRenderTarget(cmd, m_ShadowMapRT, ClearFlag.Depth, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor)); |
|
|
|
|
|
|
|