浏览代码

Implemented depth copy pass. Fixed a case that was causing depth prepass to execute even when no directional shadows were rendered.

/main
Felipe Lira 7 年前
当前提交
c05148cf
共有 4 个文件被更改,包括 59 次插入46 次删除
  1. 21
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs
  2. 21
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  3. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  4. 55
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs

21
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs


{
public static int Color;
public static int Depth;
public static int DepthMS;
public static int DepthCopy;
public static int OpaqueColor;
public static int DirectionalShadowmap;
public static int LocalShadowmap;

// Samples (MSAA) depend on camera and pipeline
AddSurface("_CameraColorTexture", out RenderTargetHandles.Color);
AddSurface("_CameraDepthTexture", out RenderTargetHandles.Depth);
AddSurface("_CameraDepthMSTexture", out RenderTargetHandles.DepthMS);
AddSurface("_CameraDepthTextureCopy", out RenderTargetHandles.DepthCopy);
AddSurface("_CameraOpaqueTexture", out RenderTargetHandles.OpaqueColor);
AddSurface("_DirectionalShadowmapTexture", out RenderTargetHandles.DirectionalShadowmap);
AddSurface("_LocalShadowmapTexture", out RenderTargetHandles.LocalShadowmap);

SetupPerObjectLightIndices(ref cullResults, ref lightData);
RenderTextureDescriptor baseDescriptor = CreateRTDesc(ref cameraData);
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 requiresCameraDepth = cameraData.requiresDepthTexture || cameraData.postProcessEnabled;
bool requiresDepthPrepass = requiresCameraDepth && !supportsDepthCopy || requiresScreenSpaceOcclusion || requiresDepthPrepassToResolveMsaa;
bool requiresDepthPrepass = requiresCameraDepth && (!supportsDepthCopy || requiresScreenSpaceOcclusion || requiresDepthPrepassToResolveMsaa);
bool needsMsaaResolve = (msaaEnabledForCamera && !LightweightPipeline.PlatformSupportsMSAABackBuffer());
bool depthRenderBuffer = requiresCameraDepth && !requiresDepthPrepass;
(msaaEnabledForCamera &&
!LightweightPipeline.PlatformSupportsMSAABackBuffer());
needsMsaaResolve ||
depthRenderBuffer ||
cameraData.requiresOpaqueTexture;
if (requiresDepthPrepass)
{

}
int colorHandle = (intermediateRenderTexture) ? RenderTargetHandles.Color : -1;
int depthHandle = (requiresCameraDepth && !requiresDepthPrepass)
? ((msaaEnabledForCamera) ? RenderTargetHandles.DepthMS : RenderTargetHandles.Depth)
: -1;
int depthHandle = (depthRenderBuffer) ? RenderTargetHandles.Depth : -1;
forwardLitPass.colorHandles = new[] { colorHandle };
forwardLitPass.depthHandle = depthHandle;

21
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;
}
void InitializeShadowData(out ShadowData shadowData)
void InitializeShadowData(bool hasDirectionalShadowCastingLight, bool hasLocalShadowCastingLight, out ShadowData shadowData)
shadowData.supportsDirectionalShadows = pipelineAsset.SupportsDirectionalShadows;
shadowData.supportsDirectionalShadows = pipelineAsset.SupportsDirectionalShadows && hasDirectionalShadowCastingLight;
shadowData.requiresScreenSpaceOcclusion = shadowData.supportsDirectionalShadows && supportsScreenSpaceShadows;
shadowData.directionalLightCascadeCount = (shadowData.requiresScreenSpaceOcclusion) ? pipelineAsset.CascadeCount : 1;
shadowData.directionalShadowAtlasWidth = pipelineAsset.DirectionalShadowAtlasResolution;

break;
}
shadowData.supportsLocalShadows = pipelineAsset.SupportsLocalShadows;
shadowData.supportsLocalShadows = 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)
{
m_LocalLightIndices.Clear();
bool hasDirectionalShadowCastingLight = false;
bool hasLocalShadowCastingLight = false;
if (visibleLights[i].lightType != LightType.Directional)
bool castShadows = visibleLights[i].light.shadows != LightShadows.None;
if (visibleLights[i].lightType == LightType.Directional)
{
hasDirectionalShadowCastingLight |= castShadows;
}
else
{
hasLocalShadowCastingLight |= castShadows;
}
}
int visibleLightsCount = Math.Min(visibleLights.Count, pipelineAsset.MaxPixelLights);

