Skip to content

Commit 15ab815

Browse files
Reducing the number of variants for ray tracing when building a player (#94)
* - Replaced the DIFFUSE_LIGHTING_ONLY multicompile by a uniform. - Removed the dynamic lightmap multicompile. - Remove the LOD cross fade multi compile for ray tracing. - Added a ray tracing mode option in the HDRP asset that allows to override and shader stripping. * fix merge * Update LayeredLit.shader * Update LayeredLit.shader Co-authored-by: sebastienlagarde <[email protected]>
1 parent bbdc81d commit 15ab815

File tree

18 files changed

+225
-140
lines changed

18 files changed

+225
-140
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
111111
- Added support for POM for emissive map
112112
- Added alpha channel support in motion blur pass.
113113
- Added the HDRP Compositor Tool (in Preview).
114+
- Added a ray tracing mode option in the HDRP asset that allows to override and shader stripping.
114115

115116
### Fixed
116117
- Fix when rescale probe all direction below zero (1219246)
@@ -658,6 +659,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
658659
- Updated shaders to be compatible with Microsoft's DXC.
659660
- Debug exposure in debug menu have been replace to debug exposure compensation in EV100 space and is always visible.
660661
- Further optimized PrepareLightsForGPU (3x faster with few shadows, 1.4x faster with a lot of shadows or equivalently cost reduced by 68% to 37%).
662+
- Raytracing: Replaced the DIFFUSE_LIGHTING_ONLY multicompile by a uniform.
663+
- Raytracing: Removed the dynamic lightmap multicompile.
664+
- Raytracing: Remove the LOD cross fade multi compile for ray tracing.
661665

662666
## [7.1.1] - 2019-09-05
663667

com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,39 @@ public override void OnInspectorGUI()
100100
PropertyField(m_LayerMask, EditorGUIUtility.TrTextContent("Layer Mask", "Layer mask used to include the objects for screen space reflection."));
101101
PropertyField(m_RayLength, EditorGUIUtility.TrTextContent("Ray Length", "Controls the length of reflection rays."));
102102
PropertyField(m_ClampValue, EditorGUIUtility.TrTextContent("Clamp Value", "Clamps the exposed intensity."));
103-
PropertyField(m_Mode, EditorGUIUtility.TrTextContent("Mode", "Controls which version of the effect should be used."));
104103

105-
EditorGUI.indentLevel++;
106-
switch (m_Mode.value.GetEnumValue<RayTracingMode>())
104+
if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Both)
107105
{
108-
case RayTracingMode.Performance:
109-
{
110-
PropertyField(m_UpscaleRadius, EditorGUIUtility.TrTextContent("Upscale Radius", "Controls the size of the upscale radius."));
111-
PropertyField(m_FullResolution, EditorGUIUtility.TrTextContent("Full Resolution", "Enables full resolution mode."));
112-
}
113-
break;
114-
case RayTracingMode.Quality:
106+
PropertyField(m_Mode, EditorGUIUtility.TrTextContent("Mode", "Controls which version of the effect should be used."));
107+
EditorGUI.indentLevel++;
108+
switch (m_Mode.value.GetEnumValue<RayTracingMode>())
115109
{
116-
PropertyField(m_SampleCount, EditorGUIUtility.TrTextContent("Sample Count", "Number of samples for reflections."));
117-
PropertyField(m_BounceCount, EditorGUIUtility.TrTextContent("Bounce Count", "Number of bounces for reflection rays."));
110+
case RayTracingMode.Performance:
111+
{
112+
PropertyField(m_UpscaleRadius, EditorGUIUtility.TrTextContent("Upscale Radius", "Controls the size of the upscale radius."));
113+
PropertyField(m_FullResolution, EditorGUIUtility.TrTextContent("Full Resolution", "Enables full resolution mode."));
114+
}
115+
break;
116+
case RayTracingMode.Quality:
117+
{
118+
PropertyField(m_SampleCount, EditorGUIUtility.TrTextContent("Sample Count", "Number of samples for reflections."));
119+
PropertyField(m_BounceCount, EditorGUIUtility.TrTextContent("Bounce Count", "Number of bounces for reflection rays."));
120+
}
121+
break;
118122
}
119-
break;
123+
EditorGUI.indentLevel--;
124+
}
125+
else if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Quality)
126+
{
127+
PropertyField(m_SampleCount, EditorGUIUtility.TrTextContent("Sample Count", "Number of samples for reflections."));
128+
PropertyField(m_BounceCount, EditorGUIUtility.TrTextContent("Bounce Count", "Number of bounces for reflection rays."));
129+
}
130+
else
131+
{
132+
PropertyField(m_UpscaleRadius, EditorGUIUtility.TrTextContent("Upscale Radius", "Controls the size of the upscale radius."));
133+
PropertyField(m_FullResolution, EditorGUIUtility.TrTextContent("Full Resolution", "Enables full resolution mode."));
120134
}
121-
EditorGUI.indentLevel--;
135+
122136
PropertyField(m_Denoise, EditorGUIUtility.TrTextContent("Denoise", "Enable denoising on the ray traced reflections."));
123137
{
124138
EditorGUI.indentLevel++;

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class GeneralSection
109109
public static readonly GUIContent supportTransparentDepthPrepass = EditorGUIUtility.TrTextContent("Transparent Depth Prepass", "When disabled, HDRP removes all transparent depth prepass Shader variants when you build for the Unity Player. This decreases build time.");
110110
public static readonly GUIContent supportTransparentDepthPostpass = EditorGUIUtility.TrTextContent("Transparent Depth Postpass", "When disabled, HDRP removes all transparent depth postpass Shader variants when you build for the Unity Player. This decreases build time.");
111111
public static readonly GUIContent supportRaytracing = EditorGUIUtility.TrTextContent("Realtime Raytracing (Preview)");
112+
public static readonly GUIContent supportedRayTracingMode = EditorGUIUtility.TrTextContent("Supported Ray Tracing Mode (Preview)");
112113
public static readonly GUIContent rayTracingUnsupportedWarning = EditorGUIUtility.TrTextContent("Ray tracing is not supported on your device. Please refer to the documentation.");
113114
public static readonly GUIContent maximumLODLevel = EditorGUIUtility.TrTextContent("Maximum LOD Level");
114115
public static readonly GUIContent LODBias = EditorGUIUtility.TrTextContent("LOD Bias");

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,13 @@ static void Drawer_SectionRenderingUnsorted(SerializedHDRenderPipelineAsset seri
845845
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportRayTracing, Styles.supportRaytracing);
846846
using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportRayTracing.boolValue))
847847
{
848+
++EditorGUI.indentLevel;
849+
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportedRayTracingMode, Styles.supportedRayTracingMode);
848850
if (serialized.renderPipelineSettings.supportRayTracing.boolValue && !UnityEngine.SystemInfo.supportsRayTracing)
849851
{
850852
EditorGUILayout.HelpBox(Styles.rayTracingUnsupportedWarning.text, MessageType.Warning, wide: true);
851853
}
854+
--EditorGUI.indentLevel;
852855
}
853856

