Skip to content
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

URP Forward+ #4500

Merged
merged 53 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ea272de
Create local test project
pbbastian Mar 22, 2021
6df1a49
Update mathematics version, and add burst
pbbastian Mar 22, 2021
7907881
Min max Z job
pbbastian Mar 24, 2021
f555ec6
Add constructor for min max Z job
pbbastian Mar 24, 2021
c50a2ec
Z-sort job prototype (untested)
pbbastian Mar 24, 2021
aa45dbd
Working radix sort using mean Z
pbbastian Mar 25, 2021
63f941a
Added re-ordering job and profiling marker
pbbastian Mar 25, 2021
fd50871
1-level tiling
pbbastian Apr 8, 2021
ec98618
TilingJob -> FineTilingJob
pbbastian Apr 8, 2021
2601fe6
Work on groups of 32 lights at a time
pbbastian Apr 9, 2021
f9a51d8
Minor optimizations
pbbastian Apr 9, 2021
a63f532
rename
pbbastian Apr 9, 2021
9d8aaa7
Move some data into one struct
pbbastian Apr 9, 2021
73eeee1
Hierarchical tiling
pbbastian Apr 13, 2021
4b849d6
Perf improvements for hierarchical tiling
pbbastian Apr 13, 2021
0327b30
Aperture Z-distribution
pbbastian Apr 13, 2021
0622504
Represent tile cone as SDF instead
pbbastian Apr 16, 2021
b9e6cc7
Separate tiling into X & Y + better debug view
pbbastian Apr 19, 2021
7eb1d35
Extract light data for slice culling
pbbastian Apr 19, 2021
0ac14c4
First pass of integration into URP lighting
pbbastian Apr 22, 2021
caa3c0a
Add clustering lighting UI option
pbbastian Apr 22, 2021
869871f
Overlap culling with setup
pbbastian Apr 23, 2021
d2fa370
Get rid of last Shader.SetGlobal
pbbastian Apr 23, 2021
00dd979
Clean up buffers in ForwardLights
pbbastian Apr 23, 2021
991bca9
Fix support for shadows
pbbastian Apr 27, 2021
40e470d
Support for directional lights
pbbastian Apr 28, 2021
f4c8de5
Remove unused code
pbbastian Apr 28, 2021
0d1af65
Use more general shader keyword, move setting to UniversalRenderer, e…
pbbastian Apr 28, 2021
ccdd86e
Handle ZBin factor better and reduce max Zbins to 4096
pbbastian Apr 29, 2021
f59ad71
Add clustered keyword to SM4.5 shaders
pbbastian Apr 29, 2021
bd01746
Make work on Android, fix shadows being stripped, strip clustered var…
pbbastian May 6, 2021
be4e371
Change back to UBOs
pbbastian May 7, 2021
dc699b8
Combine slices into tile structure
pbbastian May 7, 2021
449d2fe
Add clustered keyword to remaining shaders, and remove CPU part from …
pbbastian May 7, 2021
c2e7106
Merge branch 'master' into universal/forward-plus
pbbastian May 10, 2021
daebed7
Re-integrate Lighting.hlsl changes after merge with refactor in master
pbbastian May 10, 2021
7fcb671
Hide UI behind flag, do some minor clean up and fixing
pbbastian May 10, 2021
0741e45
Update UI text to reflect experimental
pbbastian May 10, 2021
2dfd7aa
Remove local test project
pbbastian May 10, 2021
072c8ea
Remove screenshots
pbbastian May 10, 2021
59adaa3
Revert a change
pbbastian May 10, 2021
3380c4f
Undo some unintentional changes and make new API points internal
pbbastian May 10, 2021
12d5433
Remove unused var
pbbastian May 10, 2021
1541413
Remove some more public API
pbbastian May 10, 2021
6af5e1e
Clarify some magic numbers
pbbastian May 11, 2021
b59c4da
Add keyword to Shader Graph targets
pbbastian May 11, 2021
1de6cab
Fix for crashes
pbbastian May 11, 2021
6a548ae
Fix assertion failure
pbbastian May 12, 2021
a529b5f
Merge branch 'master' into universal/forward-plus
pbbastian May 12, 2021
fdfc756
fix for merge
pbbastian May 12, 2021
32ad2e7
Workaround memory allocation assert bug
pbbastian May 12, 2021
e115daf
Fix GPU crash
pbbastian May 12, 2021
3a1bd42
Remove workaround for preview cameras
pbbastian May 12, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ static class Descriptors
{ CoreKeywordDescriptors.ShadowsSoft },
{ CoreKeywordDescriptors.LightmapShadowMixing },
{ CoreKeywordDescriptors.ShadowsShadowmask },
{ CoreKeywordDescriptors.ClusteredRendering },
{ Descriptors.DecalsNormalBlend },
{ Descriptors.LodCrossFade, new FieldCondition(Fields.LodCrossFade, true) },
};
Expand All @@ -961,6 +962,7 @@ static class Descriptors
{ CoreKeywordDescriptors.AdditionalLights },
{ CoreKeywordDescriptors.AdditionalLightShadows },
{ CoreKeywordDescriptors.ShadowsSoft },
{ CoreKeywordDescriptors.ClusteredRendering },
{ Descriptors.DecalsNormalBlend },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ static class LitKeywords
{ CoreKeywordDescriptors.DBuffer },
{ CoreKeywordDescriptors.LightLayers },
{ CoreKeywordDescriptors.DebugDisplay },
{ CoreKeywordDescriptors.ClusteredRendering },
};

