Skip to content

Move Screen Space Shadow to multicompile and remove config requirement for DXR #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion TestProjects/HDRP_DXR_Tests/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"com.unity.purchasing": "2.0.6",
"com.unity.render-pipelines.core": "file:../../../com.unity.render-pipelines.core",
"com.unity.render-pipelines.high-definition": "file:../../../com.unity.render-pipelines.high-definition",
"com.unity.render-pipelines.high-definition-config": "file:../LocalPackages/com.unity.render-pipelines.high-definition-config",
"com.unity.render-pipelines.high-definition-config": "file:../../../com.unity.render-pipelines.high-definition-config",
"com.unity.shadergraph": "file:../../../com.unity.shadergraph",
"com.unity.test-framework": "1.1.14",
"com.unity.test-framework.build": "0.0.1-preview.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public enum ShaderOptions
CameraRelativeRendering = 1, // Rendering sets the origin of the world to the position of the primary (scene view) camera
PreExposition = 1,
PrecomputedAtmosphericAttenuation = 0, // Precomputes atmospheric attenuation for the directional light on the CPU, which makes it independent from the fragment's position, which is faster but wrong
#if ENABLE_RAYTRACING
Raytracing = 1,
#else
Raytracing = 0,
#endif

#if ENABLE_VR
XrMaxViews = 2, // Used for single-pass rendering (with fast path in vertex shader code when forced to 2)
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)
#define SHADEROPTIONS_PRE_EXPOSITION (1)
#define SHADEROPTIONS_PRECOMPUTED_ATMOSPHERIC_ATTENUATION (0)
#define SHADEROPTIONS_RAYTRACING (0)
#define SHADEROPTIONS_XR_MAX_VIEWS (2)
#define SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE (0)
#define SHADEROPTIONS_PROBE_VOLUMES_ADDITIVE_BLENDING (1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ public CommonShaderPreprocessor() { }

protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData)
{
// Strip every useless shadow configs
var shadowInitParams = hdrpAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams;

foreach (var shadowVariant in m_ShadowKeywords.ShadowVariants)
{
if (shadowVariant.Key != shadowInitParams.shadowFilteringQuality)
if (inputData.shaderKeywordSet.IsEnabled(shadowVariant.Value))
return true;
}

// CAUTION: Pass Name and Lightmode name must match in master node and .shader.
// HDRP use LightMode to do drawRenderer and pass name is use here for stripping!

Expand Down Expand Up @@ -82,6 +72,26 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade
if (inputData.shaderKeywordSet.IsEnabled(m_SubsurfaceScattering) && !hdrpAsset.currentPlatformRenderPipelineSettings.supportSubsurfaceScattering)
return true;

// SHADOW

// Strip every useless shadow configs
var shadowInitParams = hdrpAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams;

foreach (var shadowVariant in m_ShadowKeywords.ShadowVariants)
{
if (shadowVariant.Key != shadowInitParams.shadowFilteringQuality)
if (inputData.shaderKeywordSet.IsEnabled(shadowVariant.Value))
return true;
}

// Screen space shadow variant is exclusive, either we have a variant with dynamic if that support screen space shadow or not
// either we have a variant that don't support at all. We can't have both at the same time.
if (inputData.shaderKeywordSet.IsEnabled(m_ScreenSpaceShadowOFFKeywords) && shadowInitParams.supportScreenSpaceShadows)
return true;

if (inputData.shaderKeywordSet.IsEnabled(m_ScreenSpaceShadowONKeywords) && !shadowInitParams.supportScreenSpaceShadows)
return true;

// DECAL

// Identify when we compile a decal shader
Expand Down Expand Up @@ -134,6 +144,7 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade
}
}

