浏览代码

Fixed Texture2DMS resolve. Simplified renderer state by baking shadow settings into camera data.

/main
Felipe Lira 6 年前
当前提交
7b171db4
共有 9 个文件被更改,包括 162 次插入347 次删除
  1. 210
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs
  2. 218
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  3. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  4. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs
  5. 65
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs
  6. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LocalShadowsPass.cs
  7. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  8. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs.meta
  9. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs

210
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public enum RenderPassHandles
{
DepthPrepass,
DirectionalShadows,
LocalShadows,
ScreenSpaceShadowResolve,
ForwardLit,
Count,
}
public enum MaterialHandles
{
Error,

public static class RenderTargetHandles
{
public static int Color;
public static int Depth;
public static int DepthCopy;
public static int DepthAttachment;
public static int DepthTexture;
public static int OpaqueColor;
public static int DirectionalShadowmap;
public static int LocalShadowmap;

public FilterRenderersSettings opaqueFilterSettings { get; private set; }
public FilterRenderersSettings transparentFilterSettings { get; private set; }
//RenderGraphNode m_RenderGraph;
List<ScriptableRenderPass> m_ShadowPassList = new List<ScriptableRenderPass>();
List<ScriptableRenderPass> m_RenderPassList = new List<ScriptableRenderPass>();
Dictionary<int, Material> m_Materials = new Dictionary<int, Material>();
Dictionary<RenderPassHandles, ScriptableRenderPass> m_RenderPassSet = new Dictionary<RenderPassHandles, ScriptableRenderPass>();
DepthOnlyPass depthOnlyPass;
DirectionalShadowsPass directionalShadowPass;
LocalShadowsPass localShadowsPass;
ScreenSpaceShadowOcclusionPass screenSpaceShadowOcclusionPass;
ForwardLitPass forwardLitPass;
Dictionary<int, Material> m_Materials;
List<RenderPassAttachment> m_AttachmentList;
RenderPass m_RenderPass;
List<ScriptableRenderPass> m_ActiveShadowQueue = new List<ScriptableRenderPass>();
List<ScriptableRenderPass> m_ActiveRenderPassQueue = new List<ScriptableRenderPass>();
AddSurface("_CameraColorTexture", out RenderTargetHandles.Color);
AddSurface("_CameraDepthTexture", out RenderTargetHandles.Depth);
AddSurface("_CameraDepthTextureCopy", out RenderTargetHandles.DepthCopy);
AddSurface("_CameraOpaqueTexture", out RenderTargetHandles.OpaqueColor);
AddSurface("_DirectionalShadowmapTexture", out RenderTargetHandles.DirectionalShadowmap);
AddSurface("_LocalShadowmapTexture", out RenderTargetHandles.LocalShadowmap);
AddSurface("_ScreenSpaceShadowMapTexture", out RenderTargetHandles.ScreenSpaceOcclusion);
RegisterSurface("_CameraColorTexture", out RenderTargetHandles.Color);
RegisterSurface("_CameraDepthAttachment", out RenderTargetHandles.DepthAttachment);
RegisterSurface("_CameraDepthTexture", out RenderTargetHandles.DepthTexture);
RegisterSurface("_CameraOpaqueTexture", out RenderTargetHandles.OpaqueColor);
RegisterSurface("_DirectionalShadowmapTexture", out RenderTargetHandles.DirectionalShadowmap);
RegisterSurface("_LocalShadowmapTexture", out RenderTargetHandles.LocalShadowmap);
RegisterSurface("_ScreenSpaceShadowMapTexture", out RenderTargetHandles.ScreenSpaceOcclusion);
m_Materials = new Dictionary<int, Material>((int)MaterialHandles.Count);
m_Materials.Add((int)MaterialHandles.Error, CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"));
m_Materials.Add((int)MaterialHandles.DepthCopy, CoreUtils.CreateEngineMaterial(pipelineAsset.CopyDepthShader));
m_Materials.Add((int)MaterialHandles.Sampling, CoreUtils.CreateEngineMaterial(pipelineAsset.SamplingShader));
m_Materials.Add((int)MaterialHandles.Blit, CoreUtils.CreateEngineMaterial(pipelineAsset.BlitShader));
m_Materials.Add((int)MaterialHandles.ScrenSpaceShadow, CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader));
Debug.Assert(m_Materials.Count == (int)MaterialHandles.Count, "All materials in MaterialHandles should be created.");
RegisterMaterial(MaterialHandles.Error, CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"));
RegisterMaterial(MaterialHandles.DepthCopy, CoreUtils.CreateEngineMaterial(pipelineAsset.CopyDepthShader));
RegisterMaterial(MaterialHandles.Sampling, CoreUtils.CreateEngineMaterial(pipelineAsset.SamplingShader));
RegisterMaterial(MaterialHandles.Blit, CoreUtils.CreateEngineMaterial(pipelineAsset.BlitShader));
RegisterMaterial(MaterialHandles.ScrenSpaceShadow, CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader));
Debug.Assert(m_Materials.Count == (int)MaterialHandles.Count, "All materials in MaterialHandles should be registered in the renderer.");
depthOnlyPass = new DepthOnlyPass(this);
directionalShadowPass = new DirectionalShadowsPass(this, pipelineAsset.DirectionalShadowAtlasResolution);
localShadowsPass = new LocalShadowsPass(this, pipelineAsset.LocalShadowAtlasResolution);
screenSpaceShadowOcclusionPass = new ScreenSpaceShadowOcclusionPass(this);
forwardLitPass = new ForwardLitPass(this);
RegisterPass(RenderPassHandles.DepthPrepass, new DepthOnlyPass(this));
RegisterPass(RenderPassHandles.DirectionalShadows, new DirectionalShadowsPass(this, pipelineAsset.DirectionalShadowAtlasResolution));
RegisterPass(RenderPassHandles.LocalShadows, new LocalShadowsPass(this, pipelineAsset.LocalShadowAtlasResolution));
RegisterPass(RenderPassHandles.ScreenSpaceShadowResolve, new ScreenSpaceShadowResolvePass(this));
RegisterPass(RenderPassHandles.ForwardLit, new ForwardLitPass(this));
Debug.Assert(m_RenderPassSet.Count == (int)RenderPassHandles.Count, "All render passes in Passes should be registered in the renderer");
postProcessRenderContext = new PostProcessRenderContext();

return m_Materials[resourceHandleID];
}
void AddSurface(string shaderProperty, out int handle)
{
handle = Shader.PropertyToID(shaderProperty);
m_ResourceMap.Add(handle, new RenderTargetIdentifier(handle));
}
public RenderTextureDescriptor CreateRTDesc(ref CameraData cameraData, float scaler = 1.0f)
{
Camera camera = cameraData.camera;

public void Setup(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)
{
CommandBuffer cmd = CommandBufferPool.Get("Setup Rendering");
m_ShadowPassList.Clear();
m_RenderPassList.Clear();
Clear();
bool requiresCameraDepth = cameraData.requiresDepthTexture || cameraData.postProcessEnabled || cameraData.isSceneViewCamera;
bool shadowsEnabledForCamera = cameraData.maxShadowDistance > 0.0f;
bool msaaEnabledForCamera = cameraData.msaaSamples > 1;
bool supportsTexture2DMS = SystemInfo.supportsMultisampledTextures != 0;
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None;
bool copyShaderSupported = GetMaterial(MaterialHandles.DepthCopy).shader.isSupported && (msaaEnabledForCamera == supportsTexture2DMS);
bool supportsDepthCopy = copyShaderSupported || supportsTextureCopy;
bool requiresDepthPrepassToResolveMsaa = msaaEnabledForCamera && !supportsTexture2DMS;
bool renderDirectionalShadows = shadowsEnabledForCamera && lightData.shadowData.supportsDirectionalShadows;
bool requiresScreenSpaceShadows = renderDirectionalShadows && lightData.shadowData.requiresScreenSpaceOcclusion;
bool requiresDepthPrepass = requiresScreenSpaceShadows || (requiresCameraDepth && (!supportsDepthCopy || requiresDepthPrepassToResolveMsaa));
bool requiresCameraDepth = cameraData.requiresDepthTexture;
bool depthRenderBuffer = requiresCameraDepth && !requiresDepthPrepass;
bool intermediateRenderTexture = cameraData.isSceneViewCamera ||
!Mathf.Approximately(cameraData.renderScale, 1.0f) ||
cameraData.isHdrEnabled ||
baseDescriptor.dimension == TextureDimension.Tex2DArray ||
cameraData.postProcessEnabled ||
depthRenderBuffer ||
cameraData.requiresOpaqueTexture;
ShadowData shadowData = lightData.shadowData;
bool requiresDepthPrepass = shadowData.requiresScreenSpaceShadowResolve || cameraData.isSceneViewCamera || (requiresCameraDepth && !CanCopyDepth(ref cameraData));
CommandBuffer cmd = CommandBufferPool.Get("Setup Rendering");
{
depthOnlyPass.Setup(cmd, baseDescriptor, null, RenderTargetHandles.Depth);
m_RenderPassList.Add(depthOnlyPass);
}
EnqueuePass(cmd, RenderPassHandles.DepthPrepass, baseDescriptor, null, RenderTargetHandles.DepthTexture);
if (renderDirectionalShadows)
if (shadowData.renderDirectionalShadows)
directionalShadowPass.Setup(cmd, baseDescriptor);
m_ShadowPassList.Add(directionalShadowPass);
if (requiresScreenSpaceShadows)
{
screenSpaceShadowOcclusionPass.Setup(cmd, baseDescriptor, new[] {RenderTargetHandles.ScreenSpaceOcclusion});
m_RenderPassList.Add(screenSpaceShadowOcclusionPass);
}
EnqueuePass(cmd, RenderPassHandles.DirectionalShadows, baseDescriptor);
if (shadowData.requiresScreenSpaceShadowResolve)
EnqueuePass(cmd, RenderPassHandles.ScreenSpaceShadowResolve, baseDescriptor, new[] {RenderTargetHandles.ScreenSpaceOcclusion});
if (shadowsEnabledForCamera && lightData.shadowData.supportsLocalShadows)
{
localShadowsPass.Setup(cmd, baseDescriptor);
m_ShadowPassList.Add(localShadowsPass);
}
if (shadowData.renderLocalShadows)
EnqueuePass(cmd, RenderPassHandles.LocalShadows, baseDescriptor);
int[] colorHandles = (intermediateRenderTexture) ? new[] {RenderTargetHandles.Color} : null;
int depthHandle = (depthRenderBuffer) ? RenderTargetHandles.Depth : -1;
forwardLitPass.Setup(cmd, baseDescriptor, colorHandles, depthHandle, cameraData.msaaSamples);
m_RenderPassList.Add(forwardLitPass);
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment = RequiresColorAttachment(ref cameraData, baseDescriptor) || requiresDepthAttachment;
int[] colorHandles = (requiresColorAttachment) ? new[] {RenderTargetHandles.Color} : null;
int depthHandle = (requiresColorAttachment) ? RenderTargetHandles.DepthAttachment : -1;
EnqueuePass(cmd, RenderPassHandles.ForwardLit, baseDescriptor, colorHandles, depthHandle, cameraData.msaaSamples);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

ref LightData lightData)
{
for (int i = 0; i < m_ShadowPassList.Count; ++i)
m_ShadowPassList[i].Execute(ref context, ref cullResults, ref cameraData, ref lightData);
// TODO: The reason we have to separate passes into two queues is because shadows require different camera
// context. We need to take a look at approaches to effectively share shadow between cameras, then we
// can move this out
for (int i = 0; i < m_ActiveShadowQueue.Count; ++i)
m_ActiveShadowQueue[i].Execute(ref context, ref cullResults, ref cameraData, ref lightData);
// SetupCameraProperties does the following:
// Setup Camera RenderTarget and Viewport

// Setup global time properties (_Time, _SinTime, _CosTime)
context.SetupCameraProperties(cameraData.camera, cameraData.isStereoEnabled);
for (int i = 0; i < m_RenderPassList.Count; ++i)
m_RenderPassList[i].Execute(ref context, ref cullResults, ref cameraData, ref lightData);
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].Execute(ref context, ref cullResults, ref cameraData, ref lightData);
#if UNITY_EDITOR
if (cameraData.isSceneViewCamera)

DisposePasses(ref context);
}
void Clear()
{
m_ActiveShadowQueue.Clear();
m_ActiveRenderPassQueue.Clear();
}
void RegisterSurface(string shaderProperty, out int handle)
{
handle = Shader.PropertyToID(shaderProperty);
m_ResourceMap.Add(handle, new RenderTargetIdentifier(handle));
}
void RegisterMaterial(MaterialHandles handle, Material material)
{
m_Materials.Add((int)handle, material);
}
void RegisterPass(RenderPassHandles passHandle, ScriptableRenderPass pass)
{
m_RenderPassSet.Add(passHandle, pass);
}
void EnqueuePass(CommandBuffer cmd, RenderPassHandles passHandle, RenderTextureDescriptor baseDescriptor,
int[] colorAttachmentHandles = null, int depthAttachmentHandle = -1, int samples = 1)
{
Debug.Assert((int)passHandle < m_RenderPassSet.Count, "Trying to add an invalid pass to renderer's frame");
ScriptableRenderPass pass = m_RenderPassSet[passHandle];
pass.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
if (passHandle == RenderPassHandles.DirectionalShadows || passHandle == RenderPassHandles.LocalShadows)
m_ActiveShadowQueue.Add(pass);
else
m_ActiveRenderPassQueue.Add(pass);
}
bool RequiresColorAttachment(ref CameraData cameraData, RenderTextureDescriptor baseDescriptor)
{
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f);
bool isTargetTexture2DArray = baseDescriptor.dimension == TextureDimension.Tex2DArray;
return cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || isTargetTexture2DArray;
}
bool CanCopyDepth(ref CameraData cameraData)
{
bool msaaEnabledForCamera = cameraData.msaaSamples > 1;
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None;
bool supportsDepthTarget = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth);
bool supportsDepthCopy = !msaaEnabledForCamera && (supportsDepthTarget || supportsTextureCopy);
bool msaaDepthResolve = msaaEnabledForCamera && SystemInfo.supportsMultisampledTextures != 0;
return supportsDepthCopy || msaaDepthResolve;
}
// Note: Scene view camera always perform depth prepass
cmd.Blit(GetSurface(RenderTargetHandles.Depth), BuiltinRenderTextureType.CameraTarget, GetMaterial(MaterialHandles.DepthCopy));
cmd.Blit(GetSurface(RenderTargetHandles.DepthTexture), BuiltinRenderTextureType.CameraTarget, GetMaterial(MaterialHandles.DepthCopy));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

