Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
5.8 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. //#define ASE_CONSOLE_WINDOW
  4. using UnityEngine;
  5. using UnityEditor;
  6. using System.Collections.Generic;
  7. namespace AmplifyShaderEditor
  8. {
  9. public sealed class DebugConsoleWindow : EditorWindow
  10. {
  11. private const float WindowSizeX = 250;
  12. private const float WindowSizeY = 250;
  13. private const float WindowPosX = 5;
  14. private const float WindowPosY = 5;
  15. private Rect m_availableArea;
  16. private bool m_wikiAreaFoldout = true;
  17. private bool m_miscAreaFoldout = true;
  18. private Vector2 m_currentScrollPos;
  19. private int m_minURLNode = 0;
  20. private int m_maxURLNode = -1;
  21. #if ASE_CONSOLE_WINDOW
  22. public readonly static bool DeveloperMode = true;
  23. public static bool UseShaderPanelsInfo = true;
  24. [MenuItem( "Window/Amplify Shader Editor/Open Debug Console" )]
  25. static void OpenMainShaderGraph()
  26. {
  27. OpenWindow();
  28. }
  29. [MenuItem( "Window/Amplify Shader Editor/Create Template Menu Items" )]
  30. public static void CreateTemplateMenuItems()
  31. {
  32. UIUtils.CurrentWindow.TemplatesManagerInstance.CreateTemplateMenuItems();
  33. }
  34. #else
  35. public readonly static bool DeveloperMode = false;
  36. public static bool UseShaderPanelsInfo = false;
  37. #endif
  38. public static DebugConsoleWindow OpenWindow()
  39. {
  40. if ( DeveloperMode )
  41. {
  42. DebugConsoleWindow currentWindow = ( DebugConsoleWindow ) DebugConsoleWindow.GetWindow( typeof( DebugConsoleWindow ), false, "ASE Debug Console" );
  43. currentWindow.titleContent.tooltip = "Debug Options for ASE. Intented only for ASE development team";
  44. currentWindow.minSize = new Vector2( WindowSizeX, WindowSizeY );
  45. currentWindow.maxSize = new Vector2( WindowSizeX, 2 * WindowSizeY ); ;
  46. currentWindow.wantsMouseMove = true;
  47. return currentWindow;
  48. }
  49. return null;
  50. }
  51. void OnGUI()
  52. {
  53. m_availableArea = new Rect( WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY );
  54. GUILayout.BeginArea( m_availableArea );
  55. {
  56. m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
  57. {
  58. EditorGUILayout.BeginVertical();
  59. {
  60. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  61. if ( window != null )
  62. {
  63. EditorGUILayout.Separator();
  64. NodeUtils.DrawPropertyGroup( ref m_wikiAreaFoldout, "Wiki Helper", ShowWikiHelperFunctions );
  65. EditorGUILayout.Separator();
  66. NodeUtils.DrawPropertyGroup( ref m_miscAreaFoldout, "Misc", ShowMiscFuntions );
  67. EditorGUILayout.Separator();
  68. }
  69. else
  70. {
  71. EditorGUILayout.LabelField( "Please open an ASE window to access debug options" );
  72. }
  73. }
  74. EditorGUILayout.EndVertical();
  75. }
  76. EditorGUILayout.EndScrollView();
  77. }
  78. GUILayout.EndArea();
  79. }
  80. void ShowWikiHelperFunctions()
  81. {
  82. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  83. EditorGUILayout.Separator();
  84. if ( GUILayout.Button( "Nodes Screen Shots" ) )
  85. {
  86. window.CurrentNodeExporterUtils.ActivateAutoScreenShot( Application.dataPath + "/../NodesInfo/Shots/",0,-1 );
  87. }
  88. GUILayout.BeginHorizontal();
  89. if( GUILayout.Button( "Nodes URLs" ) )
  90. {
  91. window.CurrentNodeExporterUtils.ActivateNodesURL( m_minURLNode, m_maxURLNode );
  92. }
  93. m_minURLNode = EditorGUILayout.IntField( m_minURLNode );
  94. m_maxURLNode = EditorGUILayout.IntField( m_maxURLNode );
  95. GUILayout.EndHorizontal();
  96. EditorGUILayout.Separator();
  97. if( GUILayout.Button( "Nodes Undo Test" ) )
  98. {
  99. window.CurrentNodeExporterUtils.ActivateAutoUndo();
  100. }
  101. EditorGUILayout.Separator();
  102. if ( GUILayout.Button( "Nodes Info" ) )
  103. {
  104. window.CurrentPaletteWindow.DumpAvailableNodes( false, Application.dataPath + "/../NodesInfo/" );
  105. window.CurrentPaletteWindow.DumpAvailableNodes( true, Application.dataPath + "/../NodesInfo/" );
  106. }
  107. EditorGUILayout.Separator();
  108. if ( GUILayout.Button( "Shortcuts Info" ) )
  109. {
  110. window.ShortcutManagerInstance.DumpShortcutsToDisk( Application.dataPath + "/../NodesInfo/" );
  111. }
  112. }
  113. void ShowMiscFuntions()
  114. {
  115. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  116. if ( GUILayout.Button( "Force Example Shader Compilation" ) )
  117. {
  118. UIUtils.ForceExampleShaderCompilation();
  119. }
  120. EditorGUILayout.Separator();
  121. if ( GUILayout.Button( "Refresh Available Nodes" ) )
  122. {
  123. window.RefreshAvaibleNodes();
  124. }
  125. EditorGUILayout.Separator();
  126. if ( GUILayout.Button( "Dump Uniform Names" ) )
  127. {
  128. //window.CurrentPaletteWindow.NewList()
  129. window.DuplicatePrevBufferInstance.DumpUniformNames();
  130. }
  131. EditorGUILayout.Separator();
  132. if ( GUILayout.Button( "Force Palette Update" ) )
  133. {
  134. Debug.Log( UIUtils.CurrentWindow.IsShaderFunctionWindow );
  135. window.CurrentPaletteWindow.ForceUpdate = true;
  136. }
  137. EditorGUILayout.Separator();
  138. if( GUILayout.Button( "Detect Infinite Loops" ) )
  139. {
  140. if( window.IsShaderFunctionWindow )
  141. {
  142. Debug.Log( "Starting infinite loop detection over shader functions" );
  143. List<FunctionOutput> nodes = window.OutsideGraph.FunctionOutputNodes.NodesList;
  144. for( int i = 0; i < nodes.Count; i++ )
  145. {
  146. UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
  147. }
  148. }
  149. else
  150. {
  151. if( window.OutsideGraph.MultiPassMasterNodes.Count > 0 )
  152. {
  153. Debug.Log( "Starting infinite loop detection over shader from template" );
  154. List<TemplateMultiPassMasterNode> nodes = window.OutsideGraph.MultiPassMasterNodes.NodesList;
  155. for( int i = 0; i < nodes.Count; i++ )
  156. {
  157. UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
  158. }
  159. }
  160. else
  161. {
  162. Debug.Log( "Starting infinite loop detection over standard shader" );
  163. UIUtils.DetectNodeLoopsFrom( window.OutsideGraph.CurrentMasterNode, new Dictionary<int, int>() );
  164. }
  165. }
  166. Debug.Log( "End infinite loop detection" );
  167. }
  168. }
  169. }
  170. }