@@ -16,12 +16,21 @@ enum Expandable
1616 {
1717 Volume = 1 << 0 ,
1818 Probes = 1 << 1 ,
19- Baking = 1 << 2
19+ Baking = 1 << 2 ,
20+ DynamicBaking = 1 << 3
21+ }
22+
23+ enum DynamicGIBakingStage
24+ {
25+ Neighborhood ,
26+ MixedLights ,
27+ FallbackRadiance ,
2028 }
2129
2230 readonly static ExpandedState < Expandable , ProbeVolume > k_ExpandedStateVolume = new ExpandedState < Expandable , ProbeVolume > ( Expandable . Volume , "HDRP" ) ;
2331 readonly static ExpandedState < Expandable , ProbeVolume > k_ExpandedStateProbes = new ExpandedState < Expandable , ProbeVolume > ( Expandable . Probes , "HDRP" ) ;
2432 readonly static ExpandedState < Expandable , ProbeVolume > k_ExpandedStateBaking = new ExpandedState < Expandable , ProbeVolume > ( Expandable . Baking , "HDRP" ) ;
33+ readonly static ExpandedState < Expandable , ProbeVolume > k_ExpandedStateDynamicBaking = new ExpandedState < Expandable , ProbeVolume > ( Expandable . DynamicBaking , "HDRP" ) ;
2534
2635 internal static readonly CED . IDrawer Inspector = CED . Group (
2736 CED . Group (
@@ -55,6 +64,13 @@ enum Expandable
5564 Expandable . Baking ,
5665 k_ExpandedStateBaking ,
5766 Drawer_BakeToolBar
67+ ) ,
68+ CED . space ,
69+ CED . FoldoutGroup (
70+ Styles . k_DynamicBakingHeader ,
71+ Expandable . DynamicBaking ,
72+ k_ExpandedStateDynamicBaking ,
73+ Drawer_DynamicBakeToolBar
5874 )
5975 )
6076 )
@@ -101,38 +117,108 @@ static void Drawer_BakeToolBar(SerializedProbeVolume serialized, Editor owner)
101117 EditorGUILayout . Slider ( serialized . backfaceTolerance , 0.0f , 1.0f , Styles . s_BackfaceToleranceLabel ) ;
102118 EditorGUILayout . PropertyField ( serialized . dilationIterations , Styles . s_DilationIterationLabel ) ;
103119
104- GUILayout . BeginHorizontal ( ) ;
105- if ( GUILayout . Button ( Styles . k_BakeSelectedText ) )
120+ var bakeButtonRect = EditorGUI . IndentedRect ( EditorGUILayout . GetControlRect ( false ) ) ;
121+ if ( GUI . Button ( bakeButtonRect , Styles . k_BakeSelectedText ) )
106122 {
107123 ProbeVolumeManager . BakeSelected ( ) ;
108124 }
109- if ( GUILayout . Button ( Styles . k_BakeDynamicGIOnlyText ) )
125+ }
126+
127+ static void Drawer_DynamicBakeToolBar ( SerializedProbeVolume serialized , Editor owner )
128+ {
129+ DynamicGIBakingStage dynamicGIBakingStage ;
130+ if ( ProbeVolume . preparingMixedLights )
131+ dynamicGIBakingStage = DynamicGIBakingStage . MixedLights ;
132+ else if ( ProbeVolume . preparingForBake )
133+ dynamicGIBakingStage = DynamicGIBakingStage . FallbackRadiance ;
134+ else
135+ dynamicGIBakingStage = DynamicGIBakingStage . Neighborhood ;
136+
137+ EditorGUI . BeginChangeCheck ( ) ;
138+ dynamicGIBakingStage = ( DynamicGIBakingStage ) EditorGUILayout . EnumPopup ( Styles . k_DynamicBakingStageLabel , dynamicGIBakingStage ) ;
139+ if ( EditorGUI . EndChangeCheck ( ) )
140+ {
141+ ProbeVolume . preparingMixedLights = dynamicGIBakingStage == DynamicGIBakingStage . MixedLights ;
142+ ProbeVolume . preparingForBake = dynamicGIBakingStage == DynamicGIBakingStage . FallbackRadiance ;
143+ }
144+
145+ EditorGUILayout . Space ( ) ;
146+
147+ var targets = serialized . GetTargetObjects ( ) ;
148+
149+ if ( dynamicGIBakingStage == DynamicGIBakingStage . Neighborhood )
110150 {
111- var targets = serialized . GetTargetObjects ( ) ;
112- for ( int i = 0 ; i < targets . Length ; i ++ )
151+ var dynamicBakeButtonRect = EditorGUI . IndentedRect ( EditorGUILayout . GetControlRect ( false ) ) ;
152+ if ( GUI . Button ( dynamicBakeButtonRect , Styles . k_DynamicBakeNeighborhoodLabel ) )
113153 {
114- var probeVolume = ( ProbeVolume ) targets [ i ] ;
115- EditorUtility . DisplayProgressBar ( "Baking Dynamic GI" , $ "{ i + 1 } /{ targets . Length } { probeVolume . name } ", ( i + 0.5f ) / targets . Length ) ;
116- probeVolume . BakeDynamicGIOnly ( ) ;
154+ for ( int i = 0 ; i < targets . Length ; i ++ )
155+ {
156+ var probeVolume = ( ProbeVolume ) targets [ i ] ;
157+ EditorUtility . DisplayProgressBar ( "Baking Dynamic GI" , $ "{ i + 1 } /{ targets . Length } { probeVolume . name } ", ( i + 0.5f ) / targets . Length ) ;
158+ probeVolume . BakeDynamicGIOnly ( ) ;
159+ }
160+ EditorUtility . ClearProgressBar ( ) ;
117161 }
118- EditorUtility . ClearProgressBar ( ) ;
119162 }
120- GUILayout . EndHorizontal ( ) ;
121-
122- EditorGUILayout . Space ( ) ;
123-
124- ProbeVolume . preparingMixedLights = EditorGUILayout . Toggle ( Styles . k_PrepareMixedLightsText , ProbeVolume . preparingMixedLights ) ;
125- GUI . enabled = ProbeVolume . preparingMixedLights ;
163+ else
164+ {
165+ GUI . enabled = ! CheckAndWarnNoNeighborhoodBaked ( targets ) ;
166+
167+ var dynamicBakeButtonRect = EditorGUI . IndentedRect ( EditorGUILayout . GetControlRect ( false ) ) ;
168+ if ( dynamicGIBakingStage == DynamicGIBakingStage . MixedLights )
169+ {
170+ if ( GUI . Button ( dynamicBakeButtonRect , Styles . k_DynamicBakeMixedLightsLabel ) )
171+ {
172+ foreach ( var target in targets )
173+ {
174+ var probeVolume = ( ProbeVolume ) target ;
175+ probeVolume . CopyDirectLightingToMixed ( ) ;
176+ }
177+ }
178+ }
179+ else if ( dynamicGIBakingStage == DynamicGIBakingStage . FallbackRadiance )
180+ {
181+ if ( GUI . Button ( dynamicBakeButtonRect , Styles . k_DynamicBakeFallbackRadianceLabel ) )
182+ {
183+ foreach ( var target in targets )
184+ {
185+ var probeVolume = ( ProbeVolume ) target ;
186+ probeVolume . CopyDynamicSHToAsset ( ) ;
187+ }
188+ }
189+ }
126190
127- if ( GUILayout . Button ( Styles . k_BakeMixedLightsText ) )
191+ GUI . enabled = true ;
192+
193+ EditorGUILayout . Space ( ) ;
194+
195+ EditorGUILayout . HelpBox ( Styles . k_DynamicPipelineOverridesWarning , MessageType . Warning ) ;
196+ var resetButtonRect = EditorGUI . IndentedRect ( EditorGUILayout . GetControlRect ( false ) ) ;
197+ if ( GUI . Button ( resetButtonRect , Styles . k_DynamicResetPipelineOverridesLabel ) )
198+ {
199+ ProbeVolume . preparingMixedLights = false ;
200+ ProbeVolume . preparingForBake = false ;
201+ }
202+ }
203+ }
204+
205+ static bool CheckAndWarnNoNeighborhoodBaked ( Object [ ] targets )
206+ {
207+ var noNeighborhoodBaked = false ;
208+ foreach ( var target in targets )
128209 {
129- var targets = serialized . GetTargetObjects ( ) ;
130- for ( int i = 0 ; i < targets . Length ; i ++ )
210+ var probeVolume = ( ProbeVolume ) target ;
211+ if ( probeVolume . probeVolumeAsset == null )
131212 {
132- var probeVolume = ( ProbeVolume ) targets [ i ] ;
133- probeVolume . CopyDirectLightingToMixed ( ) ;
213+ noNeighborhoodBaked = true ;
214+ break ;
134215 }
135216 }
217+
218+ if ( noNeighborhoodBaked )
219+ EditorGUILayout . HelpBox ( Styles . k_DynamicNoNeighborhoodWarning , MessageType . Error ) ;
220+
221+ return noNeighborhoodBaked ;
136222 }
137223
138224 static void Drawer_ToolBar ( SerializedProbeVolume serialized , Editor owner )
0 commit comments