854857
serialized.renderPipelineSettings.lodBias.ValueGUI<float>(Styles.LODBias);
@@ -1011,6 +1014,7 @@ static void SupportedSettingsInfoSection(SerializedHDRenderPipelineAsset seriali
10111014
AppendSupport(builder, serialized.renderPipelineSettings.supportTransparentDepthPostpass, Styles.supportTransparentDepthPostpass);
10121015
AppendSupport(builder, serialized.renderPipelineSettings.supportRayTracing, Styles.supportRaytracing);
10131016
AppendSupport(builder, serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent);
1017+
AppendSupport(builder, serialized.renderPipelineSettings.supportedRayTracingMode, Styles.supportedRayTracingMode);
10141018

10151019
EditorGUILayout.HelpBox(builder.ToString(), MessageType.Info, wide: true);
10161020
}

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/GlobalIlluminationEditor.cs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,38 @@ public override void OnInspectorGUI()
7676
PropertyField(m_LayerMask);
7777
PropertyField(m_RayLength);
7878
PropertyField(m_ClampValue);
79-
PropertyField(m_Mode);
8079

81-
EditorGUI.indentLevel++;
82-
switch (m_Mode.value.GetEnumValue<RayTracingMode>())
80+
if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Both)
8381
{
84-
case RayTracingMode.Performance:
85-
{
86-
PropertyField(m_FullResolution);
87-
PropertyField(m_UpscaleRadius);
88-
}
89-
break;
90-
case RayTracingMode.Quality:
91-
{
92-
PropertyField(m_SampleCount);
93-
PropertyField(m_BounceCount);
94-
}
95-
break;
82+
PropertyField(m_Mode);
83+
EditorGUI.indentLevel++;
84+
switch (m_Mode.value.GetEnumValue<RayTracingMode>())
85+
{
86+
case RayTracingMode.Performance:
87+
{
88+
PropertyField(m_FullResolution);
89+
PropertyField(m_UpscaleRadius);
90+
}
91+
break;
92+
case RayTracingMode.Quality:
93+
{
94+
PropertyField(m_SampleCount);
95+
PropertyField(m_BounceCount);
96+
}
97+
break;
98+
}
99+
EditorGUI.indentLevel--;
100+
}
101+
else if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Quality)
102+
{
103+
PropertyField(m_SampleCount);
104+
PropertyField(m_BounceCount);
105+
}
106+
else
107+
{
108+
PropertyField(m_FullResolution);
109+
PropertyField(m_UpscaleRadius);
96110
}
97-
EditorGUI.indentLevel--;
98111