CommandBuffer cmd = CommandBufferPool.Get("Release Resources");
for (int i = 0; i < m_ShadowPassList.Count; ++i)
m_ShadowPassList[i].Dispose(cmd);
for (int i = 0; i < m_ActiveShadowQueue.Count; ++i)
m_ActiveShadowQueue[i].Dispose(cmd);
for (int i = 0; i < m_RenderPassList.Count; ++i)
m_RenderPassList[i].Dispose(cmd);
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].Dispose(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

218
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


List<VisibleLight> visibleLights = m_CullResults.visibleLights;
LightData lightData;
InitializeLightData(visibleLights, m_Renderer.maxSupportedLocalLightsPerPass, m_Renderer.maxSupportedVertexLights, out lightData);
InitializeLightData(ref cameraData, visibleLights, m_Renderer.maxSupportedLocalLightsPerPass, m_Renderer.maxSupportedVertexLights, out lightData);
m_Renderer.Setup(ref context, ref m_CullResults, ref cameraData, ref lightData);
m_Renderer.Execute(ref context, ref m_CullResults, ref cameraData, ref lightData);

cameraData.msaaSamples = 1;
cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
cameraData.isOffscreenRender = camera.targetTexture != null && !cameraData.isSceneViewCamera;
cameraData.isStereoEnabled = IsStereoEnabled(camera);
cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.SupportsHDR;
cameraData.postProcessLayer = camera.GetComponent<PostProcessLayer>();
cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;
// PostProcess for VR is not working atm. Disable it for now.
cameraData.postProcessEnabled &= !cameraData.isStereoEnabled;
cameraData.isOffscreenRender = camera.targetTexture != null && !cameraData.isSceneViewCamera;
cameraData.isStereoEnabled = IsStereoEnabled(camera);
cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.SupportsHDR;
// Discard variations lesser than kRenderScaleThreshold.
// Scale is only enabled for gameview
// XR has it's own scaling mechanism.

cameraData.requiresDepthTexture = pipelineAsset.RequireDepthTexture;
cameraData.requiresDepthTexture = pipelineAsset.RequireDepthTexture || cameraData.postProcessEnabled || cameraData.isSceneViewCamera;
cameraData.requiresSoftParticles = pipelineAsset.RequireSoftParticles;
cameraData.requiresOpaqueTexture = pipelineAsset.RequireOpaqueTexture;
cameraData.opaqueTextureDownsampling = pipelineAsset.OpaqueDownsampling;

cameraData.postProcessLayer = camera.GetComponent<PostProcessLayer>();
cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;
}
void InitializeShadowData(bool hasDirectionalShadowCastingLight, bool hasLocalShadowCastingLight, out ShadowData shadowData)

