@@ -63,12 +63,18 @@ static class Styles
63
63
public static readonly GUIContent GINotEnabledInfo = EditorGUIUtility . TrTextContent ( "Lightmapping settings are currently disabled. Enable Baked Global Illumination or Realtime Global Illumination to display these settings." ) ;
64
64
public static readonly GUIContent CastShadowsProgressiveGPUWarning = EditorGUIUtility . TrTextContent ( "Cast Shadows is forced to 'On' when using the GPU lightmapper (Preview), it will be supported in a later version. Use the CPU lightmapper instead if you need this functionality." ) ;
65
65
public static readonly GUIContent ReceiveShadowsProgressiveGPUWarning = EditorGUIUtility . TrTextContent ( "Receive Shadows is forced to 'On' when using the GPU lightmapper (Preview), it will be supported in a later version. Use the CPU lightmapper instead if you need this functionality." ) ;
66
+ public static readonly GUIContent OpenPreview = EditorGUIUtility . TrTextContent ( "Open Preview" ) ;
67
+
68
+ public static readonly GUIStyle OpenPreviewStyle = EditorStyles . objectFieldThumb . name + "LightmapPreviewOverlay" ;
69
+
70
+ public static readonly int PreviewPadding = 30 ;
71
+ public static readonly int PreviewWidth = 104 ;
66
72
}
67
73
68
74
bool m_ShowChartingSettings = true ;
69
75
bool m_ShowLightmapSettings = true ;
70
- bool m_ShowBakedLM = false ;
71
- bool m_ShowRealtimeLM = false ;
76
+ bool m_ShowBakedLM = true ;
77
+ bool m_ShowRealtimeLM = true ;
72
78
73
79
SerializedObject m_SerializedObject ;
74
80
SerializedObject m_GameObjectsSerializedObject ;
@@ -240,13 +246,8 @@ public void RenderMeshSettings(bool showLightmapSettings)
240
246
{
241
247
EditorGUI . indentLevel += 1 ;
242
248
243
- m_ShowBakedLM = EditorGUILayout . Foldout ( m_ShowBakedLM , Styles . Atlas , true ) ;
244
- if ( m_ShowBakedLM )
245
- ShowAtlasGUI ( m_Renderers [ 0 ] . GetInstanceID ( ) ) ;
246
-
247
- m_ShowRealtimeLM = EditorGUILayout . Foldout ( m_ShowRealtimeLM , Styles . RealtimeLM , true ) ;
248
- if ( m_ShowRealtimeLM )
249
- ShowRealtimeLMGUI ( m_Renderers [ 0 ] ) ;
249
+ ShowAtlasGUI ( m_Renderers [ 0 ] . GetInstanceID ( ) ) ;
250
+ ShowRealtimeLMGUI ( m_Renderers [ 0 ] ) ;
250
251
251
252
EditorGUI . indentLevel -= 1 ;
252
253
}
@@ -312,13 +313,8 @@ public void RenderTerrainSettings()
312
313
if ( GUI . enabled && m_Terrains . Length == 1 && m_Terrains [ 0 ] . terrainData != null )
313
314
ShowBakePerformanceWarning ( m_Terrains [ 0 ] ) ;
314
315
315
- m_ShowBakedLM = EditorGUILayout . Foldout ( m_ShowBakedLM , Styles . Atlas , true ) ;
316
- if ( m_ShowBakedLM )
317
- ShowAtlasGUI ( m_Terrains [ 0 ] . GetInstanceID ( ) ) ;
318
-
319
- m_ShowRealtimeLM = EditorGUILayout . Foldout ( m_ShowRealtimeLM , Styles . RealtimeLM , true ) ;
320
- if ( m_ShowRealtimeLM )
321
- ShowRealtimeLMGUI ( m_Terrains [ 0 ] ) ;
316
+ ShowAtlasGUI ( m_Terrains [ 0 ] . GetInstanceID ( ) ) ;
317
+ ShowRealtimeLMGUI ( m_Terrains [ 0 ] ) ;
322
318
323
319
m_SerializedObject . ApplyModifiedProperties ( ) ;
324
320
}
@@ -413,44 +409,29 @@ void ShowAtlasGUI(int instanceID)
413
409
if ( m_CachedBakedTexture . texture == null )
414
410
return ;
415
411
416
- EditorGUI . indentLevel += 1 ;
412
+ m_ShowBakedLM = EditorGUILayout . Foldout ( m_ShowBakedLM , Styles . Atlas , true ) ;
417
413
418
- GUILayout . BeginHorizontal ( ) ;
419
- GUILayout . Space ( 30 ) ;
420
-
421
- Rect rect = GUILayoutUtility . GetRect ( 100 , 100 , EditorStyles . objectField ) ;
414
+ if ( ! m_ShowBakedLM )
415
+ return ;
422
416
423
- EditorGUI . Toggle ( rect , false , EditorStyles . objectFieldThumb ) ;
417
+ EditorGUI . indentLevel += 1 ;
424
418
425
- if ( rect . Contains ( Event . current . mousePosition ) )
426
- {
427
- Object actualTargetObject = m_CachedBakedTexture . texture ;
428
- Component com = actualTargetObject as Component ;
419
+ GUILayout . BeginHorizontal ( ) ;
429
420
430
- if ( com )
431
- actualTargetObject = com . gameObject ;
421
+ DrawLightmapPreview ( m_CachedBakedTexture . texture , false , instanceID ) ;
432
422
433
- if ( Event . current . clickCount == 2 )
434
- LightmapPreviewWindow . CreateLightmapPreviewWindow ( m_Renderers [ 0 ] . GetInstanceID ( ) , false , false ) ;
435
- else if ( Event . current . clickCount == 1 )
436
- EditorGUI . PingObjectOrShowPreviewOnClick ( actualTargetObject , GUILayoutUtility . GetLastRect ( ) ) ;
437
- }
423
+ GUILayout . BeginVertical ( ) ;
438
424
439
- if ( Event . current . type == EventType . Repaint )
440
- {
441
- rect = EditorStyles . objectFieldThumb . padding . Remove ( rect ) ;
442
- EditorGUI . DrawPreviewTexture ( rect , m_CachedBakedTexture . texture ) ;
443
- }
425
+ GUILayout . Label ( Styles . AtlasIndex . text + ": " + m_LightmapIndex . intValue . ToString ( ) ) ;
426
+ GUILayout . Label ( Styles . AtlasTilingX . text + ": " + m_LightmapTilingOffsetX . floatValue . ToString ( ) ) ;
427
+ GUILayout . Label ( Styles . AtlasTilingY . text + ": " + m_LightmapTilingOffsetY . floatValue . ToString ( ) ) ;
428
+ GUILayout . Label ( Styles . AtlasOffsetX . text + ": " + m_LightmapTilingOffsetZ . floatValue . ToString ( ) ) ;
429
+ GUILayout . Label ( Styles . AtlasOffsetY . text + ": " + m_LightmapTilingOffsetW . floatValue . ToString ( ) ) ;
444
430
431
+ GUILayout . EndVertical ( ) ;
445
432
GUILayout . FlexibleSpace ( ) ;
446
433
GUILayout . EndHorizontal ( ) ;
447
434
448
- EditorGUILayout . LabelField ( Styles . AtlasIndex , GUIContent . Temp ( m_LightmapIndex . intValue . ToString ( ) ) ) ;
449
- EditorGUILayout . LabelField ( Styles . AtlasTilingX , GUIContent . Temp ( m_LightmapTilingOffsetX . floatValue . ToString ( ) ) ) ;
450
- EditorGUILayout . LabelField ( Styles . AtlasTilingY , GUIContent . Temp ( m_LightmapTilingOffsetY . floatValue . ToString ( ) ) ) ;
451
- EditorGUILayout . LabelField ( Styles . AtlasOffsetX , GUIContent . Temp ( m_LightmapTilingOffsetZ . floatValue . ToString ( ) ) ) ;
452
- EditorGUILayout . LabelField ( Styles . AtlasOffsetY , GUIContent . Temp ( m_LightmapTilingOffsetW . floatValue . ToString ( ) ) ) ;
453
-
454
435
bool showProgressiveInfo = isPrefabAsset || ( m_EnabledBakedGI . boolValue && LightmapEditorSettings . lightmapper != LightmapEditorSettings . Lightmapper . Enlighten ) ;
455
436
456
437
if ( showProgressiveInfo && Unsupported . IsDeveloperMode ( ) )
@@ -467,19 +448,32 @@ void ShowAtlasGUI(int instanceID)
467
448
LightmapEditorSettings . GetPVRAtlasInstanceOffset ( instanceID , out atlasInstanceOffset ) ;
468
449
EditorGUILayout . LabelField ( Styles . PVRAtlasInstanceOffset , GUIContent . Temp ( atlasInstanceOffset . ToString ( ) ) ) ;
469
450
}
470
-
471
451
EditorGUI . indentLevel -= 1 ;
452
+
453
+ GUILayout . Space ( 5 ) ;
472
454
}
473
455
474
456
void ShowRealtimeLMGUI ( Terrain terrain )
475
457
{
458
+ Hash128 inputSystemHash ;
459
+ if ( terrain == null || ! LightmapEditorSettings . GetInputSystemHash ( terrain . GetInstanceID ( ) , out inputSystemHash ) || inputSystemHash == new Hash128 ( ) )
460
+ return ; // early return since we don't have any lightmaps for it
461
+
462
+ if ( ! UpdateRealtimeTexture ( inputSystemHash , terrain . GetInstanceID ( ) ) )
463
+ return ;
464
+
465
+ m_ShowRealtimeLM = EditorGUILayout . Foldout ( m_ShowRealtimeLM , Styles . RealtimeLM , true ) ;
466
+
467
+ if ( ! m_ShowRealtimeLM )
468
+ return ;
469
+
476
470
EditorGUI . indentLevel += 1 ;
477
471
478
- Hash128 inputSystemHash ;
479
- if ( terrain != null && LightmapEditorSettings . GetInputSystemHash ( terrain . GetInstanceID ( ) , out inputSystemHash ) )
480
- {
481
- ShowRealtimeLightmapPreview ( inputSystemHash ) ;
482
- }
472
+ GUILayout . BeginHorizontal ( ) ;
473
+
474
+ DrawLightmapPreview ( m_CachedRealtimeTexture . texture , true , terrain . GetInstanceID ( ) ) ;
475
+
476
+ GUILayout . BeginVertical ( ) ;
483
477
484
478
// Resolution of the system.
485
479
int width , height ;
@@ -489,34 +483,56 @@ void ShowRealtimeLMGUI(Terrain terrain)
489
483
var str = width . ToString ( ) + "x" + height . ToString ( ) ;
490
484
if ( numChunksInX > 1 || numChunksInY > 1 )
491
485
str += string . Format ( " ({0}x{1} chunks)" , numChunksInX , numChunksInY ) ;
492
- EditorGUILayout . LabelField ( Styles . RealtimeLMResolution , GUIContent . Temp ( str ) ) ;
486
+ GUILayout . Label ( Styles . RealtimeLMResolution . text + ": " + str ) ;
493
487
}
494
488
489
+ GUILayout . EndVertical ( ) ;
490
+ GUILayout . FlexibleSpace ( ) ;
491
+ GUILayout . EndHorizontal ( ) ;
492
+
495
493
EditorGUI . indentLevel -= 1 ;
494
+
495
+ GUILayout . Space ( 5 ) ;
496
496
}
497
497
498
498
void ShowRealtimeLMGUI ( Renderer renderer )
499
499
{
500
+ Hash128 inputSystemHash ;
501
+ if ( renderer == null || ! LightmapEditorSettings . GetInputSystemHash ( renderer . GetInstanceID ( ) , out inputSystemHash ) || inputSystemHash == new Hash128 ( ) )
502
+ return ; // early return since we don't have any lightmaps for it
503
+
504
+ if ( ! UpdateRealtimeTexture ( inputSystemHash , renderer . GetInstanceID ( ) ) )
505
+ return ;
506
+
507
+ m_ShowRealtimeLM = EditorGUILayout . Foldout ( m_ShowRealtimeLM , Styles . RealtimeLM , true ) ;
508
+
509
+ if ( ! m_ShowRealtimeLM )
510
+ return ;
511
+
500
512
EditorGUI . indentLevel += 1 ;
501
513
502
- Hash128 inputSystemHash = new Hash128 ( ) ;
503
- if ( renderer != null && LightmapEditorSettings . GetInputSystemHash ( renderer . GetInstanceID ( ) , out inputSystemHash ) )
504
- {
505
- ShowRealtimeLightmapPreview ( inputSystemHash ) ;
506
- }
514
+ GUILayout . BeginHorizontal ( ) ;
515
+
516
+ DrawLightmapPreview ( m_CachedRealtimeTexture . texture , true , renderer . GetInstanceID ( ) ) ;
517
+
518
+ GUILayout . BeginVertical ( ) ;
507
519
508
520
int instWidth , instHeight ;
509
521
if ( LightmapEditorSettings . GetInstanceResolution ( renderer , out instWidth , out instHeight ) )
510
522
{
511
- EditorGUILayout . LabelField ( Styles . RealtimeLMInstanceResolution , GUIContent . Temp ( instWidth . ToString ( ) + "x" + instHeight . ToString ( ) ) ) ;
523
+ GUILayout . Label ( Styles . RealtimeLMInstanceResolution . text + ": " + instWidth . ToString ( ) + "x" + instHeight . ToString ( ) ) ;
512
524
}
513
525
514
526
int width , height ;
515
527
if ( LightmapEditorSettings . GetSystemResolution ( renderer , out width , out height ) )
516
528
{
517
- EditorGUILayout . LabelField ( Styles . RealtimeLMResolution , GUIContent . Temp ( width . ToString ( ) + "x" + height . ToString ( ) ) ) ;
529
+ GUILayout . Label ( Styles . RealtimeLMResolution . text + ": " + width . ToString ( ) + "x" + height . ToString ( ) ) ;
518
530
}
519
531
532
+ GUILayout . EndVertical ( ) ;
533
+ GUILayout . FlexibleSpace ( ) ;
534
+ GUILayout . EndHorizontal ( ) ;
535
+
520
536
if ( Unsupported . IsDeveloperMode ( ) )
521
537
{
522
538
Hash128 instanceHash ;
@@ -535,12 +551,14 @@ void ShowRealtimeLMGUI(Renderer renderer)
535
551
}
536
552
537
553
EditorGUI . indentLevel -= 1 ;
554
+
555
+ GUILayout . Space ( 5 ) ;
538
556
}
539
557
540
- void ShowRealtimeLightmapPreview ( Hash128 inputSystemHash )
558
+ bool UpdateRealtimeTexture ( Hash128 inputSystemHash , int instanceId )
541
559
{
542
560
if ( inputSystemHash == new Hash128 ( ) )
543
- return ;
561
+ return false ;
544
562
545
563
Hash128 contentHash = LightmapVisualizationUtility . GetRealtimeGITextureHash ( inputSystemHash , GITextureType . Irradiance ) ;
546
564
@@ -549,35 +567,51 @@ void ShowRealtimeLightmapPreview(Hash128 inputSystemHash)
549
567
m_CachedRealtimeTexture = LightmapVisualizationUtility . GetRealtimeGITexture ( inputSystemHash , GITextureType . Irradiance ) ;
550
568
551
569
if ( m_CachedRealtimeTexture . texture == null )
552
- return ;
570
+ return false ;
553
571
554
- GUILayout . BeginHorizontal ( ) ;
555
- GUILayout . Space ( 30 ) ;
572
+ return true ;
573
+ }
556
574
557
- Rect rect = GUILayoutUtility . GetRect ( 100 , 100 , EditorStyles . objectField ) ;
575
+ private void DrawLightmapPreview ( Texture2D texture , bool realtimeLightmap , int instanceId )
576
+ {
577
+ GUILayout . Space ( Styles . PreviewPadding ) ;
558
578
559
- EditorGUI . Toggle ( rect , false , EditorStyles . objectFieldThumb ) ;
579
+ int previewWidth = Styles . PreviewWidth - 4 ; // padding
560
580
561
- if ( rect . Contains ( Event . current . mousePosition ) )
581
+ Rect rect = GUILayoutUtility . GetRect ( previewWidth , previewWidth , EditorStyles . objectField ) ;
582
+ Rect buttonRect = new Rect ( rect . xMax - 70 , rect . yMax - 14 , 70 , 14 ) ;
583
+
584
+ if ( Event . current . type == EventType . MouseDown )
562
585
{
563
- Object actualTargetObject = m_CachedRealtimeTexture . texture ;
564
- Component com = actualTargetObject as Component ;
586
+ if ( ( buttonRect . Contains ( Event . current . mousePosition ) && Event . current . clickCount == 1 ) ||
587
+ ( rect . Contains ( Event . current . mousePosition ) && Event . current . clickCount == 2 ) )
588
+ {
589
+ LightmapPreviewWindow . CreateLightmapPreviewWindow ( instanceId , realtimeLightmap , false ) ;
590
+ }
591
+ else if ( rect . Contains ( Event . current . mousePosition ) && Event . current . clickCount == 1 )
592
+ {
593
+ Object actualTargetObject = texture ;
594
+ Component com = actualTargetObject as Component ;
565
595
566
- if ( com )
567
- actualTargetObject = com . gameObject ;
596
+ if ( com )
597
+ actualTargetObject = com . gameObject ;
568
598
569
- if ( Event . current . clickCount == 2 )
570
- LightmapPreviewWindow . CreateLightmapPreviewWindow ( m_Renderers [ 0 ] . GetInstanceID ( ) , true , false ) ;
599
+ EditorGUI . PingObjectOrShowPreviewOnClick ( actualTargetObject , rect ) ;
600
+ }
571
601
}
572
602
603
+ EditorGUI . Toggle ( rect , false , EditorStyles . objectFieldThumb ) ;
604
+
573
605
if ( Event . current . type == EventType . Repaint )
574
606
{
575
607
rect = EditorStyles . objectFieldThumb . padding . Remove ( rect ) ;
576
- EditorGUI . DrawPreviewTexture ( rect , m_CachedRealtimeTexture . texture ) ;
608
+ EditorGUI . DrawPreviewTexture ( rect , texture ) ;
609
+
610
+ Styles . OpenPreviewStyle . Draw ( rect , Styles . OpenPreview , false , false , false , false ) ;
577
611
}
578
612
579
- GUILayout . FlexibleSpace ( ) ;
580
- GUILayout . EndHorizontal ( ) ;
613
+ float spacing = Mathf . Max ( 5.0f , EditorGUIUtility . labelWidth - Styles . PreviewPadding - Styles . PreviewWidth ) ;
614
+ GUILayout . Space ( spacing ) ;
581
615
}
582
616
583
617
static bool HasNormals ( Renderer renderer )
0 commit comments