-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLightmapping.bindings.cs
More file actions
825 lines (660 loc) · 34.4 KB
/
Lightmapping.bindings.cs
File metadata and controls
825 lines (660 loc) · 34.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
using System.Runtime.InteropServices;
using Scene = UnityEngine.SceneManagement.Scene;
using NativeArrayUnsafeUtility = Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility;
using Unity.Collections;
using UnityEditor.LightBaking;
using UnityEngine.Rendering;
namespace UnityEditor
{
[UsedByNativeCode]
[NativeHeader("Editor/Src/GI/Progressive/PVRData.h")]
internal struct LightmapConvergence
{
[NativeName("IsConverged")]
public extern bool IsConverged();
public bool IsValid() { return -1 != visibleConvergedDirectTexelCount; }
[NativeName("GetTileCount")]
internal extern int GetTileCount();
[NativeName("m_CullingHash")] public Hash128 cullingHash;
[NativeName("m_VisibleConvergedDirectTexelCount")] public int visibleConvergedDirectTexelCount;
[NativeName("m_VisibleConvergedGITexelCount")] public int visibleConvergedGITexelCount;
[NativeName("m_VisibleConvergedEnvTexelCount")] public int visibleConvergedEnvTexelCount;
[NativeName("m_VisibleTexelCount")] public int visibleTexelCount;
[NativeName("m_ConvergedDirectTexelCount")] public int convergedDirectTexelCount;
[NativeName("m_ConvergedGITexelCount")] public int convergedGITexelCount;
[NativeName("m_ConvergedEnvTexelCount")] public int convergedEnvTexelCount;
[NativeName("m_OccupiedTexelCount")] public int occupiedTexelCount;
[NativeName("m_OccupiedTexelCountInCurrentTile")] public int occupiedTexelCountInCurrentTile;
[NativeName("m_MinDirectSamples")] public int minDirectSamples;
[NativeName("m_MinGISamples")] public int minGISamples;
[NativeName("m_MinEnvSamples")] public int minEnvSamples;
[NativeName("m_MaxDirectSamples")] public int maxDirectSamples;
[NativeName("m_MaxGISamples")] public int maxGISamples;
[NativeName("m_MaxEnvSamples")] public int maxEnvSamples;
[NativeName("m_AvgDirectSamples")] public int avgDirectSamples;
[NativeName("m_AvgGISamples")] public int avgGISamples;
[NativeName("m_AvgEnvSamples")] public int avgEnvSamples;
[NativeName("m_ForceStop")] public bool avgGIForceStop;
[NativeName("m_Progress")] public float progress;
[NativeName("m_TilingMode")] public int tilingMode;
[NativeName("m_TilingPassNum")] public int tilingPassNum;
}
[UsedByNativeCode]
[NativeHeader("Editor/Src/GI/Progressive/PVRData.h")]
internal struct LightProbesConvergence
{
public bool IsConverged() { return probeSetCount == convergedProbeSetCount; }
public bool IsValid() { return -1 != probeSetCount; }
[NativeName("m_ProbeSetCount")] public int probeSetCount;
[NativeName("m_ConvergedProbeSetCount")] public int convergedProbeSetCount;
}
[UsedByNativeCode]
[NativeHeader("Editor/Src/GI/Progressive/PVRData.h")]
internal struct LightmapSize
{
[NativeName("m_Width")] public int width;
[NativeName("m_Height")] public int height;
}
[UsedByNativeCode]
[NativeHeader("Editor/Src/GI/Progressive/PVRData.h")]
internal struct RunningBakeInfo
{
[NativeName("m_LightmapSizes")] public LightmapSize[] lightmapSizes;
[NativeName("m_ProbePositions")] public UInt64 probePositions;
}
[UsedByNativeCode]
[NativeHeader("Editor/Src/GI/Progressive/PVRData.h")]
internal struct LightmapMemory
{
[NativeName("m_LightmapDataSizeCPU")] public float lightmapDataSizeCPU;
[NativeName("m_LightmapTexturesSize")] public float lightmapTexturesSize;
[NativeName("m_LightmapDataSizeGPU")] public float lightmapDataSizeGPU;
}
internal struct MemLabels
{
public string[] labels;
public float[] sizes;
}
internal struct GeoMemLabels
{
public string[] labels;
public float[] sizes;
public UInt64[] triCounts;
}
internal struct TetrahedralizationData
{
public int[] indices;
public Vector3[] positions;
}
[NativeHeader("Editor/Src/GI/Progressive/BakeContextManager.h")]
internal struct EnvironmentSamplesData
{
public Vector4[] directions;
public Vector4[] intensities;
}
[NativeHeader("Editor/Src/GI/Progressive/PVRHelpers.h")]
internal struct DeviceAndPlatform
{
public int deviceId;
public int platformId;
public string name;
};
[NativeHeader("Editor/Mono/GI/Lightmapping.bindings.h")]
public static partial class Lightmapping
{
[NativeHeader("Editor/Src/JobManager/QueueJobTypes.h")]
internal enum ConcurrentJobsType
{
Min = 0,
Low = 1,
High = 2,
}
[NativeHeader("Runtime/Graphics/LightmapEnums.h")]
public enum GIWorkflowMode
{
// Data is automatically precomputed for dynamic and static GI.
Iterative = 0,
// Data is only precomputed for dynamic and static GI when the bake button is pressed.
OnDemand = 1,
// Lightmaps are calculated in the same way as in Unity 4.x.
Legacy = 2
}
// Obsolete, please use Actions instead
public delegate void OnStartedFunction();
public delegate void OnCompletedFunction();
// [Obsolete("Lightmapping.giWorkflowMode is obsolete, use LightingSettings.autoGenerate instead. ", false)]
public static GIWorkflowMode giWorkflowMode
{
get { return GetLightingSettingsOrDefaultsFallback().autoGenerate ? GIWorkflowMode.Iterative : GIWorkflowMode.OnDemand; }
set { GetOrCreateLightingsSettings().autoGenerate = (value == GIWorkflowMode.Iterative); }
}
// [Obsolete("Lightmapping.realtimeGI is obsolete, use LightingSettings.realtimeGI instead. ", false)]
public static bool realtimeGI
{
get { return GetLightingSettingsOrDefaultsFallback().realtimeGI; }
set { GetOrCreateLightingsSettings().realtimeGI = value; }
}
// [Obsolete("Lightmapping.bakedGI is obsolete, use LightingSettings.bakedGI instead. ", false)]
public static bool bakedGI
{
get { return GetLightingSettingsOrDefaultsFallback().bakedGI; }
set { GetOrCreateLightingsSettings().bakedGI = value; }
}
[Obsolete("Lightmapping.indirectOutputScale is obsolete, use LightingSettings.indirectScale instead. ", false)]
public static float indirectOutputScale
{
get { return GetLightingSettingsOrDefaultsFallback().indirectScale; }
set { GetOrCreateLightingsSettings().indirectScale = value; }
}
[Obsolete("Lightmapping.bounceBoost is obsolete, use LightingSettings.albedoBoost instead. ", false)]
public static float bounceBoost
{
get { return GetLightingSettingsOrDefaultsFallback().albedoBoost; }
set { GetOrCreateLightingsSettings().albedoBoost = value; }
}
// Set concurrent jobs type. Warning, high priority can impact Editor performance
[StaticAccessor("EnlightenPrecompManager::Get()", StaticAccessorType.Arrow)]
internal static extern ConcurrentJobsType concurrentJobsType { get; set; }
// Clears disk cache and recreates cache directories.
[StaticAccessor("GICache", StaticAccessorType.DoubleColon)]
public static extern void ClearDiskCache();
// Updates cache path from Editor preferences.
[StaticAccessor("GICache", StaticAccessorType.DoubleColon)]
internal static extern void UpdateCachePath();
// Get the disk cache size in Mb.
[StaticAccessor("GICache", StaticAccessorType.DoubleColon)]
[NativeName("LastKnownCacheSize")]
internal static extern long diskCacheSize { get; }
// Get the disk cache path.
[StaticAccessor("GICache", StaticAccessorType.DoubleColon)]
[NativeName("CachePath")]
internal static extern string diskCachePath { get; }
[Obsolete("Lightmapping.enlightenForceWhiteAlbedo is obsolete, use LightingSettings.realtimeForceWhiteAlbedo instead. ", false)]
internal static bool enlightenForceWhiteAlbedo
{
get { return GetLightingSettingsOrDefaultsFallback().realtimeForceWhiteAlbedo; }
set { GetOrCreateLightingsSettings().realtimeForceWhiteAlbedo = value; }
}
[Obsolete("Lightmapping.enlightenForceUpdates is obsolete, use LightingSettings.realtimeForceUpdates instead. ", false)]
internal static bool enlightenForceUpdates
{
get { return GetLightingSettingsOrDefaultsFallback().realtimeForceUpdates; }
set { GetOrCreateLightingsSettings().realtimeForceUpdates = value; }
}
[Obsolete("Lightmapping.filterMode is obsolete, use LightingSettings.lightmapFilterMode instead. ", false)]
internal static FilterMode filterMode
{
get { return GetLightingSettingsOrDefaultsFallback().lightmapFilterMode; }
set { GetOrCreateLightingsSettings().lightmapFilterMode = value; }
}
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern bool isProgressiveLightmapperDone {[NativeName("IsBakedGIDone")] get; }
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern ulong occupiedTexelCount { get; }
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern ulong GetVisibleTexelCount(int lightmapIndex);
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern int atlasCount { [NativeName("GetAtlasCount")] get; }
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern LightmapConvergence GetLightmapConvergence(int lightmapIndex);
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern RunningBakeInfo GetRunningBakeInfo();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern LightProbesConvergence GetLightProbesConvergence();
[FreeFunction]
internal static extern MemLabels GetLightProbeMemLabels();
[FreeFunction]
internal static extern MemLabels GetTransmissionTexturesMemLabels();
[FreeFunction]
internal static extern MemLabels GetMaterialTexturesMemLabels();
[StaticAccessor("PVRMemoryLabelTracker::Get()", StaticAccessorType.Arrow)]
internal static extern void ResetExplicitlyShownMemLabels();
[StaticAccessor("PVROpenRLMemoryTracker::Get()", StaticAccessorType.Arrow)]
[NativeName("GetGeometryMemory")]
internal static extern GeoMemLabels GetGeometryMemory();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern float ComputeTotalCPUMemoryUsageInBytes();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern float ComputeTotalGPUMemoryUsageInBytes();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern void LogGPUMemoryStatistics();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern float GetLightmapBakeTimeTotal();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
[NativeName("GetLightmapBakePerformance")]
internal static extern float GetLightmapBakePerformanceTotal();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern string GetLightmapBakeGPUDeviceName();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern int GetLightmapBakeGPUDeviceIndex();
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
internal static extern DeviceAndPlatform[] GetLightmappingGpuDevices();
// Exports the current state of the scene to the dynamic GI workflow.
[FreeFunction]
internal static extern void PrintStateToConsole();
// Starts an asynchronous bake job.
[FreeFunction]
public static extern bool BakeAsync();
// Stars a synchronous bake job.
[FreeFunction]
public static extern bool Bake();
// Cancels the currently running asynchronous bake job.
[FreeFunction("CancelLightmapping")]
public static extern void Cancel();
// Stops the current bake at the state it has reached so far.
[FreeFunction]
[System.Obsolete("ForceStop is no longer available, use Cancel instead to stop a bake.", false)]
public static extern void ForceStop();
// Returns true when the bake job is running, false otherwise (RO).
public static extern bool isRunning {[FreeFunction("IsRunningLightmapping")] get; }
[System.Obsolete("OnStartedFunction.started is obsolete, please use bakeStarted instead. ", false)]
public static event OnStartedFunction started;
public static event Action bakeStarted;
private static void OpenNestedSubScenes()
{
if (SceneHierarchyHooks.provideSubScenes == null)
return;
var subSceneInfos = SceneHierarchyHooks.provideSubScenes();
if (subSceneInfos != null)
{
// Open all nested sub scenes.
int subSceneCount = subSceneInfos.Length;
foreach (var subSceneInfo in subSceneInfos)
{
if (subSceneInfo.scene.isLoaded)
continue;
var path = AssetDatabase.GetAssetPath(subSceneInfo.sceneAsset);
var scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
scene.isSubScene = true;
}
// Keep going deeper until sub scene count has stabilized.
subSceneInfos = SceneHierarchyHooks.provideSubScenes();
if (subSceneCount != subSceneInfos.Length)
OpenNestedSubScenes();
}
}
private static void Internal_CallBakeStartedFunctions()
{
if (bakeStarted != null)
bakeStarted();
// Open all sub scenes before the bake so they can participate in the GI calculations.
OpenNestedSubScenes();
#pragma warning disable 0618
if (started != null)
started();
#pragma warning restore 0618
}
internal static event Action startedRendering;
internal static void Internal_CallStartedRenderingFunctions()
{
if (startedRendering != null)
startedRendering();
}
public static event Action lightingDataUpdated;
internal static void Internal_CallLightingDataUpdatedFunctions()
{
if (lightingDataUpdated != null)
lightingDataUpdated();
}
public static event Action lightingDataCleared;
internal static void Internal_CallLightingDataCleared()
{
if (lightingDataCleared != null)
lightingDataCleared();
}
public static event Action lightingDataAssetCleared;
internal static void Internal_CallLightingDataAssetCleared()
{
if (lightingDataAssetCleared != null)
lightingDataAssetCleared();
}
internal static event Action wroteLightingDataAsset;
internal static void Internal_CallOnWroteLightingDataAsset()
{
if (wroteLightingDataAsset != null)
wroteLightingDataAsset();
}
// This event is fired when BakeInput has been populated, but before passing it to Bake().
// Do not store and access BakeInput beyond the call-back.
internal static event Action<LightBaker.BakeInput, InputExtraction.SourceMap> createdBakeInput;
internal static void Internal_CallOnCreatedBakeInput(IntPtr p_BakeInput, IntPtr p_SourceMap)
{
if (createdBakeInput != null)
{
using var bakeInput = new LightBaker.BakeInput(p_BakeInput);
using var sourceMap = new InputExtraction.SourceMap(p_SourceMap);
createdBakeInput(bakeInput, sourceMap);
}
}
[System.Obsolete("OnCompletedFunction.completed is obsolete, please use event bakeCompleted instead. ", false)]
public static OnCompletedFunction completed;
public static event Action bakeCompleted;
private static void Internal_CallBakeCompletedFunctions()
{
if (bakeCompleted != null)
bakeCompleted();
#pragma warning disable 0618
if (completed != null)
completed();
#pragma warning restore 0618
}
internal static event Action<string> bakeAnalytics;
private static void Internal_CallBakeAnalyticsFunctions(string analytics)
{
if (bakeAnalytics != null)
bakeAnalytics(analytics);
}
// Returns the progress of a build when the bake job is running, returns 0 when no bake job is running.
public static extern float buildProgress {[FreeFunction] get; }
// Deletes all runtime lighting data for the current scene.
[FreeFunction]
public static extern void Clear();
// Deletes the lighting data asset for the current scene.
[FreeFunction]
public static extern void ClearLightingDataAsset();
// Calculates a Delaunay Tetrahedralization of the 'positions' point set - the same way the lightmapper
public static void Tetrahedralize(Vector3[] positions, out int[] outIndices, out Vector3[] outPositions)
{
TetrahedralizationData data = TetrahedralizeInternal(positions);
outIndices = data.indices;
outPositions = data.positions;
}
[NativeName("LightProbeUtils::Tetrahedralize")]
[FreeFunction]
private static extern TetrahedralizationData TetrahedralizeInternal(Vector3[] positions);
[FreeFunction]
public static extern bool BakeReflectionProbe(ReflectionProbe probe, string path);
// Used to quickly update baked reflection probes without GI computations.
[FreeFunction]
internal static extern bool BakeReflectionProbeSnapshot(ReflectionProbe probe);
// Used to quickly update all baked reflection probes without GI computations.
[FreeFunction]
internal static extern bool BakeAllReflectionProbesSnapshots();
// Called when the user changes the Lightmap Encoding option:
// - reload shaders to set correct lightmap decoding keyword
// - reimport lightmaps with the new encoding
// - rebake reflection probes because the lightmaps may look different
[FreeFunction]
internal static extern void OnUpdateLightmapEncoding(BuildTargetGroup target);
// Called when the user changes the HDR Cubemap Encoding option,
// will reimport HDR cubemaps with the new encoding.
[FreeFunction]
internal static extern void OnUpdateHDRCubemapEncoding(BuildTargetGroup target);
// Called when the user changes the Lightmap streaming settings:
[FreeFunction]
internal static extern void OnUpdateLightmapStreaming(BuildTargetGroup target);
[FreeFunction]
public static extern void GetTerrainGIChunks([NotNull] Terrain terrain, ref int numChunksX, ref int numChunksY);
[StaticAccessor("GetLightmapSettings()")]
public static extern LightingDataAsset lightingDataAsset { get; set; }
public static bool TryGetLightingSettings(out LightingSettings settings)
{
settings = lightingSettingsInternal;
return (settings != null);
}
public static LightingSettings lightingSettings
{
get
{
var settings = lightingSettingsInternal;
if (settings == null)
{
throw new Exception("Lightmapping.lightingSettings is null. Please assign it to an existing asset or a new instance. ");
}
return settings;
}
set
{
lightingSettingsInternal = value;
}
}
[StaticAccessor("GetLightmapSettings()")]
[NativeName("LightingSettings")]
internal static extern LightingSettings lightingSettingsInternal { get; set; }
[StaticAccessor("GetLightmapSettings()")]
[NativeName("LightingSettingsDefaults_Scripting")]
public static extern LightingSettings lightingSettingsDefaults { get; }
// To be used by internal code when just reading settings, not settings them
internal static LightingSettings GetLightingSettingsOrDefaultsFallback()
{
var lightingSettings = Lightmapping.lightingSettingsInternal;
if (lightingSettings != null)
return lightingSettings;
return Lightmapping.lightingSettingsDefaults;
}
// used to make sure that the old APIs work. The user should not be required to manually create an asset, so we do it for them.
internal static LightingSettings GetOrCreateLightingsSettings()
{
if (Lightmapping.lightingSettingsInternal == null)
{
Lightmapping.lightingSettingsInternal = new LightingSettings();
}
return Lightmapping.lightingSettingsInternal;
}
[StaticAccessor("GetLightmapSettingsManager()")]
[NativeName("SetLightingSettingsForScene")]
public static extern void SetLightingSettingsForScene(Scene scene, LightingSettings lightingSettings);
[StaticAccessor("GetLightmapSettingsManager()")]
[NativeName("SetLightingSettingsForScenes")]
public static extern void SetLightingSettingsForScenes(Scene[] scenes, LightingSettings lightingSettings);
[StaticAccessor("GetLightmapSettingsManager()")]
[NativeName("GetLightingSettingsForScene")]
public static extern LightingSettings GetLightingSettingsForScene(Scene scene);
public static void BakeMultipleScenes(string[] paths)
{
if (paths.Length == 0)
return;
for (int i = 0; i < paths.Length; i++)
{
for (int j = i + 1; j < paths.Length; j++)
{
if (paths[i] == paths[j])
throw new System.Exception("no duplication of scenes is allowed");
}
}
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
return;
var sceneSetup = EditorSceneManager.GetSceneManagerSetup();
// Restore old scene setup once the bake finishes
Action OnBakeFinish = null;
OnBakeFinish = () =>
{
EditorSceneManager.SaveOpenScenes();
if (sceneSetup.Length > 0)
EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);
Lightmapping.bakeCompleted -= OnBakeFinish;
};
// Call BakeAsync when all scenes are loaded and attach cleanup delegate
EditorSceneManager.SceneOpenedCallback BakeOnAllOpen = null;
BakeOnAllOpen = (UnityEngine.SceneManagement.Scene scene, SceneManagement.OpenSceneMode loadSceneMode) =>
{
if (SceneManager.loadedSceneCount == paths.Length)
{
BakeAsync();
Lightmapping.bakeCompleted += OnBakeFinish;
EditorSceneManager.sceneOpened -= BakeOnAllOpen;
}
};
EditorSceneManager.sceneOpened += BakeOnAllOpen;
EditorSceneManager.OpenScene(paths[0]);
for (int i = 1; i < paths.Length; i++)
EditorSceneManager.OpenScene(paths[i], OpenSceneMode.Additive);
}
// Reset lightmapping settings
[StaticAccessor("GetLightingSettings()")]
extern internal static void Reset();
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool IsLightmappedOrDynamicLightmappedForRendering([NotNull] Renderer renderer);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool IsOptixDenoiserSupported();
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool IsRadeonDenoiserSupported();
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool IsOpenImageDenoiserSupported();
// Packing for realtime GI may fail of the mesh has zero UV or surface area. This is the outcome for the given renderer.
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool HasZeroAreaMesh([NotNull("NullExceptionObject")] Renderer renderer);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool HasUVOverlaps([NotNull("NullExceptionObject")] Renderer renderer);
// Packing for realtime GI may clamp the output resolution. This is the outcome for the given renderer.
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool HasClampedResolution([NotNull("NullExceptionObject")] Renderer renderer);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetSystemResolution([NotNull("NullExceptionObject")] Renderer renderer, out int width, out int height);
[FreeFunction("GetSystemResolution")]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetTerrainSystemResolution([NotNull("NullExceptionObject")] Terrain terrain, out int width, out int height, out int numChunksInX, out int numChunksInY);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetInstanceResolution([NotNull("NullExceptionObject")] Renderer renderer, out int width, out int height);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetInputSystemHash(int instanceID, out Hash128 inputSystemHash);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetLightmapIndex(int instanceID, out int lightmapIndex);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal Hash128[] GetMainSystemHashes();
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetInstanceHash([NotNull("NullExceptionObject")] Renderer renderer, out Hash128 instanceHash);
[FreeFunction]
[NativeHeader("Editor/Src/GI/EditorHelpers.h")]
extern static internal bool GetGeometryHash([NotNull("NullExceptionObject")] Renderer renderer, out Hash128 geometryHash);
[FreeFunction]
[NativeHeader("Editor/Src/GI/ExtractInstances.h")]
extern static internal bool IsRendererValid([NotNull("NullExceptionObject")] Renderer renderer);
}
}
namespace UnityEditor.Experimental
{
public sealed partial class Lightmapping
{
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
public static extern bool probesIgnoreDirectEnvironment { get; set; }
public static void SetCustomBakeInputs(Vector4[] inputData, int sampleCount)
{
SetCustomBakeInputs(inputData.AsSpan(), sampleCount);
}
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
public static extern void SetCustomBakeInputs(ReadOnlySpan<Vector4> inputData, int sampleCount);
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
private static extern unsafe bool GetCustomBakeResultsCopy(Span<Vector4> results);
public static bool GetCustomBakeResults(Span<Vector4> results)
{
return GetCustomBakeResultsCopy(results);
}
public static bool GetCustomBakeResults([Out] Vector4[] results)
{
return GetCustomBakeResults(results.AsSpan());
}
[StaticAccessor("BakedGISceneManager::Get()", StaticAccessorType.Arrow)]
public static extern ReadOnlySpan<Vector4> GetCustomBakeResultsNoCopy();
[Obsolete("UnityEditor.Experimental.Lightmapping.extractAmbientOcclusion is obsolete, use LightingSettings.extractAO instead. ", false)]
public static bool extractAmbientOcclusion
{
get { return UnityEditor.Lightmapping.GetLightingSettingsOrDefaultsFallback().extractAO; }
set { UnityEditor.Lightmapping.GetOrCreateLightingsSettings().extractAO = value; }
}
[NativeThrows]
[FreeFunction]
public static extern bool BakeAsync(Scene targetScene);
[NativeThrows]
[FreeFunction]
public static extern bool Bake(Scene targetScene);
public static event Action additionalBakedProbesCompleted;
internal static void Internal_CallAdditionalBakedProbesCompleted()
{
if (additionalBakedProbesCompleted != null)
additionalBakedProbesCompleted();
}
[FreeFunction]
internal unsafe static extern bool GetAdditionalBakedProbes(int id, void* outBakedProbeSH, void* outBakedProbeValidity, void* outBakedProbeOctahedralDepth, int outBakedProbeCount);
[Obsolete("Please use the new GetAdditionalBakedProbes with added octahedral depth map data.", false)]
public unsafe static bool GetAdditionalBakedProbes(int id, NativeArray<SphericalHarmonicsL2> outBakedProbeSH, NativeArray<float> outBakedProbeValidity)
{
const int octahedralDepthMapTexelCount = 64; // 8*8
var outBakedProbeOctahedralDepth = new NativeArray<float>(outBakedProbeSH.Length * octahedralDepthMapTexelCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
bool success = GetAdditionalBakedProbes(id, outBakedProbeSH, outBakedProbeValidity, outBakedProbeOctahedralDepth);
outBakedProbeOctahedralDepth.Dispose();
return success;
}
public unsafe static bool GetAdditionalBakedProbes(int id, Span<SphericalHarmonicsL2> outBakedProbeSH, Span<float> outBakedProbeValidity, Span<float> outBakedProbeOctahedralDepth)
{
const int octahedralDepthMapTexelCount = 64; // 8*8
int numEntries = outBakedProbeSH.Length;
if (outBakedProbeOctahedralDepth.Length != numEntries * octahedralDepthMapTexelCount)
{
Debug.LogError("Octahedral array must provide " + numEntries * octahedralDepthMapTexelCount + " floats.");
return false;
}
if (outBakedProbeValidity.Length != numEntries)
{
Debug.LogError("All output arrays must have equal size.");
return false;
}
fixed (void* shPtr = outBakedProbeSH)
fixed (void* validityPtr = outBakedProbeValidity)
fixed (void* octahedralDepthPtr = outBakedProbeOctahedralDepth)
{
return GetAdditionalBakedProbes(id, shPtr, validityPtr, octahedralDepthPtr, outBakedProbeSH.Length);
}
}
public unsafe static bool GetAdditionalBakedProbes(int id, NativeArray<SphericalHarmonicsL2> outBakedProbeSH, NativeArray<float> outBakedProbeValidity, NativeArray<float> outBakedProbeOctahedralDepth)
{
if (outBakedProbeSH == null || !outBakedProbeSH.IsCreated ||
outBakedProbeValidity == null || !outBakedProbeValidity.IsCreated ||
outBakedProbeOctahedralDepth == null || !outBakedProbeOctahedralDepth.IsCreated)
{
Debug.LogError("Output arrays need to be properly initialized.");
return false;
}
const int octahedralDepthMapTexelCount = 64; // 8*8
int numEntries = outBakedProbeSH.Length;
if (outBakedProbeOctahedralDepth.Length != numEntries * octahedralDepthMapTexelCount)
{
Debug.LogError("Octahedral array must provide " + numEntries * octahedralDepthMapTexelCount + " floats.");
return false;
}
if (outBakedProbeValidity.Length != numEntries)
{
Debug.LogError("All output arrays must have equal size.");
return false;
}
void* shPtr = NativeArrayUnsafeUtility.GetUnsafePtr(outBakedProbeSH);
void* validityPtr = NativeArrayUnsafeUtility.GetUnsafePtr(outBakedProbeValidity);
void* octahedralDepthPtr = NativeArrayUnsafeUtility.GetUnsafePtr(outBakedProbeOctahedralDepth);
return GetAdditionalBakedProbes(id, shPtr, validityPtr, octahedralDepthPtr, outBakedProbeSH.Length);
}
public static void SetAdditionalBakedProbes(int id, Vector3[] positions)
{
SetAdditionalBakedProbes(id, positions.AsSpan(), true);
}
public static void SetAdditionalBakedProbes(int id, ReadOnlySpan<Vector3> positions)
{
SetAdditionalBakedProbes(id, positions, true);
}
[FreeFunction]
public static extern void SetAdditionalBakedProbes(int id, ReadOnlySpan<Vector3> positions, bool dering);
[FreeFunction]
public static extern void SetLightDirty(Light light);
}
}