浏览代码

Fixed DepthCopy shader. Disabled depth resolve on VR until we can properly figure out how to resolve texture2DMS in stereo.

/main
Felipe Lira 6 年前
当前提交
3160d4ad
共有 5 个文件被更改,包括 51 次插入34 次删除
  1. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs
  2. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  3. 19
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs
  4. 48
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl
  5. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs


bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
renderingData.cameraData.isSceneViewCamera || (requiresCameraDepth && !CanCopyDepth(ref renderingData.cameraData));
// For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;
CommandBuffer cmd = CommandBufferPool.Get("Setup Rendering");
if (requiresDepthPrepass)
EnqueuePass(cmd, RenderPassHandles.DepthPrepass, baseDescriptor, null, RenderTargetHandles.DepthTexture);

// Note: Scene view camera always perform depth prepass
CommandBuffer cmd = CommandBufferPool.Get("Copy Depth to Camera");
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
cmd.DisableShaderKeyword(LightweightKeywords.MsaaDepthResolve);
cmd.EnableShaderKeyword(LightweightKeywords.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa4);
cmd.Blit(GetSurface(RenderTargetHandles.DepthTexture), BuiltinRenderTextureType.CameraTarget, GetMaterial(MaterialHandles.DepthCopy));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


public static readonly string LocalShadowsText = "_LOCAL_SHADOWS_ENABLED";
public static readonly string SoftShadowsText = "_SHADOWS_SOFT";
public static readonly string CascadeShadowsText = "_SHADOWS_CASCADE";
public static readonly string MsaaDepthResolve = "_MSAA_DEPTH";
public static readonly string DepthNoMsaa = "_DEPTH_NO_MSAA";
public static readonly string DepthMsaa2 = "_DEPTH_MSAA_2";
public static readonly string DepthMsaa4 = "_DEPTH_MSAA_4";
#if UNITY_2018_2_OR_NEWER
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword(AdditionalLightsText);

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


// Depth Copy Pass
Material m_DepthCopyMaterial;
int m_SampleCountShaderHandle;
// Opaque Copy Pass
Material m_SamplingMaterial;

// Copy Depth Pass
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy);
m_SampleCountShaderHandle = Shader.PropertyToID("_SampleCount");
// Copy Opaque Color Pass
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling);

if (cameraData.msaaSamples > 1)
{
cmd.SetGlobalFloat(m_SampleCountShaderHandle, cameraData.msaaSamples);
cmd.EnableShaderKeyword(LightweightKeywords.MsaaDepthResolve);
cmd.DisableShaderKeyword(LightweightKeywords.DepthNoMsaa);
if (cameraData.msaaSamples == 4)
{
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa2);
cmd.EnableShaderKeyword(LightweightKeywords.DepthMsaa4);
}
else
{
cmd.EnableShaderKeyword(LightweightKeywords.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa4);
}
cmd.DisableShaderKeyword(LightweightKeywords.MsaaDepthResolve);
cmd.EnableShaderKeyword(LightweightKeywords.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywords.DepthMsaa4);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
context.ExecuteCommandBuffer(cmd);

48
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl


}
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define DEPTH_TEXTURE_MS Texture2DMSArray
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMSArray<float, samples> name
#define DEPTH_TEXTURE_MS Texture2DMS
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMS<float, samples> name
#ifdef _MSAA_DEPTH
DEPTH_TEXTURE_MS<float> _CameraDepthAttachment;
float _SampleCount;
float4 _CameraDepthAttachment_TexelSize;
#else
#ifdef _DEPTH_MSAA_2
#define MSAA_SAMPLES 2
#elif _DEPTH_MSAA_4
#define MSAA_SAMPLES 4
#endif
#ifdef _DEPTH_NO_MSAA
#else
DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
float4 _CameraDepthAttachment_TexelSize;
#endif
#if UNITY_REVERSED_Z
#define DEPTH_DEFAULT_VALUE 1.0
#define DEPTH_OP min
#else
#define DEPTH_DEFAULT_VALUE 0.0
#define DEPTH_OP max
#ifdef _MSAA_DEPTH
#ifdef _DEPTH_NO_MSAA
return SAMPLE(uv);
#else
int samples = (int)_SampleCount;
#if UNITY_REVERSED_Z
float outDepth = 1.0;
#define DEPTH_OP min
#else
float outDepth = 0.0;
#define DEPTH_OP max
#endif
for (int i = 0; i < samples; ++i)
outDepth = DEPTH_OP(LOAD(uv, i), outDepth);
float outDepth = DEPTH_DEFAULT_VALUE;
[unroll]
for (int i = 0; i < MSAA_SAMPLES; ++i)
outDepth = DEPTH_OP(LOAD(coord, i), outDepth);
#else
return SAMPLE(uv);
#endif
}

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader


Shader "Hidden/LightweightPipeline/CopyDepth"
{
Properties
{
[HideInInspector] _SampleCount("MSAA sample count", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"}

#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ _MSAA_DEPTH
#pragma multi_compile _DEPTH_NO_MSAA _DEPTH_MSAA_2 _DEPTH_MSAA_4
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"

正在加载...
取消
保存