forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLookDevView.cs
More file actions
2098 lines (1779 loc) · 107 KB
/
Copy pathLookDevView.cs
File metadata and controls
2098 lines (1779 loc) · 107 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
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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 UnityEditorInternal;
using UnityEditor.SceneManagement;
using UnityEditor.ShortcutManagement;
using UnityEngine.Rendering;
using UnityEngine.Scripting;
namespace UnityEditor
{
[EditorWindowTitle(title = "Look Dev", useTypeNameAsIconName = true)]
internal class LookDevView : EditorWindow, IHasCustomMenu
{
internal class TestUtility
{
public TestUtility(LookDevView lookDevView)
{
this.lookDevView = lookDevView;
}
public readonly LookDevView lookDevView;
public Camera camera => lookDevView.m_PreviewUtilityContexts[lookDevView.m_LookDevConfig.currentEditionContextIndex].m_PreviewUtility[0].camera;
}
static readonly Vector2 s_MinWindowSize = new Vector2(300, 60);
// Note: Color init in OnEnable
public static Color32 m_FirstViewGizmoColor;
public static Color32 m_SecondViewGizmoColor;
private static string m_configAssetPath = "Library/LookDevConfig.asset";
bool m_IsSaveRegistered = false;
public class Styles
{
public readonly GUIStyle sBigTitleInnerStyle = "IN BigTitle inner";
public readonly GUIStyle sToolBarButton = "toolbarbutton";
public readonly GUIContent sSingleMode1 = EditorGUIUtility.TrIconContent("LookDevSingle1", "Single1 object view");
public readonly GUIContent sSingleMode2 = EditorGUIUtility.TrIconContent("LookDevSingle2", "Single2 object view");
public readonly GUIContent sSideBySideMode = EditorGUIUtility.TrIconContent("LookDevSideBySide", "Side by side comparison view");
public readonly GUIContent sSplitMode = EditorGUIUtility.TrIconContent("LookDevSplit", "Single object split comparison view");
public readonly GUIContent sZoneMode = EditorGUIUtility.TrIconContent("LookDevZone", "Single object zone comparison view");
public readonly GUIContent sLinkActive = EditorGUIUtility.TrIconContent("LookDevMirrorViewsActive", "Links the property between the different views");
public readonly GUIContent sLinkInactive = EditorGUIUtility.TrIconContent("LookDevMirrorViewsInactive", "Links the property between the different views");
public readonly GUIContent sDragAndDropObjsText = EditorGUIUtility.TrTextContent("Drag and drop Prefabs here.");
public readonly GUIStyle[] sPropertyLabelStyle =
{
new GUIStyle(EditorStyles.miniLabel),
new GUIStyle(EditorStyles.miniLabel),
new GUIStyle(EditorStyles.miniLabel)
};
public Styles()
{
sPropertyLabelStyle[0].normal.textColor = LookDevView.m_FirstViewGizmoColor;
sPropertyLabelStyle[1].normal.textColor = LookDevView.m_SecondViewGizmoColor;
}
}
static Styles s_Styles = null;
public static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
internal class PreviewContextCB
{
public CommandBuffer m_drawBallCB;
public CommandBuffer m_patchGBufferCB;
public MaterialPropertyBlock m_drawBallPB;
public PreviewContextCB()
{
m_drawBallCB = new CommandBuffer();
m_drawBallCB.name = "draw ball";
m_patchGBufferCB = new CommandBuffer();
m_patchGBufferCB.name = "patch gbuffer";
m_drawBallPB = new MaterialPropertyBlock();
}
};
internal class PreviewContext
{
public enum PreviewContextPass
{
kView = 0,
kViewWithShadow,
kShadow,
kCount
};
public PreviewRenderUtility[] m_PreviewUtility = new PreviewRenderUtility[(int)PreviewContextPass.kCount];
public Texture[] m_PreviewResult = new Texture[(int)PreviewContextPass.kCount];
public PreviewContextCB[] m_PreviewCB = new PreviewContextCB[(int)PreviewContextPass.kCount];
public PreviewContext()
{
for (int i = 0; i < (int)PreviewContextPass.kCount; ++i)
{
m_PreviewUtility[i] = new PreviewRenderUtility();
m_PreviewUtility[i].camera.fieldOfView = 30.0f;
m_PreviewUtility[i].camera.cullingMask = 1 << Camera.PreviewCullingLayer;
m_PreviewCB[i] = new PreviewContextCB();
}
}
public void Cleanup()
{
for (int contextIndex = 0; contextIndex < (int)PreviewContext.PreviewContextPass.kCount; ++contextIndex)
{
if (m_PreviewUtility[contextIndex] != null)
{
m_PreviewUtility[contextIndex].Cleanup();
m_PreviewUtility[contextIndex] = null;
}
}
}
}
public static void DrawFullScreenQuad(Rect previewRect)
{
GL.PushMatrix();
GL.LoadOrtho();
GL.Viewport(previewRect);
GL.Begin(GL.QUADS);
GL.TexCoord2(0, 0);
GL.Vertex3(0.0F, 0.0F, 0);
GL.TexCoord2(0, 1);
GL.Vertex3(0.0F, 1.0F, 0);
GL.TexCoord2(1, 1);
GL.Vertex3(1.0F, 1.0F, 0);
GL.TexCoord2(1, 0);
GL.Vertex3(1.0F, 0.0F, 0);
GL.End();
GL.PopMatrix();
}
private PreviewContext[] m_PreviewUtilityContexts = new PreviewContext[2];
private GUIContent m_RenderdocContent;
private GUIContent m_SyncLightVertical;
private GUIContent m_ResetEnvironment;
private Rect[] m_PreviewRects = new Rect[3];
private Rect m_DisplayRect;
private Vector4 m_ScreenRatio;
private Vector2 m_OnMouseDownOffsetToGizmo;
private LookDevEditionContext m_CurrentDragContext = LookDevEditionContext.None;
private LookDevOperationType m_LookDevOperationType = LookDevOperationType.None;
private RenderTexture m_FinalCompositionTexture = null;
private LookDevEnvironmentWindow m_LookDevEnvWindow = null;
private bool m_ShowLookDevEnvWindow = false;
private bool m_CaptureRD = false;
private bool[] m_LookDevModeToggles = new bool[(int)LookDevMode.Count];
private float m_GizmoThickness = 0.0028f;
private float m_GizmoThicknessSelected = 0.015f;
private float m_GizmoCircleRadius = 0.014f;
private float m_GizmoCircleRadiusSelected = 0.03f;
private bool m_ForceGizmoRenderSelector = false;
private LookDevOperationType m_GizmoRenderMode = LookDevOperationType.None;
private float m_BlendFactorCircleSelectionRadius = 0.03f;
private float m_BlendFactorCircleRadius = 0.01f;
private Rect m_ControlWindowRect;
private float kLineHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
private LookDevConfig m_LookDevConfig = null;// Configuration of the 3D view. This will be saved in the library folder (it should not be versionned)
private LookDevEnvironmentLibrary m_LookDevEnvLibrary = null;// This is the working copy of the library in use. It's always an instance of the chosen library in order not to alter the original one.
[SerializeField]
private LookDevEnvironmentLibrary m_LookDevUserEnvLibrary = null;// Current user library. This is the asset we are going to serialize in the end.
private bool m_DisplayDebugGizmo = false;
private float kReferenceScale = 1080.0f;
private int m_hotControlID = 0;
private float m_DirBias = 0.01f;
private float m_DirNormalBias = 0.4f;
private float m_CurrentObjRotationOffset = 0.0f;
private float m_ObjRotationAcc = 0.0f;
private float m_EnvRotationAcc = 0.0f;
// This a workaround: Currently the edition scene and any preview scenes are not distinct. They share the same world space
// So if there are reflection probes in the main edition scene, they will affect the lookdev.
// Since there is now good way yet to separate the two scenes properly, we just render far under ground and hope that no reflections probes are there...
private float kDefaultSceneHeight = -500.0f;
private CameraControllerStandard m_CameraController = new CameraControllerStandard();
internal PreviewContext[] previewUtilityContexts { get { return m_PreviewUtilityContexts; } }
public int hotControl
{
get { return m_hotControlID; }
}
public LookDevConfig config
{
get { return m_LookDevConfig; }
}
public LookDevEnvironmentLibrary envLibrary
{
get { return m_LookDevEnvLibrary; }
set
{
if (value == null)
{
// "None" is selected, we have to reset to the default library
m_LookDevEnvLibrary = ScriptableObject.CreateInstance<LookDevEnvironmentLibrary>();
m_LookDevUserEnvLibrary = null;
}
else
{
// Update the current user library
if (value != m_LookDevUserEnvLibrary)
{
m_LookDevUserEnvLibrary = value;
m_LookDevEnvLibrary = ScriptableObject.Instantiate<LookDevEnvironmentLibrary>(value);
m_LookDevEnvLibrary.SetLookDevView(this);
}
}
int hdriCount = m_LookDevEnvLibrary.hdriCount;
if (m_LookDevConfig.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Left) >= hdriCount || m_LookDevConfig.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Right) >= hdriCount)
{
// When switching library, the new one can have fewer HDRIs so we reset the HDRI property to zero to make sure we don't get out of range.
m_LookDevConfig.UpdatePropertyLink(LookDevProperty.HDRI, true);
m_LookDevConfig.UpdateIntProperty(LookDevProperty.HDRI, 0);
}
}
}
public LookDevEnvironmentLibrary userEnvLibrary
{
get { return m_LookDevUserEnvLibrary; }
}
public void CreateNewLibrary(string assetPath)
{
// Create a new library based on the state of the current one.
LookDevEnvironmentLibrary newLibrary = ScriptableObject.Instantiate(envLibrary) as LookDevEnvironmentLibrary;
AssetDatabase.CreateAsset(newLibrary, assetPath);
envLibrary = AssetDatabase.LoadAssetAtPath(assetPath, typeof(LookDevEnvironmentLibrary)) as LookDevEnvironmentLibrary;
}
[RequiredByNativeCode]
public static void OpenInLookDevTool(UnityEngine.Object go)
{
LookDevView lookDev = EditorWindow.GetWindow<LookDevView>();
lookDev.m_LookDevConfig.SetCurrentPreviewObject(go as GameObject, LookDevEditionContext.Left);
lookDev.m_LookDevConfig.SetCurrentPreviewObject(go as GameObject, LookDevEditionContext.Right);
lookDev.Frame(LookDevEditionContext.Left, false);
lookDev.Repaint();
}
public LookDevView()
{
for (int i = 0; i < (int)LookDevMode.Count; ++i)
{
m_LookDevModeToggles[i] = false;
}
wantsMouseMove = true;
minSize = s_MinWindowSize;
}
private void Initialize()
{
LookDevResources.Initialize();
InitializePreviewUtilities();
LoadLookDevConfig();
// When we reload the scene the pointer like m_DefaultHDRI can become null but the list of HDRI is not null
// so test it to be sure we don't add two time default HDRI.
if (m_LookDevEnvLibrary.hdriList.Count == 0)
{
UpdateContextWithCurrentHDRI(LookDevResources.m_DefaultHDRI);
}
if (m_LookDevEnvWindow == null)
{
m_LookDevEnvWindow = new LookDevEnvironmentWindow(this);
}
}
void InitializePreviewUtilities()
{
if (m_PreviewUtilityContexts[0] == null)
{
// Do this check only the first time
if (QualitySettings.activeColorSpace == ColorSpace.Gamma)
Debug.LogWarning("Look Dev is designed for linear color space. Currently project is set to gamma color space. This can be changed in player settings.");
if (Rendering.EditorGraphicsSettings.GetCurrentTierSettings().renderingPath != RenderingPath.DeferredShading)
Debug.LogWarning("Look Dev switched rendering mode to deferred shading for display.");
if (Camera.main != null && !Camera.main.allowHDR)
Debug.LogWarning("Look Dev switched HDR mode on for display.");
for (int i = 0; i < 2; ++i)
m_PreviewUtilityContexts[i] = new PreviewContext();
}
}
private void Cleanup()
{
LookDevResources.Cleanup();
m_LookDevConfig.Cleanup();
for (int i = 0; i < 2; ++i)
{
if (m_PreviewUtilityContexts[i] != null)
m_PreviewUtilityContexts[i].Cleanup();
m_PreviewUtilityContexts[i] = null;
}
if (m_FinalCompositionTexture)
{
UnityEngine.Object.DestroyImmediate(m_FinalCompositionTexture);
m_FinalCompositionTexture = null;
}
m_CameraController.DeactivateFlyModeContext();
}
private void UpdateRenderTexture(Rect rect)
{
int rtWidth = (int)rect.width;
int rtHeight = (int)rect.height;
if (!m_FinalCompositionTexture || m_FinalCompositionTexture.width != rtWidth || m_FinalCompositionTexture.height != rtHeight)
{
if (m_FinalCompositionTexture)
{
UnityEngine.Object.DestroyImmediate(m_FinalCompositionTexture);
m_FinalCompositionTexture = null;
}
m_FinalCompositionTexture = new RenderTexture(rtWidth, rtHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
m_FinalCompositionTexture.hideFlags = HideFlags.HideAndDontSave;
}
}
private void GetRenderableBoundsRecurse(ref Bounds bounds, GameObject go)
{
// Do we have a mesh?
MeshRenderer renderer = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
MeshFilter filter = go.GetComponent(typeof(MeshFilter)) as MeshFilter;
if (renderer && filter && filter.sharedMesh)
{
// To prevent origo from always being included in bounds we initialize it
// with renderer.bounds. This ensures correct bounds for meshes with origo outside the mesh.
if (bounds.extents == Vector3.zero)
bounds = renderer.bounds;
else
bounds.Encapsulate(renderer.bounds);
}
// Do we have a skinned mesh?
SkinnedMeshRenderer skin = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer;
if (skin && skin.sharedMesh)
{
if (bounds.extents == Vector3.zero)
bounds = skin.bounds;
else
bounds.Encapsulate(skin.bounds);
}
// Do we have a Sprite?
SpriteRenderer sprite = go.GetComponent(typeof(SpriteRenderer)) as SpriteRenderer;
if (sprite && sprite.sprite)
{
if (bounds.extents == Vector3.zero)
bounds = sprite.bounds;
else
bounds.Encapsulate(sprite.bounds);
}
// Recurse into children
foreach (Transform t in go.transform)
{
GetRenderableBoundsRecurse(ref bounds, t.gameObject);
}
}
private void RenderScene(Rect previewRect, LookDevContext lookDevContext, PreviewContext previewUtilityContext, GameObject[] currentObjectByPasses, CameraState originalCameraState, bool secondView)
{
// Explanation of how this work:
// To simulate the shadow of a directional light, we want to interpolate between two environments. One with a skybox without sun for shadowed area and the other with the sun.
// To create the lerp mask we render the scene with a white diffuse material (by patching the GBuffer so object can used their regular material) and a single shadow casting directional light.
// This will create a mask where the shadowed area is 0 and the lit area is 1 with a smooth NDotL transition in-between.
// Then we render the scene twice, once with the sunless environment and once with the original environment.
// At last we composite everything in the lookdev compositing pass.
// Do a render with a white material and no GI at all. This will result in a shadow mask
// If shadows are disabled or if we need a debug view mode, we don't send an object to be rendered so that the mask stays neutral white.
bool needNeutralMask = !m_LookDevConfig.enableShadowCubemap || (m_LookDevConfig.enableShadowCubemap && ((DrawCameraMode)lookDevContext.shadingMode != DrawCameraMode.Normal) && ((DrawCameraMode)lookDevContext.shadingMode != DrawCameraMode.TexturedWire));
previewUtilityContext.m_PreviewResult[(int)PreviewContext.PreviewContextPass.kShadow] = needNeutralMask ?
Texture2D.whiteTexture :
RenderScene(previewRect, lookDevContext, previewUtilityContext, currentObjectByPasses[(int)PreviewContext.PreviewContextPass.kShadow], originalCameraState, null, PreviewContext.PreviewContextPass.kShadow, secondView);
// Render the scene normally.
CubemapInfo cubemapInfo = m_LookDevEnvLibrary.hdriList[lookDevContext.currentHDRIIndex];
previewUtilityContext.m_PreviewResult[(int)PreviewContext.PreviewContextPass.kView] = RenderScene(previewRect, lookDevContext, previewUtilityContext, currentObjectByPasses[(int)PreviewContext.PreviewContextPass.kView], originalCameraState, cubemapInfo, PreviewContext.PreviewContextPass.kView, secondView);
// Render the scene with the environment without the sun
previewUtilityContext.m_PreviewResult[(int)PreviewContext.PreviewContextPass.kViewWithShadow] = RenderScene(previewRect, lookDevContext, previewUtilityContext, currentObjectByPasses[(int)PreviewContext.PreviewContextPass.kViewWithShadow], originalCameraState, cubemapInfo.cubemapShadowInfo, PreviewContext.PreviewContextPass.kViewWithShadow, secondView);
}
private Texture RenderScene(Rect previewRect, LookDevContext lookDevContext, PreviewContext previewUtilityContext, GameObject currentObject, CameraState originalCameraState, CubemapInfo cubemapInfo, PreviewContext.PreviewContextPass contextPass, bool secondView)
{
PreviewRenderUtility previewUtility = previewUtilityContext.m_PreviewUtility[(int)contextPass];
PreviewContextCB contextCB = previewUtilityContext.m_PreviewCB[(int)contextPass];
// Save several lighting panel parameter as they are not unique to our lookdev but share with the scene view :(
UnityEngine.Rendering.DefaultReflectionMode oldReflectionMode = RenderSettings.defaultReflectionMode;
UnityEngine.Rendering.AmbientMode oldAmbientMode = RenderSettings.ambientMode;
Cubemap oldCubeMap = RenderSettings.customReflection;
Material oldSkybox = RenderSettings.skybox;
float oldAmbientIntensity = RenderSettings.ambientIntensity;
SphericalHarmonicsL2 oldAmbientProbe = RenderSettings.ambientProbe;
float oldReflectionIntensity = RenderSettings.reflectionIntensity;
previewUtility.BeginPreview(previewRect, styles.sBigTitleInnerStyle);
bool shadowPass = contextPass == PreviewContext.PreviewContextPass.kShadow;
DrawCameraMode shadingMode = (DrawCameraMode)lookDevContext.shadingMode;
bool needDebugMode = shadingMode != DrawCameraMode.Normal && shadingMode != DrawCameraMode.TexturedWire;
float oldShadowDistance = QualitySettings.shadowDistance;
Vector3 oldShadowCascade4Split = QualitySettings.shadowCascade4Split;
float cubemapOffset = m_LookDevEnvLibrary.hdriList[lookDevContext.currentHDRIIndex].angleOffset;
// We need to invert the sign of the envRotation because we move the camera and not the cubemap itself
float envRotation = -(lookDevContext.envRotation + cubemapOffset);
// Here is a little trick. The lookdev allows us to rotate the environment.
// The problem is that we can't properly rotate it in the engine right now.
// So to simulate this, we always rotate the camera around the center of the world and compensate by rotating and moving the observed object by the inverse transform.
CameraState cameraState = originalCameraState.Clone();
Vector3 angles = cameraState.rotation.value.eulerAngles;
cameraState.rotation.value = Quaternion.Euler(angles + new Vector3(0.0f, envRotation, 0.0f)); // Add environment rotation to current camera orientation
cameraState.pivot.value = new Vector3(0.0f, kDefaultSceneHeight, 0.0f); // Look at the center of the world
cameraState.UpdateCamera(previewUtility.camera);
previewUtility.camera.renderingPath = RenderingPath.DeferredShading;
previewUtility.camera.clearFlags = shadowPass ? CameraClearFlags.Color : CameraClearFlags.Skybox; // We need to clear to white for the shadow mask to work properly
previewUtility.camera.backgroundColor = Color.white;
previewUtility.camera.allowHDR = true;
for (int lightIndex = 0; lightIndex < 2; lightIndex++)
{
previewUtility.lights[lightIndex].enabled = false;
previewUtility.lights[lightIndex].intensity = 0.0f;
previewUtility.lights[lightIndex].shadows = LightShadows.None;
}
// If shadows are disable or if we are in a Debug view mode (albedo, normal, etc) we don't want to have shadows in the mask
if (currentObject != null && shadowPass && m_LookDevConfig.enableShadowCubemap && !needDebugMode) // The default shadow flag serves as a switch to completely remove the shadows, even those specific to different environments.
{
Bounds bounds = new Bounds(currentObject.transform.position, Vector3.zero);
GetRenderableBoundsRecurse(ref bounds, currentObject);
float maxBound = Mathf.Max(bounds.max.x, Mathf.Max(bounds.max.y, bounds.max.z)); // Compute the approximate size of the object
float shadowMaxDistance = m_LookDevConfig.shadowDistance > 0.0f ? m_LookDevConfig.shadowDistance : 25.0f * maxBound; // We want to see shadows until a distance of 25 times the size of the object.
float splitBaseDistance = Mathf.Min(maxBound * 2.0f, 20.0f) / shadowMaxDistance; // Try to conserve a bit of shadow precision for big objects
QualitySettings.shadowDistance = shadowMaxDistance;
QualitySettings.shadowCascade4Split = new Vector3(Mathf.Clamp(splitBaseDistance, 0.0f, 1.0f), Mathf.Clamp(splitBaseDistance * 2.0f, 0.0f, 1.0f), Mathf.Clamp(splitBaseDistance * 6.0f, 0.0f, 1.0f));
ShadowInfo shadowInfo = m_LookDevEnvLibrary.hdriList[lookDevContext.currentHDRIIndex].shadowInfo;
// previewUtility.m_Light[0].enabled = true; // Apparently doing this will add the light to the global manager, making it visible in the scene view... so don't do that.
previewUtility.lights[0].intensity = 1.0f;
previewUtility.lights[0].color = Color.white;
previewUtility.lights[0].shadows = LightShadows.Soft;
previewUtility.lights[0].shadowBias = m_DirBias;
previewUtility.lights[0].shadowNormalBias = m_DirNormalBias;
previewUtility.lights[0].transform.rotation = Quaternion.Euler(shadowInfo.latitude, shadowInfo.longitude, 0.0f);
// Can't pre-record the command buffer :( because to make MaterialPropertyBlock working, it need to be setup each frame with DrawMesh. Calling DrawMesh mean we need to call clear
// else DrawMesh accumulate each frame. Calling clear mean we can't pre-record command buffer.
// We need a command buffer to patch the Gbuffer to generate the 'fake' screen space shadow map
// Patch diffuse+specular+smoothness into two MRTs
contextCB.m_patchGBufferCB.Clear();
RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1 };
contextCB.m_patchGBufferCB.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget);
contextCB.m_patchGBufferCB.DrawMesh(LookDevResources.m_ScreenQuadMesh, Matrix4x4.identity, LookDevResources.m_GBufferPatchMaterial);
// set this command buffer to be executed just before deferred lighting pass
previewUtility.camera.AddCommandBuffer(CameraEvent.AfterGBuffer, contextCB.m_patchGBufferCB);
if (m_LookDevConfig.showBalls)
{
// We need to draw the balls in order that they are not shadowed
contextCB.m_drawBallCB.Clear();
// Patch lighting buffer - This will write the shape of the screen space balls after the render of the shadow map to be sure we display only the normal view 0
RenderTargetIdentifier[] lightingBuffer = { BuiltinRenderTextureType.CameraTarget };
contextCB.m_drawBallCB.SetRenderTarget(lightingBuffer, BuiltinRenderTextureType.CameraTarget);
contextCB.m_drawBallPB.SetVector("_WindowsSize", new Vector4(previewUtility.camera.pixelWidth, previewUtility.camera.pixelHeight, secondView ? 1.0f : 0.0f, 0));
contextCB.m_drawBallCB.DrawMesh(LookDevResources.m_ScreenQuadMesh, Matrix4x4.identity, LookDevResources.m_DrawBallsMaterial, 0, 1, contextCB.m_drawBallPB);
// Draw ball in screen space by patching the GBuffer
previewUtility.camera.AddCommandBuffer(CameraEvent.AfterLighting, contextCB.m_drawBallCB);
}
}
previewUtility.ambientColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
Cubemap skyboxCubemap = cubemapInfo != null ? cubemapInfo.cubemap : null;
LookDevResources.m_SkyboxMaterial.SetTexture("_Tex", skyboxCubemap);
LookDevResources.m_SkyboxMaterial.SetFloat("_Exposure", 1.0f); // Exposure handled in the compositing shader
RenderSettings.customReflection = skyboxCubemap;
// Cache computation of ambient probe
if (cubemapInfo != null && !cubemapInfo.alreadyComputed && !shadowPass)
{
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.skybox = LookDevResources.m_SkyboxMaterial;
DynamicGI.UpdateEnvironment();
cubemapInfo.ambientProbe = RenderSettings.ambientProbe;
RenderSettings.skybox = oldSkybox;
cubemapInfo.alreadyComputed = true;
}
RenderSettings.ambientProbe = cubemapInfo != null ? cubemapInfo.ambientProbe : LookDevResources.m_ZeroAmbientProbe;
RenderSettings.skybox = LookDevResources.m_SkyboxMaterial;
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
// Note: This test must be all after the setup of the RenderSettings.ambientProbe
if (contextPass == PreviewContext.PreviewContextPass.kView && m_LookDevConfig.showBalls)
{
// To display greyball we need ambient probe information
// Copy/paste from SHContantCache.cpp and convert to C#. Yes we should expose C++ impl to c #
const int kSHCoefficients = 7;
Vector4[] shaderConstants = new Vector4[kSHCoefficients];
GetShaderConstantsFromNormalizedSH(RenderSettings.ambientProbe, shaderConstants);
// Can't pre-record the command buffer :( because to make MaterialPropertyBlock working, it need to be setup each frame with DrawMesh. Calling DrawMesh mean we need to call clear
// else DrawMesh accumulate each frame. Calling clear mean we can't pre-record command buffer.
// We modify the Gbuffer to draw chrome/Grey balls
contextCB.m_drawBallCB.Clear();
// Patch diffuse+occlusion+specular+smoothness into three MRTs
// See https://issuetracker.unity3d.com/issues/camera-slash-commandbuffer-commandbuffer-dot-blit-texture2d-dot-blacktexture-builtinrendertexturetype-dot-gbuffer3-fails-when-hdr-is-enabled
// for why we do not use BuiltinRenderTextureType.GBuffer3 but the camera target instead (LookDev is always HDR)
RenderTargetIdentifier[] mrt2 = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1, BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.CameraTarget };
contextCB.m_drawBallCB.SetRenderTarget(mrt2, BuiltinRenderTextureType.CameraTarget);
contextCB.m_drawBallPB.SetVector("_SHAr", shaderConstants[0]);
contextCB.m_drawBallPB.SetVector("_SHAg", shaderConstants[1]);
contextCB.m_drawBallPB.SetVector("_SHAb", shaderConstants[2]);
contextCB.m_drawBallPB.SetVector("_SHBr", shaderConstants[3]);
contextCB.m_drawBallPB.SetVector("_SHBg", shaderConstants[4]);
contextCB.m_drawBallPB.SetVector("_SHBb", shaderConstants[5]);
contextCB.m_drawBallPB.SetVector("_SHC", shaderConstants[6]);
contextCB.m_drawBallPB.SetVector("_WindowsSize", new Vector4(previewUtility.camera.pixelWidth, previewUtility.camera.pixelHeight, secondView ? 1.0f : 0.0f, 0));
contextCB.m_drawBallCB.DrawMesh(LookDevResources.m_ScreenQuadMesh, Matrix4x4.identity, LookDevResources.m_DrawBallsMaterial, 0, 0, contextCB.m_drawBallPB);
// Draw ball in screen space by patching the GBuffer
previewUtility.camera.AddCommandBuffer(CameraEvent.AfterGBuffer, contextCB.m_drawBallCB);
}
Vector3 oldAngles = Vector3.zero;
Vector3 oldTranslation = Vector3.zero;
if (currentObject != null)
{
// Setup object property
LODGroup lodGroup = currentObject.GetComponent(typeof(LODGroup)) as LODGroup;
if (lodGroup != null)
{
lodGroup.ForceLOD(lookDevContext.lodIndex);
}
PreviewRenderUtility.SetEnabledRecursive(currentObject, true);
oldAngles = currentObject.transform.eulerAngles;
oldTranslation = currentObject.transform.localPosition;
currentObject.transform.position = new Vector3(0.0f, kDefaultSceneHeight, 0.0f);
currentObject.transform.rotation = Quaternion.identity;
// Applies inverse transform from camera pivot + environment rotation.
currentObject.transform.Rotate(0.0f, envRotation, 0.0f);
currentObject.transform.Translate(-originalCameraState.pivot.value);
currentObject.transform.Rotate(0.0f, m_CurrentObjRotationOffset, 0.0f);
}
// Specific drawing pass for TexturedWire
if (shadingMode == DrawCameraMode.TexturedWire && !shadowPass)
{
Handles.ClearCamera(previewRect, previewUtility.camera);
Handles.DrawCamera(previewRect, previewUtility.camera, shadingMode);
}
else
{
previewUtility.Render(true, false);
}
if (currentObject != null)
{
// restore initial transform
currentObject.transform.eulerAngles = oldAngles;
currentObject.transform.position = oldTranslation;
PreviewRenderUtility.SetEnabledRecursive(currentObject, false);
}
if (needDebugMode && !shadowPass) // Even with the debug modes we need to keep the shadow mask white.
{
if (Event.current.type == EventType.Repaint)
{
float scaleFac = previewUtility.GetScaleFactor(previewRect.width, previewRect.height);
LookDevResources.m_DeferredOverlayMaterial.SetInt("_DisplayMode", (int)shadingMode - (int)DrawCameraMode.DeferredDiffuse);
Graphics.DrawTexture(new Rect(0, 0, previewRect.width * scaleFac, previewRect.height * scaleFac), EditorGUIUtility.whiteTexture, LookDevResources.m_DeferredOverlayMaterial);
}
}
if (shadowPass)
{
previewUtility.camera.RemoveCommandBuffer(CameraEvent.AfterGBuffer, contextCB.m_patchGBufferCB);
if (m_LookDevConfig.showBalls)
{
previewUtility.camera.RemoveCommandBuffer(CameraEvent.AfterLighting, contextCB.m_drawBallCB);
}
}
else if (contextPass == PreviewContext.PreviewContextPass.kView && m_LookDevConfig.showBalls)
{
// Draw ball in screen space by patching the GBuffer
previewUtility.camera.RemoveCommandBuffer(CameraEvent.AfterGBuffer, contextCB.m_drawBallCB);
}
QualitySettings.shadowCascade4Split = oldShadowCascade4Split;
QualitySettings.shadowDistance = oldShadowDistance;
// Restore saved render settings
RenderSettings.defaultReflectionMode = oldReflectionMode;
RenderSettings.ambientMode = oldAmbientMode;
RenderSettings.customReflection = oldCubeMap;
RenderSettings.skybox = oldSkybox;
RenderSettings.ambientIntensity = oldAmbientIntensity;
RenderSettings.reflectionIntensity = oldReflectionIntensity;
RenderSettings.ambientProbe = oldAmbientProbe;
return previewUtility.EndPreview();
}
public void UpdateLookDevModeToggle(LookDevMode lookDevMode, bool value)
{
LookDevMode newLookDevMode = lookDevMode;
if (value)
{
m_LookDevModeToggles[(int)lookDevMode] = value;
// Disable all others
for (int i = 0; i < (int)LookDevMode.Count; ++i)
{
if (i != (int)lookDevMode)
{
m_LookDevModeToggles[i] = false;
}
}
newLookDevMode = lookDevMode;
}
else
{
for (int i = 0; i < (int)LookDevMode.Count; ++i)
{
if (m_LookDevModeToggles[i])
{
newLookDevMode = (LookDevMode)i;
}
}
// all are false, keep current mode
m_LookDevModeToggles[(int)lookDevMode] = true;
newLookDevMode = lookDevMode;
}
m_LookDevConfig.lookDevMode = newLookDevMode;
Repaint();
}
void OnUndoRedo()
{
Repaint();
}
private void DoAdditionalGUI()
{
if (m_LookDevConfig.lookDevMode == LookDevMode.SideBySide)
{
// Camera link icon
int linkIconSize = 32;
GUILayout.BeginArea(new Rect((m_PreviewRects[2].width - linkIconSize) / 2, (m_PreviewRects[2].height - linkIconSize) / 2, linkIconSize, linkIconSize));
{
EditorGUI.BeginChangeCheck();
bool isLink = m_LookDevConfig.sideBySideCameraLinked;
bool linked = GUILayout.Toggle(isLink, GetGUIContentLink(isLink), styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.sideBySideCameraLinked = linked;
// When re-linking camera we need to copy the current context into the other one
if (linked)
{
CameraState currentState = m_LookDevConfig.currentEditionContext == LookDevEditionContext.Left ? m_LookDevConfig.cameraStateLeft : m_LookDevConfig.cameraStateRight;
CameraState otherState = m_LookDevConfig.currentEditionContext == LookDevEditionContext.Left ? m_LookDevConfig.cameraStateRight : m_LookDevConfig.cameraStateLeft;
otherState.Copy(currentState);
}
}
}
GUILayout.EndArea();
}
}
GUIStyle GetPropertyLabelStyle(LookDevProperty property)
{
if (m_LookDevConfig.IsPropertyLinked(property) || m_LookDevConfig.lookDevMode == LookDevMode.Single1 || m_LookDevConfig.lookDevMode == LookDevMode.Single2)
return styles.sPropertyLabelStyle[2];
else
return styles.sPropertyLabelStyle[m_LookDevConfig.currentEditionContextIndex];
}
GUIContent GetGUIContentLink(bool active)
{
return active ? styles.sLinkActive : styles.sLinkInactive;
}
private void DoControlWindow()
{
if (!m_LookDevConfig.showControlWindows)
return;
float sliderLabelWidth = 68.0f;
float sliderWidth = 150.0f;
float fieldWidth = 30.0f;
GUILayout.BeginArea(m_ControlWindowRect, styles.sBigTitleInnerStyle);
{
GUILayout.BeginVertical();
{
GUILayout.BeginHorizontal(GUILayout.Height(kLineHeight));
{
GUILayout.FlexibleSpace();
bool value = false;
EditorGUI.BeginChangeCheck();
value = GUILayout.Toggle(m_LookDevModeToggles[(int)LookDevMode.Single1], styles.sSingleMode1, styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
UpdateLookDevModeToggle(LookDevMode.Single1, value);
m_LookDevConfig.UpdateFocus(LookDevEditionContext.Left);
Repaint();
}
EditorGUI.BeginChangeCheck();
value = GUILayout.Toggle(m_LookDevModeToggles[(int)LookDevMode.Single2], styles.sSingleMode2, styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
UpdateLookDevModeToggle(LookDevMode.Single2, value);
m_LookDevConfig.UpdateFocus(LookDevEditionContext.Right);
Repaint();
}
EditorGUI.BeginChangeCheck();
value = GUILayout.Toggle(m_LookDevModeToggles[(int)LookDevMode.SideBySide], styles.sSideBySideMode, styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
UpdateLookDevModeToggle(LookDevMode.SideBySide, value);
}
EditorGUI.BeginChangeCheck();
value = GUILayout.Toggle(m_LookDevModeToggles[(int)LookDevMode.Split], styles.sSplitMode, styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
UpdateLookDevModeToggle(LookDevMode.Split, value);
}
EditorGUI.BeginChangeCheck();
value = GUILayout.Toggle(m_LookDevModeToggles[(int)LookDevMode.Zone], styles.sZoneMode, styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
UpdateLookDevModeToggle(LookDevMode.Zone, value);
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.Height(kLineHeight));
{
GUILayout.Label(LookDevViewsWindow.styles.sExposure, GetPropertyLabelStyle(LookDevProperty.ExposureValue), GUILayout.Width(sliderLabelWidth));
float fExposureValue = m_LookDevConfig.currentLookDevContext.exposureValue;
EditorGUI.BeginChangeCheck();
// Display in the float field is rounded for display. To 1 decimal in case of negative number to account for the '-' character.
float roundedExposureRange = Mathf.Round(m_LookDevConfig.exposureRange);
fExposureValue = Mathf.Clamp(GUILayout.HorizontalSlider((float)Math.Round(fExposureValue, fExposureValue < 0.0f ? 1 : 2), -roundedExposureRange, roundedExposureRange, GUILayout.Width(sliderWidth)), -roundedExposureRange, roundedExposureRange);
fExposureValue = Mathf.Clamp(EditorGUILayout.FloatField(fExposureValue, GUILayout.Width(fieldWidth)), -roundedExposureRange, roundedExposureRange);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdateFloatProperty(LookDevProperty.ExposureValue, fExposureValue);
}
bool linked = false;
EditorGUI.BeginChangeCheck();
bool isLink = m_LookDevConfig.IsPropertyLinked(LookDevProperty.ExposureValue);
linked = GUILayout.Toggle(isLink, GetGUIContentLink(isLink), styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdatePropertyLink(LookDevProperty.ExposureValue, linked);
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.Height(kLineHeight));
{
using (new EditorGUI.DisabledScope(m_LookDevEnvLibrary.hdriList.Count <= 1))
{
GUILayout.Label(LookDevViewsWindow.styles.sEnvironment, GetPropertyLabelStyle(LookDevProperty.HDRI), GUILayout.Width(sliderLabelWidth));
int iHDRIIndex = -1;
if (m_LookDevEnvLibrary.hdriList.Count > 1)
{
int maxHDRIIndex = m_LookDevEnvLibrary.hdriList.Count - 1;
iHDRIIndex = m_LookDevConfig.currentLookDevContext.currentHDRIIndex;
EditorGUI.BeginChangeCheck();
iHDRIIndex = (int)GUILayout.HorizontalSlider(iHDRIIndex, 0.0f, (float)maxHDRIIndex, GUILayout.Width(sliderWidth));
iHDRIIndex = Mathf.Clamp(EditorGUILayout.IntField(iHDRIIndex, GUILayout.Width(fieldWidth)), 0, maxHDRIIndex);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdateIntProperty(LookDevProperty.HDRI, iHDRIIndex);
}
}
else
{
GUILayout.HorizontalSlider(0.0f, 0.0f, 0.0f, GUILayout.Width(sliderWidth));
GUILayout.Label(LookDevViewsWindow.styles.sZero, EditorStyles.miniLabel, GUILayout.Width(fieldWidth));
}
}
bool linked = false;
EditorGUI.BeginChangeCheck();
bool isLink = m_LookDevConfig.IsPropertyLinked(LookDevProperty.HDRI);
linked = GUILayout.Toggle(isLink, GetGUIContentLink(isLink), styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdatePropertyLink(LookDevProperty.HDRI, linked);
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.Height(kLineHeight));
{
GUILayout.Label(LookDevViewsWindow.styles.sShadingMode, GetPropertyLabelStyle(LookDevProperty.ShadingMode), GUILayout.Width(sliderLabelWidth));
int shadingMode = m_LookDevConfig.currentLookDevContext.shadingMode;
EditorGUI.BeginChangeCheck();
shadingMode = EditorGUILayout.IntPopup("", shadingMode, LookDevViewsWindow.styles.sShadingModeStrings, LookDevViewsWindow.styles.sShadingModeValues, GUILayout.Width(fieldWidth + sliderWidth + 4.0f));
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdateIntProperty(LookDevProperty.ShadingMode, shadingMode);
}
bool linked = false;
EditorGUI.BeginChangeCheck();
bool isLink = m_LookDevConfig.IsPropertyLinked(LookDevProperty.ShadingMode);
linked = GUILayout.Toggle(isLink, GetGUIContentLink(isLink), styles.sToolBarButton);
if (EditorGUI.EndChangeCheck())
{
m_LookDevConfig.UpdatePropertyLink(LookDevProperty.ShadingMode, linked);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
GUILayout.EndArea();
}
public void Update()
{
// Force refresh of the frame to make the object turn
if (m_ObjRotationAcc > 0.0f || m_EnvRotationAcc > 0.0f)
{
// This is necessary to make the framerate normal for the editor window.
Repaint();
}
}
private void LoadRenderDoc()
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
RenderDoc.Load();
ShaderUtil.RecreateGfxDevice();
}
}
private float ComputeLookDevEnvWindowWidth()
{
bool needVerticalScrollBar = (m_DisplayRect.height - 5.0f) < LookDevEnvironmentWindow.m_HDRIHeight * m_LookDevEnvLibrary.hdriCount;
return LookDevEnvironmentWindow.m_HDRIWidth + (needVerticalScrollBar ? 19.0f : 5.0f);
}
private float ComputeLookDevEnvWindowHeight()
{
return m_DisplayRect.height;
}
private void DoToolbarGUI()
{
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
Rect settingsRect = GUILayoutUtility.GetRect(LookDevSettingsWindow.styles.sTitle, EditorStyles.toolbarDropDown, GUILayout.Width(120));
if (EditorGUI.DropdownButton(settingsRect, LookDevSettingsWindow.styles.sTitle, FocusType.Passive, EditorStyles.toolbarDropDown))
{
Rect rect = GUILayoutUtility.topLevel.GetLast();
PopupWindow.Show(rect, new LookDevSettingsWindow(this));
GUIUtility.ExitGUI();
}
settingsRect = GUILayoutUtility.GetRect(LookDevViewsWindow.styles.sTitle, EditorStyles.toolbarDropDown, GUILayout.Width(120));
if (EditorGUI.DropdownButton(settingsRect, LookDevViewsWindow.styles.sTitle, FocusType.Passive, EditorStyles.toolbarDropDown))
{
Rect rect = GUILayoutUtility.topLevel.GetLast();
PopupWindow.Show(rect, new LookDevViewsWindow(this));
GUIUtility.ExitGUI();
}
m_LookDevConfig.enableShadowCubemap = GUILayout.Toggle(m_LookDevConfig.enableShadowCubemap, LookDevSettingsWindow.styles.sEnableShadowIcon, styles.sToolBarButton);
m_LookDevConfig.rotateObjectMode = GUILayout.Toggle(m_LookDevConfig.rotateObjectMode, LookDevSettingsWindow.styles.sEnableObjRotationIcon, styles.sToolBarButton);
m_LookDevConfig.rotateEnvMode = GUILayout.Toggle(m_LookDevConfig.rotateEnvMode, LookDevSettingsWindow.styles.sEnableEnvRotationIcon, styles.sToolBarButton);
GUILayout.FlexibleSpace();
if (m_ShowLookDevEnvWindow)
{
if (GUILayout.Button(m_SyncLightVertical, EditorStyles.toolbarButton))
{
Undo.RecordObject(m_LookDevEnvLibrary, "Synchronize lights");
int currentHDRIIndex = m_LookDevConfig.currentLookDevContext.currentHDRIIndex;
for (int i = 0; i < m_LookDevEnvLibrary.hdriList.Count; ++i)
{
// Get offset to apply to cubemap to align (offset will be -360..360, so can be apply directly on cubemap angleOffset).
// code in PositionToLatLong / LatLongToPosition ensure that we are 0..360 for longitude.
m_LookDevEnvLibrary.hdriList[i].angleOffset += (m_LookDevEnvLibrary.hdriList[currentHDRIIndex].shadowInfo.longitude + m_LookDevEnvLibrary.hdriList[currentHDRIIndex].angleOffset) - (m_LookDevEnvLibrary.hdriList[i].shadowInfo.longitude + m_LookDevEnvLibrary.hdriList[i].angleOffset);
m_LookDevEnvLibrary.hdriList[i].angleOffset = (m_LookDevEnvLibrary.hdriList[i].angleOffset + 360.0f) % 360.0f;
}
m_LookDevEnvLibrary.dirty = true;
GUIUtility.ExitGUI();
}
if (GUILayout.Button(m_ResetEnvironment, EditorStyles.toolbarButton))
{
Undo.RecordObject(m_LookDevEnvLibrary, "Reset environment");
for (int i = 0; i < m_LookDevEnvLibrary.hdriList.Count; ++i)
{
m_LookDevEnvLibrary.hdriList[i].angleOffset = 0;
}
m_LookDevEnvLibrary.dirty = true;
GUIUtility.ExitGUI();
}
}
if (RenderDoc.IsLoaded())
{
using (new EditorGUI.DisabledScope(!RenderDoc.IsSupported()))
{
if (GUILayout.Button(m_RenderdocContent, EditorStyles.toolbarButton))
{
m_CaptureRD = true;
GUIUtility.ExitGUI();
}