shadowData.supportsDirectionalShadows = pipelineAsset.SupportsDirectionalShadows && hasDirectionalShadowCastingLight;
shadowData.requiresScreenSpaceOcclusion = shadowData.supportsDirectionalShadows && supportsScreenSpaceShadows;
shadowData.directionalLightCascadeCount = (shadowData.requiresScreenSpaceOcclusion) ? pipelineAsset.CascadeCount : 1;
shadowData.renderDirectionalShadows = pipelineAsset.SupportsDirectionalShadows && hasDirectionalShadowCastingLight;
shadowData.requiresScreenSpaceShadowResolve = shadowData.renderDirectionalShadows && supportsScreenSpaceShadows;
shadowData.directionalLightCascadeCount = (shadowData.requiresScreenSpaceShadowResolve) ? pipelineAsset.CascadeCount : 1;
shadowData.directionalShadowAtlasWidth = pipelineAsset.DirectionalShadowAtlasResolution;
shadowData.directionalShadowAtlasHeight = pipelineAsset.DirectionalShadowAtlasResolution;

break;
}
shadowData.supportsLocalShadows = pipelineAsset.SupportsLocalShadows && hasLocalShadowCastingLight;
shadowData.renderLocalShadows = pipelineAsset.SupportsLocalShadows && hasLocalShadowCastingLight;
shadowData.localShadowAtlasWidth = shadowData.localShadowAtlasHeight = pipelineAsset.LocalShadowAtlasResolution;
shadowData.supportsSoftShadows = pipelineAsset.SupportsSoftShadows;
shadowData.bufferBitCount = 16;

}
void InitializeLightData(List<VisibleLight> visibleLights, int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights, out LightData lightData)
void InitializeLightData(ref CameraData cameraData, List<VisibleLight> visibleLights, int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights, out LightData lightData)
for (int i = 0; i < visibleLights.Count; ++i)
if (cameraData.maxShadowDistance > 0.0f)
bool castShadows = visibleLights[i].light.shadows != LightShadows.None;
if (visibleLights[i].lightType == LightType.Directional)
{
hasDirectionalShadowCastingLight |= castShadows;
}
else
for (int i = 0; i < visibleLights.Count; ++i)
hasLocalShadowCastingLight |= castShadows;
m_LocalLightIndices.Add(i);
bool castShadows = visibleLights[i].light.shadows != LightShadows.None;
if (visibleLights[i].lightType == LightType.Directional)
{
hasDirectionalShadowCastingLight |= castShadows;
}
else
{
hasLocalShadowCastingLight |= castShadows;
m_LocalLightIndices.Add(i);
}
}
}