public static readonly KeywordCollection GBuffer = new KeywordCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,15 @@ static class CoreKeywordDescriptors
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
};

public static readonly KeywordDescriptor ClusteredRendering = new KeywordDescriptor()
{
displayName = "Clustered Rendering",
referenceName = "_CLUSTERED_RENDERING",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
};
}
#endregion

Expand Down
50 changes: 41 additions & 9 deletions com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum ShaderFeatures
DecalNormalBlendLow = (1 << 22),
DecalNormalBlendMedium = (1 << 23),
DecalNormalBlendHigh = (1 << 24),
ClusteredRendering = (1 << 25)
}

internal class ShaderPreprocessor : IPreprocessShaders
Expand Down Expand Up @@ -82,13 +83,13 @@ internal class ShaderPreprocessor : IPreprocessShaders
ShaderKeyword m_UseFastSRGBLinearConversion = new ShaderKeyword(ShaderKeywordStrings.UseFastSRGBLinearConversion);
ShaderKeyword m_LightLayers = new ShaderKeyword(ShaderKeywordStrings.LightLayers);
ShaderKeyword m_DebugDisplay = new ShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);

ShaderKeyword m_DBufferMRT1 = new ShaderKeyword(ShaderKeywordStrings.DBufferMRT1);
ShaderKeyword m_DBufferMRT2 = new ShaderKeyword(ShaderKeywordStrings.DBufferMRT2);
ShaderKeyword m_DBufferMRT3 = new ShaderKeyword(ShaderKeywordStrings.DBufferMRT3);
ShaderKeyword m_DecalNormalBlendLow = new ShaderKeyword(ShaderKeywordStrings.DecalNormalBlendLow);
ShaderKeyword m_DecalNormalBlendMedium = new ShaderKeyword(ShaderKeywordStrings.DecalNormalBlendMedium);
ShaderKeyword m_DecalNormalBlendHigh = new ShaderKeyword(ShaderKeywordStrings.DecalNormalBlendHigh);
ShaderKeyword m_ClusteredRendering = new ShaderKeyword(ShaderKeywordStrings.ClusteredRendering);

