浏览代码

Merged CopyDepth and CopyDepthMSAA shaders into one and created a keyword to control the differences.

/main
Aleksandr Kirillov 7 年前
当前提交
a4adefcb
共有 8 个文件被更改,包括 26 次插入63 次删除
  1. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.asset
  3. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs
  4. 32
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  5. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl
  6. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader
  7. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader.meta
  8. 30
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


get { return resources != null ? resources.CopyDepthShader : null; }
}
public Shader CopyDepthMSAAShader
{
get { return resources != null ? resources.CopyDepthMSAAShader : null; }
}
public Shader ScreenSpaceShadowShader
{
get { return resources != null ? resources.ScreenSpaceShadowShader : null; }

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.asset


m_EditorClassIdentifier:
BlitShader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
CopyDepthShader: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
CopyDepthMSAAShader: {fileID: 4800000, guid: 3aaf3bbc87e49413fa5019b840757406, type: 3}
ScreenSpaceShadowShader: {fileID: 4800000, guid: 0f854b35a0cf61a429bd5dcfea30eddd,
type: 3}
SamplingShader: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3}

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs


{
public Shader BlitShader;
public Shader CopyDepthShader;
public Shader CopyDepthMSAAShader;
public Shader ScreenSpaceShadowShader;
public Shader SamplingShader;
}

32
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private static readonly float kRenderScaleThreshold = 0.05f;
private static readonly string kMSAADepthKeyword = "_MSAA_DEPTH";
private bool m_IsOffscreenCamera;
private Vector4 kDefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);

private CameraComparer m_CameraComparer = new CameraComparer();
private Material m_BlitMaterial;
private Material m_CopyDepthNoMSAAMaterial;
private Material m_CopyDepthMSAAMaterial;
private Material m_CopyDepthMaterial;
private Material m_ErrorMaterial;
private Material m_SamplingMaterial;

Shader.globalRenderPipeline = "LightweightPipeline";
m_BlitMaterial = CoreUtils.CreateEngineMaterial(m_Asset.BlitShader);
m_CopyDepthNoMSAAMaterial = CoreUtils.CreateEngineMaterial(m_Asset.CopyDepthShader);
m_CopyDepthMSAAMaterial = CoreUtils.CreateEngineMaterial(m_Asset.CopyDepthMSAAShader);
m_CopyDepthMaterial = CoreUtils.CreateEngineMaterial(m_Asset.CopyDepthShader);
m_SamplingMaterial = CoreUtils.CreateEngineMaterial(m_Asset.SamplingShader);
m_ErrorMaterial = CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader");
}

SupportedRenderingFeatures.active = new SupportedRenderingFeatures();
m_CopyDepthMaterial = null;
CoreUtils.Destroy(m_CopyDepthNoMSAAMaterial);
CoreUtils.Destroy(m_CopyDepthMSAAMaterial);
CoreUtils.Destroy(m_CopyDepthMaterial);
CoreUtils.Destroy(m_BlitMaterial);
CoreUtils.Destroy(m_SamplingMaterial);

if (LightweightUtils.HasFlag(config, FrameRenderingConfiguration.DepthCopy))
{
m_CopyDepthMSAAMaterial.SetFloat(m_SampleCount, (float)m_MSAASamples);
bool forceBlit = m_CopyDepthMaterial == m_CopyDepthMSAAMaterial;
bool forceBlit = false;
if (m_MSAASamples > 1)
{
m_CopyDepthMaterial.SetFloat(m_SampleCount, (float)m_MSAASamples);
m_CopyDepthMaterial.EnableKeyword(kMSAADepthKeyword);
forceBlit = true;
}
else
m_CopyDepthMaterial.DisableKeyword(kMSAADepthKeyword);
CopyTexture(cmd, m_DepthRT, m_CopyDepth, m_CopyDepthMaterial, forceBlit);
depthRT = m_CopyDepth;
setRenderTarget = true;

private void SetupFrameRenderingConfiguration(out FrameRenderingConfiguration configuration, bool screenspaceShadows, bool stereoEnabled, bool sceneViewCamera)
{
m_CopyDepthMaterial = null;
configuration = (stereoEnabled) ? FrameRenderingConfiguration.Stereo : FrameRenderingConfiguration.None;
if (stereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
m_IntermediateTextureArray = true;

if (m_RequireDepthTexture)
{
bool copyShaderSupported = (msaaEnabled && m_Asset.CopyDepthMSAAShader.isSupported) || (!msaaEnabled && m_Asset.CopyDepthShader.isSupported);
bool hasTex2DMS = SystemInfo.supportsMultisampledTextures != 0;
bool copyShaderSupported = m_Asset.CopyDepthShader.isSupported && (msaaEnabled == hasTex2DMS);
bool requiresDepthPrepassToResolveMSAA = msaaEnabled && (SystemInfo.supportsMultisampledTextures == 0);
bool requiresDepthPrepassToResolveMSAA = msaaEnabled && !hasTex2DMS;
bool requiresDepthPrepass = !supportsDepthCopy || screenspaceShadows || requiresDepthPrepassToResolveMSAA;
m_DepthRenderBuffer = !requiresDepthPrepass;

configuration |= FrameRenderingConfiguration.DepthPrePass;
else if (supportsDepthCopy && !canSkipDepthCopy)
{
m_CopyDepthMaterial = msaaEnabled ? m_CopyDepthMSAAMaterial : m_CopyDepthNoMSAAMaterial;
}
}
Rect cameraRect = m_CurrCamera.rect;

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


#define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv)
#endif
#ifdef MSAA_DEPTH
#ifdef _MSAA_DEPTH
DEPTH_TEXTURE_MS<float> _CameraDepthTexture;
float _SampleCount;
float4 _CameraDepthTexture_TexelSize;

float SampleDepth(float2 uv)
{
#ifdef MSAA_DEPTH
#ifdef _MSAA_DEPTH
int2 coord = int2(uv * _CameraDepthTexture_TexelSize.zw);
int samples = (int)_SampleCount;
#if UNITY_REVERSED_Z

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" = "LightiweightPipeline"}

#pragma exclude_renderers d3d11_9x
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _MSAA_DEPTH
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader.meta


fileFormatVersion: 2
guid: 3aaf3bbc87e49413fa5019b840757406
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

30
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader


Shader "Hidden/LightweightPipeline/CopyDepthMSAA"
{
Properties
{
[HideInInspector] _SampleCount("MSAA sample count", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"}
Pass
{
ZTest Always ZWrite On ColorMask 0
HLSLPROGRAM
#pragma exclude_renderers d3d11_9x
#pragma vertex vert
#pragma fragment frag
#pragma require msaatex
#define MSAA_DEPTH 1
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"
ENDHLSL
}
}
}
正在加载...
取消
保存