else
cameraData.postProcessLayer.Render(context);
}
//private void SetupFrameRenderingConfiguration(out FrameRenderingConfiguration configuration, bool screenspaceShadows, bool stereoEnabled, bool sceneViewCamera)
//{
//configuration = (stereoEnabled) ? FrameRenderingConfiguration.Stereo : FrameRenderingConfiguration.None;
//if (stereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
// m_IntermediateTextureArray = true;
//else
// m_IntermediateTextureArray = false;
//bool hdrEnabled = m_Asset.SupportsHDR && m_CurrCamera.allowHDR;
//bool defaultRenderScale = Mathf.Approximately(GetRenderScale(), 1.0f);
//bool intermediateTexture = m_CurrCamera.targetTexture != null || m_CurrCamera.cameraType == CameraType.SceneView ||
// !defaultRenderScale || hdrEnabled;
//m_ColorFormat = hdrEnabled ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
//m_RequireCopyColor = false;
//m_DepthRenderBuffer = false;
//m_CameraPostProcessLayer = m_CurrCamera.GetComponent<PostProcessLayer>();
//bool msaaEnabled = m_CurrCamera.allowMSAA && m_Asset.MsaaSampleCount > 1 && (m_CurrCamera.targetTexture == null || m_CurrCamera.targetTexture.antiAliasing > 1);
// TODO: PostProcessing and SoftParticles are currently not support for VR
//bool postProcessEnabled = m_CameraPostProcessLayer != null && m_CameraPostProcessLayer.enabled && !stereoEnabled;
//m_RequireDepthTexture = m_Asset.RequireDepthTexture && !stereoEnabled;
//bool canSkipDepthCopy = !m_RequireDepthTexture;
//if (postProcessEnabled)
//{
// m_RequireDepthTexture = true;
// intermediateTexture = true;
// configuration |= FrameRenderingConfiguration.PostProcess;
// if (m_CameraPostProcessLayer.HasOpaqueOnlyEffects(m_PostProcessRenderContext))
// {
// configuration |= FrameRenderingConfiguration.BeforeTransparentPostProcess;
// if (m_CameraPostProcessLayer.sortedBundles[PostProcessEvent.BeforeTransparent].Count == 1)
// m_RequireCopyColor = true;
// }
//}
//if (sceneViewCamera)
//{
// m_RequireDepthTexture = true;
// canSkipDepthCopy = false;
//}
//m_RequireDepthTexture = m_RequireDepthTexture || screenspaceShadows;
//canSkipDepthCopy = canSkipDepthCopy && !screenspaceShadows;
//if (msaaEnabled)
//{
// configuration |= FrameRenderingConfiguration.Msaa;
// intermediateTexture = intermediateTexture || !PlatformSupportsMSAABackBuffer();
// canSkipDepthCopy = false;
//}
//if (m_RequireDepthTexture)
//{
// bool hasTex2DMS = SystemInfo.supportsMultisampledTextures != 0;
// bool copyShaderSupported = m_Asset.CopyDepthShader.isSupported && (msaaEnabled == hasTex2DMS);
// bool supportsDepthCopy = m_CopyTextureSupport != CopyTextureSupport.None || copyShaderSupported;
// bool requiresDepthPrepassToResolveMSAA = msaaEnabled && !hasTex2DMS;
// bool requiresDepthPrepass = !supportsDepthCopy || screenspaceShadows || requiresDepthPrepassToResolveMSAA;
// m_DepthRenderBuffer = !requiresDepthPrepass;
// intermediateTexture = intermediateTexture || m_DepthRenderBuffer;
// if (requiresDepthPrepass)
// configuration |= FrameRenderingConfiguration.DepthPrePass;
// else if (supportsDepthCopy && !canSkipDepthCopy)
// configuration |= FrameRenderingConfiguration.DepthCopy;
//}
//Rect cameraRect = m_CurrCamera.rect;
//if (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f))
// configuration |= FrameRenderingConfiguration.DefaultViewport;
//else
// intermediateTexture = true;
//if (intermediateTexture)
// configuration |= FrameRenderingConfiguration.IntermediateTexture;
//}
//private void SetupIntermediateResources(FrameRenderingConfiguration renderingConfig, bool shadows, ref ScriptableRenderContext context)
//{
// CommandBuffer cmd = CommandBufferPool.Get("Setup Intermediate Resources");
// m_CurrCameraColorRT = BuiltinRenderTextureType.CameraTarget;
// if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture) || m_RequireDepthTexture)
// SetupIntermediateRenderTextures(cmd, renderingConfig, shadows, msaaSamples);
// context.ExecuteCommandBuffer(cmd);
// CommandBufferPool.Release(cmd);
//}
//private void SetupIntermediateRenderTextures(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, bool shadows, int msaaSamples)
//{
// RenderTextureDescriptor baseDesc = CreateRTDesc(renderingConfig);
// if (m_RequireDepthTexture)
// {
// var depthRTDesc = baseDesc;
// depthRTDesc.colorFormat = RenderTextureFormat.Depth;
// depthRTDesc.depthBufferBits = kDepthStencilBufferBits;
// // This also means we don't do a depth copy
// bool doesDepthPrepass = CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthPrePass);
// if (doesDepthPrepass)
// m_DepthOnlyPass.BindSurface(cmd, baseDesc, msaaSamples);
// //if (!doesDepthPrepass)
// //{
// // depthRTDesc.bindMS = msaaSamples > 1;
// // depthRTDesc.msaaSamples = msaaSamples;
// //}
// //cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Point);
// if (!doesDepthPrepass)
// {
// depthRTDesc.bindMS = false;
// depthRTDesc.msaaSamples = 1;
// cmd.GetTemporaryRT(CameraRenderTargetID.depthCopy, depthRTDesc, FilterMode.Point);
// }
// m_ShadowPass.BindSurface(cmd, baseDesc, 1);
// }
// var colorRTDesc = baseDesc;
// colorRTDesc.colorFormat = m_ColorFormat;
// colorRTDesc.depthBufferBits = kDepthStencilBufferBits; // TODO: does the color RT always need depth?
// colorRTDesc.sRGB = true;
// colorRTDesc.msaaSamples = msaaSamples;
// colorRTDesc.enableRandomWrite = false;
// // When offscreen camera current rendertarget is CameraTarget
// if (!m_IsOffscreenCamera)
// {
// cmd.GetTemporaryRT(CameraRenderTargetID.color, colorRTDesc, FilterMode.Bilinear);
// m_CurrCameraColorRT = m_ColorRT;
// }
// // When BeforeTransparent PostFX is enabled and only one effect is in the stack we need to create a temp
// // color RT to blit the effect.
// if (m_RequireCopyColor)
// cmd.GetTemporaryRT(CameraRenderTargetID.copyColor, colorRTDesc, FilterMode.Point);
//}
//public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, ClearFlag clearFlag = ClearFlag.None)
//{
// int depthSlice = (m_IntermediateTextureArray) ? -1 : 0;
// CoreUtils.SetRenderTarget(cmd, colorRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, depthSlice);
//}
//public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderTargetIdentifier depthRT, ClearFlag clearFlag = ClearFlag.None)
//{
// if (depthRT == BuiltinRenderTextureType.None || !m_DepthRenderBuffer)
// {
// SetRenderTarget(cmd, colorRT, clearFlag);
// return;
// }
// int depthSlice = (m_IntermediateTextureArray) ? -1 : 0;
// CoreUtils.SetRenderTarget(cmd, colorRT, depthRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, depthSlice);
//}
public static void Blit(CommandBuffer cmd, ref CameraData cameraData, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null)
{

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


public struct ShadowData
{
public bool supportsDirectionalShadows;
public bool requiresScreenSpaceOcclusion;
public bool renderDirectionalShadows;
public bool requiresScreenSpaceShadowResolve;
public bool supportsLocalShadows;
public bool renderLocalShadows;
public int localShadowAtlasWidth;
public int localShadowAtlasHeight;
public bool supportsSoftShadows;

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs


Clear();
ShadowData shadowData = lightData.shadowData;
if (shadowData.supportsDirectionalShadows)
if (shadowData.renderDirectionalShadows)
lightData.shadowData.renderedDirectionalShadowQuality = RenderDirectionalCascadeShadowmap(ref context, ref cullResults, ref lightData, ref shadowData);
}

// In order to avoid shader variants explosion we only do hard shadows when sampling shadowmap in the lit pass.
// GLES2 platform is forced to hard single cascade shadows.
if (!shadowData.requiresScreenSpaceOcclusion)
if (!shadowData.requiresScreenSpaceShadowResolve)
shadowQuality = LightShadows.Hard;
SetupDirectionalShadowReceiverConstants(ref context, cmd, ref shadowData, shadowLight);

65
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs


}
}
void AfterOpaque(ref ScriptableRenderContext context, ref CameraData cameraData)
{
//if (m_RequireDepthTexture)
//{
// CommandBuffer cmd = CommandBufferPool.Get("After Opaque");
// bool setRenderTarget = false;
// RenderTargetIdentifier depthRT = m_DepthRT;
// // TODO: There's currently an issue in the PostFX stack that has a one frame delay when an effect is enabled/disabled
// // when an effect is disabled, HasOpaqueOnlyEffects returns true in the first frame, however inside render the effect
// // state is update, causing RenderPostProcess here to not blit to FinalColorRT. Until the next frame the RT will have garbage.
// if (CoreUtils.HasFlag(config, FrameRenderingConfiguration.BeforeTransparentPostProcess))
// {
// // When only have one effect in the stack we blit to a work RT then blit it back to active color RT.
// // This seems like an extra blit but it saves us a depth copy/blit which has some corner cases like msaa depth resolve.
// if (m_RequireCopyColor)
// {
// RenderPostProcess(cmd, m_CurrCameraColorRT, m_CopyColorRT, true);
// cmd.Blit(m_CopyColorRT, m_CurrCameraColorRT);
// }
// else
// RenderPostProcess(cmd, m_CurrCameraColorRT, m_CurrCameraColorRT, true);
// setRenderTarget = true;
// SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);
// }
// if (CoreUtils.HasFlag(config, FrameRenderingConfiguration.DepthCopy))
// {
// bool forceBlit = false;
// if (m_MSAASamples > 1)
// {
// cmd.SetGlobalFloat(m_SampleCount, (float)m_MSAASamples);
// cmd.EnableShaderKeyword(kMSAADepthKeyword);
// forceBlit = true;
// }
// else
// cmd.DisableShaderKeyword(kMSAADepthKeyword);
// CopyTexture(cmd, m_DepthRT, m_CopyDepth, m_CopyDepthMaterial, forceBlit);
// depthRT = m_CopyDepth;
// setRenderTarget = true;
// cmd.SetGlobalTexture(RenderTargetHandle.Depth, m_CopyDepth);
// }
// if (setRenderTarget)
// SetRenderTarget(cmd, m_CurrCameraColorRT, depthRT);
// context.ExecuteCommandBuffer(cmd);
// CommandBufferPool.Release(cmd);
//}
}
// TODO: move to postfx pass
void PostProcessPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{

{
CommandBuffer cmd = CommandBufferPool.Get("Depth Copy");
RenderTargetIdentifier depthSurface = GetSurface(depthAttachmentHandle);
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthCopy);
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthTexture);
cmd.GetTemporaryRT(RenderTargetHandles.DepthCopy, descriptor, FilterMode.Point);
cmd.GetTemporaryRT(RenderTargetHandles.DepthTexture, descriptor, FilterMode.Point);
cmd.SetGlobalFloat(m_SampleCountShaderHandle, cameraData.msaaSamples);
m_DepthCopyMaterial.SetFloat(m_SampleCountShaderHandle, cameraData.msaaSamples);
m_DepthCopyMaterial.EnableKeyword(k_MsaaDepthKeyword);
cmd.DisableShaderKeyword(k_MsaaDepthKeyword);
m_DepthCopyMaterial.DisableKeyword(k_MsaaDepthKeyword);
//cmd.SetGlobalTexture(RenderTargetHandles.Depth, copyDepthSurface);
m_DepthCopyMaterial.DisableKeyword(k_MsaaDepthKeyword);
}
void CopyColorSubpass(ref ScriptableRenderContext context, ref CameraData cameraData)

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LocalShadowsPass.cs


{
Clear();
ShadowData shadowData = lightData.shadowData;
if (shadowData.supportsLocalShadows)
if (shadowData.renderLocalShadows)
lightData.shadowData.renderedLocalShadowQuality = RenderLocalShadowmapAtlas(ref context, ref cullResults, ref lightData, ref shadowData);
}

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class ScreenSpaceShadowOcclusionPass : ScriptableRenderPass
public class ScreenSpaceShadowResolvePass : ScriptableRenderPass
{
public bool softShadows { get; set; }

public ScreenSpaceShadowOcclusionPass(LightweightForwardRenderer renderer) : base(renderer)
public ScreenSpaceShadowResolvePass(LightweightForwardRenderer renderer) : base(renderer)
{
m_ColorFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8)
? RenderTextureFormat.R8

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowOcclusionPass.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs.meta

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowOcclusionPass.cs → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs

正在加载...
取消
保存