ShaderKeyword m_LocalDetailMulx2;
ShaderKeyword m_LocalDetailScaled;
Expand Down Expand Up @@ -122,7 +123,7 @@ bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
{
if (SupportedRenderingFeatures.active.enlighten == false ||
((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0)
return true;
return true;
}

if (snippetData.passType == PassType.ShadowCaster)
Expand Down Expand Up @@ -228,20 +229,23 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa
// Additional light are shaded per-vertex or per-pixel.
bool isFeaturePerPixelLightingEnabled = IsFeatureEnabled(features, ShaderFeatures.AdditionalLights);
bool isFeaturePerVertexLightingEnabled = IsFeatureEnabled(features, ShaderFeatures.VertexLighting);
bool clusteredRendering = IsFeatureEnabled(features, ShaderFeatures.ClusteredRendering);
bool isAdditionalLightPerPixel = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel);
bool isAdditionalLightPerVertex = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsVertex);

// Strip if Per-Pixel lighting is NOT used in the project and the
// Per-Pixel (_ADDITIONAL_LIGHTS) or additional shadows (_ADDITIONAL_LIGHT_SHADOWS)
// variants are enabled in the shader.
if (!isFeaturePerPixelLightingEnabled && (isAdditionalLightPerPixel || isAdditionalLightShadow))
// Per-Pixel (_ADDITIONAL_LIGHTS) variant is enabled in the shader.
if (!isFeaturePerPixelLightingEnabled && isAdditionalLightPerPixel)
return true;

// Strip if Per-Vertex lighting is NOT used in the project and the
// Per-Vertex (_ADDITIONAL_LIGHTS_VERTEX) variant is enabled in the shader.
if (!isFeaturePerVertexLightingEnabled && isAdditionalLightPerVertex)
return true;

if (!clusteredRendering && compilerData.shaderKeywordSet.IsEnabled(m_ClusteredRendering))
return true;

// Screen Space Shadows
if (!IsFeatureEnabled(features, ShaderFeatures.ScreenSpaceShadows) &&
compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadowsScreen))
Expand Down Expand Up @@ -320,7 +324,7 @@ bool StripInvalidVariants(ShaderCompilerData compilerData)
bool isMainShadow = isMainShadowNoCascades || isMainShadowCascades || isMainShadowScreen;

bool isAdditionalShadow = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);
if (isAdditionalShadow && !compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel))
if (isAdditionalShadow && !(compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel) || compilerData.shaderKeywordSet.IsEnabled(m_ClusteredRendering)))
return true;

bool isDeferredShadow = compilerData.shaderKeywordSet.IsEnabled(m_DeferredLightShadows);
Expand Down Expand Up @@ -390,6 +394,7 @@ public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList<
#if PROFILE_BUILD
Profiler.BeginSample(k_ProcessShaderTag);
#endif

UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
if (urpAsset == null || compilerDataList == null || compilerDataList.Count == 0)
return;
Expand Down Expand Up @@ -506,9 +511,6 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
{
shaderFeatures |= ShaderFeatures.AdditionalLights;

if (pipelineAsset.supportsAdditionalLightShadows)
shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
}

bool anyShadows = pipelineAsset.supportsMainLightShadows ||
Expand All @@ -533,6 +535,8 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
bool hasDeferredRenderer = false;
bool withAccurateGbufferNormals = false;
bool withoutAccurateGbufferNormals = false;
bool clusteredRendering = false;
bool onlyClusteredRendering = false;

int rendererCount = pipelineAsset.m_RendererDataList.Length;
for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
Expand All @@ -549,6 +553,7 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
}
}

var rendererClustered = false;

ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
if (rendererData != null)
Expand Down Expand Up @@ -585,7 +590,16 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
}
}
}

if (rendererData is UniversalRendererData universalRendererData)
{
rendererClustered = universalRendererData.renderingMode == RenderingMode.Forward &&
universalRendererData.clusteredRendering;
}
}

clusteredRendering |= rendererClustered;
onlyClusteredRendering &= rendererClustered;
}

if (hasDeferredRenderer)
Expand All @@ -610,6 +624,24 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline
if (pipelineAsset.reflectionProbeBoxProjection)
shaderFeatures |= ShaderFeatures.ReflectionProbeBoxProjection;