#if UNITY_2020_2_OR_NEWER
class HDRPPreprocessComputeShaders : IPreprocessComputeShaders
{
struct ExportComputeShaderStrip : System.IDisposable
Expand Down Expand Up @@ -195,6 +206,8 @@ public void Dispose()
protected ShadowKeywords m_ShadowKeywords = new ShadowKeywords();
protected ShaderKeyword m_EnableAlpha = new ShaderKeyword("ENABLE_ALPHA");
protected ShaderKeyword m_MSAA = new ShaderKeyword("ENABLE_MSAA");
protected ShaderKeyword m_ScreenSpaceShadowOFFKeywords = new ShaderKeyword("SCREEN_SPACE_SHADOWS_OFF");
protected ShaderKeyword m_ScreenSpaceShadowONKeywords = new ShaderKeyword("SCREEN_SPACE_SHADOWS_ON");

public int callbackOrder { get { return 0; } }

Expand Down Expand Up @@ -226,18 +239,24 @@ internal bool StripShader(HDRenderPipelineAsset hdAsset, ComputeShader shader, s
if (shadowVariant.Key != shadowInitParams.shadowFilteringQuality)
{
if (inputData.shaderKeywordSet.IsEnabled(shadowVariant.Value))
{
return true;
}
}
}

if(inputData.shaderKeywordSet.IsEnabled(m_MSAA) && !hdAsset.currentPlatformRenderPipelineSettings.supportMSAA)
// Screen space shadow variant is exclusive, either we have a variant with dynamic if that support screen space shadow or not
// either we have a variant that don't support at all. We can't have both at the same time.
if (inputData.shaderKeywordSet.IsEnabled(m_ScreenSpaceShadowOFFKeywords) && shadowInitParams.supportScreenSpaceShadows)
return true;

if (inputData.shaderKeywordSet.IsEnabled(m_ScreenSpaceShadowONKeywords) && !shadowInitParams.supportScreenSpaceShadows)
return true;

if (inputData.shaderKeywordSet.IsEnabled(m_MSAA) && !hdAsset.currentPlatformRenderPipelineSettings.supportMSAA)
{
return true;
}

if(inputData.shaderKeywordSet.IsEnabled(m_EnableAlpha) && !hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha)
if (inputData.shaderKeywordSet.IsEnabled(m_EnableAlpha) && !hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha)
{
return true;
}
Expand Down Expand Up @@ -308,6 +327,7 @@ public void OnProcessComputeShader(ComputeShader shader, string kernelName, ILis
}
}
}
#endif // #if UNITY_2020_2_OR_NEWER

class HDRPreprocessShaders : IPreprocessShaders
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ Entry[] entries
new Entry(InclusiveScope.DXR, Style.dxrReflections, IsDXRReflectionsCorrect, FixDXRReflections),
new Entry(InclusiveScope.DXR, Style.dxrActivated, IsDXRActivationCorrect, FixDXRActivation),
new Entry(InclusiveScope.DXR, Style.dxrResources, IsDXRAssetCorrect, FixDXRAsset),
new Entry(InclusiveScope.DXR, Style.dxrShaderConfig, IsDXRShaderConfigCorrect, FixDXRShaderConfig),
new Entry(InclusiveScope.DXR, Style.dxrScene, IsDXRDefaultSceneCorrect, FixDXRDefaultScene),
};
return m_Entries;
Expand Down Expand Up @@ -634,42 +633,6 @@ void FixDXRAsset(bool fromAsyncUnused)
= AssetDatabase.LoadAssetAtPath<HDRenderPipelineRayTracingResources>(HDUtils.GetHDRenderPipelinePath() + "Runtime/RenderPipelineResources/HDRenderPipelineRayTracingResources.asset");
ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources, HDUtils.GetHDRenderPipelinePath());
}

bool IsDXRShaderConfigCorrect()
{
if (!lastPackageConfigInstalledCheck)
return false;

bool found = false;
using (StreamReader streamReader = new StreamReader("LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl"))
{
while (!streamReader.EndOfStream && !found)
found = streamReader.ReadLine().Contains("#define SHADEROPTIONS_RAYTRACING (1)");
}
return found;
}
void FixDXRShaderConfig(bool fromAsyncUnused)
{
Debug.Log("Fixing DXRShaderConfig");
if (!lastPackageConfigInstalledCheck)
{
InstallLocalConfigurationPackage(() => FixDXRShaderConfig(false));
}
else
{
// Then we want to make sure that the shader config value is set to 1
string[] lines = System.IO.File.ReadAllLines("LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl");
for (int lineIdx = 0; lineIdx < lines.Length; ++lineIdx)
{
if (lines[lineIdx].Contains("SHADEROPTIONS_RAYTRACING"))
{
lines[lineIdx] = "#define SHADEROPTIONS_RAYTRACING (1)";
break;
}
}
File.WriteAllLines("LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl", lines);
}
}

bool IsDXRScreenSpaceShadowCorrect()
=> HDRenderPipeline.currentAsset != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ public ConfigStyle(string label, string error, string button = resolve, MessageT
public static readonly ConfigStyle dxrResources = new ConfigStyle(
label: "DXR resources",
error: "There is an issue with the DXR resources! Or your hardware and/or OS cannot be used for DXR! (unfixable in second case)");
public static readonly ConfigStyle dxrShaderConfig = new ConfigStyle(
label: "DXR shader config",
error: "There is an issue with the DXR shader config!");
public static readonly ConfigStyle dxrScene = new ConfigStyle(
label: "Default DXR scene prefab",
error: "Default DXR scene prefab must be set to create HD templated scene!");
Expand Down
Loading