99112
PropertyField(m_Denoise);
100113
{

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/RayTracingShaderPreprocessor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade
2121
|| snippet.passName == "SubSurfaceDXR")
2222
return true;
2323
}
24+
else
25+
{
26+
// If we only support Performance mode, we do not want the indirectDXR shader
27+
if (hdrpAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Performance
28+
&& snippet.passName == "IndirectDXR")
29+
return true;
30+
31+
// If we only support Quality mode, we do not want the indirectDXR shader
32+
if (hdrpAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Quality
33+
&& snippet.passName == "GBufferDXR")
34+
return true;
35+
}
2436

2537
return false;
2638
}

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SerializedRenderPipelineSettings
4949
public SerializedProperty supportDitheringCrossFade;
5050
public SerializedProperty supportTerrainHole;
5151
public SerializedProperty supportRayTracing;
52+
public SerializedProperty supportedRayTracingMode;
5253
public SerializedProperty supportDistortion;
5354
public SerializedProperty supportTransparentBackface;
5455
public SerializedProperty supportTransparentDepthPrepass;
@@ -115,6 +116,7 @@ public SerializedRenderPipelineSettings(SerializedProperty root)
115116
supportProbeVolume = root.Find((RenderPipelineSettings s) => s.supportProbeVolume);
116117

117118
supportRayTracing = root.Find((RenderPipelineSettings s) => s.supportRayTracing);
119+
supportedRayTracingMode = root.Find((RenderPipelineSettings s) => s.supportedRayTracingMode);
118120

119121
lightLoopSettings = new SerializedGlobalLightLoopSettings(root.Find((RenderPipelineSettings s) => s.lightLoopSettings));
120122
hdShadowInitParams = new SerializedHDShadowInitParameters(root.Find((RenderPipelineSettings s) => s.hdShadowInitParams));

com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using UnityEngine.Rendering;
@@ -541,6 +541,15 @@ static class CoreKeywords
541541
{ CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) },
542542
};
543543

544+
public static KeywordCollection HDBaseNoCrossFade = new KeywordCollection
545+
{
546+
{ CoreKeywordDescriptors.SurfaceTypeTransparent },
547+
{ CoreKeywordDescriptors.BlendMode },
548+
{ CoreKeywordDescriptors.DoubleSided, new FieldCondition(HDFields.SubShader.Unlit, false) },
549+
{ CoreKeywordDescriptors.FogOnTransparent },
550+
{ CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) },
551+
};
552+
544553
public static KeywordCollection Lightmaps = new KeywordCollection
545554
{
546555
{ CoreKeywordDescriptors.Lightmap },
@@ -578,14 +587,13 @@ static class CoreKeywords
578587

579588
public static KeywordCollection RaytracingIndirect = new KeywordCollection
580589
{
581-
{ HDBase },
582-
{ CoreKeywordDescriptors.DiffuseLightingOnly },
590+
{ HDBaseNoCrossFade },
583591
{ Lightmaps },
584592
};
585593

586594
public static KeywordCollection RaytracingGBufferForward = new KeywordCollection
587595
{
588-
{ HDBase },
596+
{ HDBaseNoCrossFade },
589597
{ Lightmaps },
590598
};
591599
}
@@ -871,15 +879,6 @@ static class CoreKeywordDescriptors
871879
scope = KeywordScope.Global,
872880
};
873881