if (clusteredRendering)
{
shaderFeatures |= ShaderFeatures.ClusteredRendering;
}

if (onlyClusteredRendering)
{
shaderFeatures &= ~(ShaderFeatures.AdditionalLights | ShaderFeatures.VertexLighting);
}

if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel || clusteredRendering)
{
if (pipelineAsset.supportsAdditionalLightShadows)
{
shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
}
}

return shaderFeatures;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static class Styles
public static readonly GUIContent defaultStencilStateLabel = EditorGUIUtility.TrTextContent("Default Stencil State", "Configure the stencil state for the opaque and transparent render passes.");
public static readonly GUIContent shadowTransparentReceiveLabel = EditorGUIUtility.TrTextContent("Transparent Receive Shadows", "When disabled, none of the transparent objects will receive shadows.");
public static readonly GUIContent invalidStencilOverride = EditorGUIUtility.TrTextContent("Error: When using the deferred rendering path, the Renderer requires the control over the 4 highest bits of the stencil buffer to store Material types. The current combination of the stencil override options prevents the Renderer from controlling the required bits. Try changing one of the options to Replace.");
public static readonly GUIContent clusteredRenderingLabel = EditorGUIUtility.TrTextContent("Clustered (experimental)", "(Experimental) Enables clustered rendering, allowing for more lights per object and more accurate light cullling.");
}

SerializedProperty m_OpaqueLayerMask;
Expand All @@ -33,6 +34,8 @@ private static class Styles
SerializedProperty m_DepthPrimingMode;
SerializedProperty m_AccurateGbufferNormals;
//SerializedProperty m_TiledDeferredShading;
SerializedProperty m_ClusteredRendering;
SerializedProperty m_TileSize;
#if ENABLE_RENDER_PASS_UI
SerializedProperty m_UseNativeRenderPass;
#endif
Expand All @@ -41,6 +44,12 @@ private static class Styles
SerializedProperty m_Shaders;
SerializedProperty m_ShadowTransparentReceiveProp;

#if URP_ENABLE_CLUSTERED_UI
static bool s_EnableClusteredUI => true;
#else
static bool s_EnableClusteredUI => false;
#endif

private void OnEnable()
{
m_OpaqueLayerMask = serializedObject.FindProperty("m_OpaqueLayerMask");
Expand All @@ -50,6 +59,8 @@ private void OnEnable()
m_AccurateGbufferNormals = serializedObject.FindProperty("m_AccurateGbufferNormals");
// Not exposed yet.
//m_TiledDeferredShading = serializedObject.FindProperty("m_TiledDeferredShading");
m_ClusteredRendering = serializedObject.FindProperty("m_ClusteredRendering");
m_TileSize = serializedObject.FindProperty("m_TileSize");
#if ENABLE_RENDER_PASS_UI
m_UseNativeRenderPass = serializedObject.FindProperty("m_UseNativeRenderPass");
#endif
Expand Down Expand Up @@ -86,11 +97,21 @@ public override void OnInspectorGUI()
if (m_RenderingMode.intValue == (int)RenderingMode.Forward)
{
EditorGUI.indentLevel++;

if (s_EnableClusteredUI)
{
EditorGUILayout.PropertyField(m_ClusteredRendering, Styles.clusteredRenderingLabel);
EditorGUI.BeginDisabledGroup(!m_ClusteredRendering.boolValue);
EditorGUILayout.PropertyField(m_TileSize);
EditorGUI.EndDisabledGroup();
}

EditorGUILayout.PropertyField(m_DepthPrimingMode, Styles.DepthPrimingModeLabel);
if (m_DepthPrimingMode.intValue != (int)DepthPrimingMode.Disabled)
{
EditorGUILayout.HelpBox(Styles.DepthPrimingModeInfo.text, MessageType.Info);
}

EditorGUI.indentLevel--;
}

Expand Down
Loading