lightData.totalAdditionalLightsCount = additionalPixelLightsCount + vertexLightCount;
lightData.visibleLights = visibleLights;
lightData.visibleLocalLightIndices = m_LocalLightIndices;
InitializeShadowData(out lightData.shadowData);
InitializeShadowData(hasDirectionalShadowCastingLight, hasLocalShadowCastingLight, out lightData.shadowData);
}
// Main Light is always a directional light

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


// Remaining light types don't support cookies
}
public static void CopyTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material)
{
if (SystemInfo.copyTextureSupport != CopyTextureSupport.None)
cmd.CopyTexture(source, dest);
else
cmd.Blit(source, dest, material);
}
public static bool IsSupportedShadowType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;

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


// Depth Copy Pass
Material m_DepthCopyMaterial;
const string k_MSAADepthKeyword = "_MSAA_DEPTH";
const string k_MsaaDepthKeyword = "_MSAA_DEPTH";
int m_SampleCountShaderHandle;
// Opaque Copy Pass

descriptor.depthBufferBits = k_DepthStencilBufferBits;
descriptor.msaaSamples = samples;
descriptor.bindMS = samples > 1;
cmd.GetTemporaryRT(colorHandles[1], descriptor, FilterMode.Point);
cmd.GetTemporaryRT(depthHandle, descriptor, FilterMode.Point);
}
m_Disposed = false;
}

if (cameraData.postProcessEnabled &&
cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
OpaquePostProcessPass(ref context, ref cameraData);
OpaquePostProcessSubPass(ref context, ref cameraData);
if (cameraData.requiresDepthTexture)
CopyDepthPass(ref context, ref cameraData);
if (depthHandle != -1 && cameraData.requiresDepthTexture)
CopyDepthSubPass(ref context, ref cameraData);
OpaqueTexturePass(ref context, ref cameraData);
CopyColorSubpass(ref context, ref cameraData);
// TODO: Move these to separate passes
if (cameraData.postProcessEnabled)
PostProcessPass(ref context, ref cameraData);

}
}
void OpaquePostProcessPass(ref ScriptableRenderContext context, ref CameraData cameraData)
void OpaquePostProcessSubPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects");

CommandBufferPool.Release(cmd);
}
void CopyDepthPass(ref ScriptableRenderContext context, ref CameraData cameraData)
void CopyDepthSubPass(ref ScriptableRenderContext context, ref CameraData cameraData)
if (depthHandle == RenderTargetHandles.DepthMS)
RenderTargetIdentifier depthSurface = GetSurface(RenderTargetHandles.Depth);
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthCopy);
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref cameraData);
descriptor.colorFormat = RenderTextureFormat.Depth;
descriptor.depthBufferBits = k_DepthStencilBufferBits;
cmd.GetTemporaryRT(RenderTargetHandles.DepthCopy, descriptor, FilterMode.Point);
if (cameraData.msaaSamples > 1)
cmd.EnableShaderKeyword(k_MSAADepthKeyword);
cmd.Blit(GetSurface(RenderTargetHandles.DepthMS), GetSurface(RenderTargetHandles.Depth), m_DepthCopyMaterial);
cmd.EnableShaderKeyword(k_MsaaDepthKeyword);
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial);
// TODO:
//cmd.Blit(GetSurface(RenderTargetHandle.Depth), depthCopy, m_DepthCopyMaterial);
cmd.DisableShaderKeyword(k_MsaaDepthKeyword);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
cmd.DisableShaderKeyword(k_MSAADepthKeyword);
cmd.SetGlobalTexture(RenderTargetHandles.Depth, copyDepthSurface);
// 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);
void OpaqueTexturePass(ref ScriptableRenderContext context, ref CameraData cameraData)
void CopyColorSubpass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Copy Opaque Color");
Downsampling downsampling = cameraData.opaqueTextureDownsampling;

cmd.Blit(colorRT, opaqueColorRT);
break;
}
//SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
正在加载...
取消
保存