874-
public static KeywordDescriptor DiffuseLightingOnly = new KeywordDescriptor()
875-
{
876-
displayName = "Diffuse Lighting Only",
877-
referenceName = "DIFFUSE_LIGHTING_ONLY",
878-
type = KeywordType.Boolean,
879-
definition = KeywordDefinition.MultiCompile,
880-
scope = KeywordScope.Global,
881-
};
882-
883882
public static KeywordDescriptor LightLayers = new KeywordDescriptor()
884883
{
885884
displayName = "Light Layers",

com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,6 @@ Shader "HDRP/LayeredLit"
460460
#pragma shader_feature_local _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
461461
#pragma shader_feature_local _MATERIAL_FEATURE_TRANSMISSION
462462

463-
// enable dithering LOD crossfade
464-
#pragma multi_compile _ LOD_FADE_CROSSFADE
465-
466463
//-------------------------------------------------------------------------------------
467464
// Define
468465
//-------------------------------------------------------------------------------------
@@ -534,6 +531,7 @@ Shader "HDRP/LayeredLit"
534531
//enable GPU instancing support
535532
#pragma multi_compile_instancing
536533
#pragma instancing_options renderinglayer
534+
#pragma multi_compile _ LOD_FADE_CROSSFADE
537535

538536
// Note: Require _ObjectId and _PassValue variables
539537

@@ -576,6 +574,7 @@ Shader "HDRP/LayeredLit"
576574
//enable GPU instancing support
577575
#pragma multi_compile_instancing
578576
#pragma instancing_options renderinglayer
577+
#pragma multi_compile _ LOD_FADE_CROSSFADE
579578

580579
#pragma multi_compile _ DEBUG_DISPLAY
581580
#pragma multi_compile _ LIGHTMAP_ON
@@ -623,6 +622,7 @@ Shader "HDRP/LayeredLit"
623622
//enable GPU instancing support
624623
#pragma multi_compile_instancing
625624
#pragma instancing_options renderinglayer
625+
#pragma multi_compile _ LOD_FADE_CROSSFADE
626626

627627
// Lightmap memo
628628
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
@@ -666,6 +666,7 @@ Shader "HDRP/LayeredLit"
666666
//enable GPU instancing support
667667
#pragma multi_compile_instancing
668668
#pragma instancing_options renderinglayer
669+
#pragma multi_compile _ LOD_FADE_CROSSFADE
669670

670671
#pragma multi_compile _ WRITE_NORMAL_BUFFER
671672
#pragma multi_compile _ WRITE_MSAA_DEPTH
@@ -706,6 +707,7 @@ Shader "HDRP/LayeredLit"
706707
//enable GPU instancing support
707708
#pragma multi_compile_instancing
708709
#pragma instancing_options renderinglayer
710+
#pragma multi_compile _ LOD_FADE_CROSSFADE
709711

710712
#define SHADERPASS SHADERPASS_SHADOWS
711713
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -745,6 +747,7 @@ Shader "HDRP/LayeredLit"
745747
//enable GPU instancing support
746748
#pragma multi_compile_instancing
747749
#pragma instancing_options renderinglayer
750+
#pragma multi_compile _ LOD_FADE_CROSSFADE
748751

749752
// In deferred, depth only pass don't output anything.
750753
// In forward it output the normal buffer
@@ -795,6 +798,7 @@ Shader "HDRP/LayeredLit"
795798
//enable GPU instancing support
796799
#pragma multi_compile_instancing
797800
#pragma instancing_options renderinglayer
801+
#pragma multi_compile _ LOD_FADE_CROSSFADE
798802

799803
#pragma multi_compile _ DEBUG_DISPLAY
800804
#pragma multi_compile _ LIGHTMAP_ON
@@ -889,12 +893,10 @@ Shader "HDRP/LayeredLit"
889893
#pragma multi_compile _ DEBUG_DISPLAY
890894
#pragma multi_compile _ LIGHTMAP_ON
891895
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
892-
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
893896

894897
#define SHADERPASS SHADERPASS_RAYTRACING_INDIRECT
895898

896899
// multi compile that allows us to
897-
#pragma multi_compile _ DIFFUSE_LIGHTING_ONLY
898900
#pragma multi_compile _ MULTI_BOUNCE_INDIRECT
899901

900902
// We use the low shadow maps for raytracing
@@ -934,7 +936,6 @@ Shader "HDRP/LayeredLit"
934936
#pragma multi_compile _ DEBUG_DISPLAY
935937
#pragma multi_compile _ LIGHTMAP_ON
936938
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
937-
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
938939

939940
#define SHADERPASS SHADERPASS_RAYTRACING_FORWARD
940941

@@ -975,8 +976,6 @@ Shader "HDRP/LayeredLit"
975976
#pragma multi_compile _ DEBUG_DISPLAY
976977
#pragma multi_compile _ LIGHTMAP_ON
977978
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
978-
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
979-
#pragma multi_compile _ DIFFUSE_LIGHTING_ONLY
980979

981980
#define SHADERPASS SHADERPASS_RAYTRACING_GBUFFER
982981

@@ -1038,8 +1037,6 @@ Shader "HDRP/LayeredLit"
10381037
#pragma multi_compile _ DEBUG_DISPLAY
10391038
#pragma multi_compile _ LIGHTMAP_ON
10401039
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
1041-
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
1042-
#pragma multi_compile _ DIFFUSE_LIGHTING_ONLY
10431040

10441041
#define SHADERPASS SHADERPASS_RAYTRACING_SUB_SURFACE
10451042

@@ -1072,7 +1069,6 @@ Shader "HDRP/LayeredLit"
10721069
#pragma multi_compile _ DEBUG_DISPLAY
10731070
#pragma multi_compile _ LIGHTMAP_ON
10741071
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
1075-
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
10761072

10771073
#define SHADERPASS SHADERPASS_PATH_TRACING
10781074
#define SKIP_RASTERIZED_SHADOWS

0 commit comments

Comments
 (0)