RenderFeatureEditor.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace ShinySSRR {
  4. [CustomEditor(typeof(ShinySSRR))]
  5. public class RenderFeatureEditor : Editor {
  6. SerializedProperty useDeferred, renderPassEvent, showInSceneView;
  7. SerializedProperty reflectionsMultiplier, reflectionsMinIntensity, reflectionsMaxIntensity;
  8. SerializedProperty downsampling, depthBias, outputMode, separationPos, lowPrecision, stopNaN;
  9. SerializedProperty sampleCount, maxRayLength, thickness, binarySearchIterations, refineThickness, thicknessFine, decay, jitter, animatedJitter;
  10. SerializedProperty fresnel, fuzzyness, contactHardening, minimumBlur;
  11. SerializedProperty blurDownsampling, blurStrength, specularControl, specularSoftenPower, vignetteSize;
  12. Reflections[] reflections;
  13. public Texture bulbOnIcon, bulbOffIcon, deleteIcon, arrowRight;
  14. private void OnEnable() {
  15. renderPassEvent = serializedObject.FindProperty("renderPassEvent");
  16. useDeferred = serializedObject.FindProperty("useDeferred");
  17. showInSceneView = serializedObject.FindProperty("showInSceneView");
  18. reflectionsMultiplier = serializedObject.FindProperty("reflectionsMultiplier");
  19. reflectionsMinIntensity = serializedObject.FindProperty("reflectionsMinIntensity");
  20. reflectionsMaxIntensity = serializedObject.FindProperty("reflectionsMaxIntensity");
  21. downsampling = serializedObject.FindProperty("downsampling");
  22. depthBias = serializedObject.FindProperty("depthBias");
  23. outputMode = serializedObject.FindProperty("outputMode");
  24. separationPos = serializedObject.FindProperty("separationPos");
  25. lowPrecision = serializedObject.FindProperty("lowPrecision");
  26. stopNaN = serializedObject.FindProperty("stopNaN");
  27. sampleCount = serializedObject.FindProperty("sampleCount");
  28. maxRayLength = serializedObject.FindProperty("maxRayLength");
  29. binarySearchIterations = serializedObject.FindProperty("binarySearchIterations");
  30. thickness = serializedObject.FindProperty("thickness");
  31. thicknessFine = serializedObject.FindProperty("thicknessFine");
  32. refineThickness = serializedObject.FindProperty("refineThickness");
  33. decay = serializedObject.FindProperty("decay");
  34. fresnel = serializedObject.FindProperty("fresnel");
  35. fuzzyness = serializedObject.FindProperty("fuzzyness");
  36. contactHardening = serializedObject.FindProperty("contactHardening");
  37. minimumBlur = serializedObject.FindProperty("minimumBlur");
  38. jitter = serializedObject.FindProperty("jitter");
  39. animatedJitter = serializedObject.FindProperty("animatedJitter");
  40. blurDownsampling = serializedObject.FindProperty("blurDownsampling");
  41. blurStrength = serializedObject.FindProperty("blurStrength");
  42. specularControl = serializedObject.FindProperty("specularControl");
  43. specularSoftenPower = serializedObject.FindProperty("specularSoftenPower");
  44. vignetteSize = serializedObject.FindProperty("vignetteSize");
  45. #if UNITY_2020_1_OR_NEWER
  46. reflections = FindObjectsOfType<Reflections>(true);
  47. #else
  48. reflections = FindObjectsOfType<Reflections>();
  49. #endif
  50. }
  51. public override void OnInspectorGUI() {
  52. int reflectionsCount = reflections != null ? reflections.Length : 0;
  53. EditorGUILayout.PropertyField(useDeferred);
  54. EditorGUILayout.PropertyField(renderPassEvent);
  55. EditorGUILayout.PropertyField(showInSceneView);
  56. EditorGUILayout.PropertyField(downsampling);
  57. if (downsampling.intValue > 1 && !useDeferred.boolValue) {
  58. EditorGUI.indentLevel++;
  59. EditorGUILayout.PropertyField(depthBias);
  60. EditorGUI.indentLevel--;
  61. }
  62. EditorGUILayout.PropertyField(outputMode);
  63. if (outputMode.intValue == (int)OutputMode.SideBySideComparison) {
  64. EditorGUI.indentLevel++;
  65. EditorGUILayout.PropertyField(separationPos);
  66. EditorGUI.indentLevel--;
  67. }
  68. EditorGUILayout.PropertyField(lowPrecision);
  69. EditorGUILayout.PropertyField(stopNaN, new GUIContent("Stop NaN"));
  70. EditorGUILayout.Separator();
  71. EditorGUILayout.LabelField("Raytracing Settings", EditorStyles.boldLabel);
  72. EditorGUILayout.BeginHorizontal();
  73. EditorGUILayout.LabelField("Apply Quality Preset:", GUILayout.Width(EditorGUIUtility.labelWidth));
  74. ShinySSRR ssr = (ShinySSRR)target;
  75. if (GUILayout.Button("Fast")) {
  76. ssr.ApplyRaytracingPreset(RaytracingPreset.Fast);
  77. }
  78. if (GUILayout.Button("Medium")) {
  79. ssr.ApplyRaytracingPreset(RaytracingPreset.Medium);
  80. }
  81. if (GUILayout.Button("High")) {
  82. ssr.ApplyRaytracingPreset(RaytracingPreset.High);
  83. }
  84. if (GUILayout.Button("Superb")) {
  85. ssr.ApplyRaytracingPreset(RaytracingPreset.Superb);
  86. }
  87. if (GUILayout.Button("Ultra")) {
  88. ssr.ApplyRaytracingPreset(RaytracingPreset.Ultra);
  89. }
  90. EditorGUILayout.EndHorizontal();
  91. EditorGUILayout.PropertyField(sampleCount);
  92. EditorGUILayout.PropertyField(maxRayLength);
  93. EditorGUILayout.PropertyField(thickness);
  94. EditorGUILayout.PropertyField(binarySearchIterations);
  95. EditorGUILayout.PropertyField(refineThickness);
  96. if (refineThickness.boolValue) {
  97. EditorGUILayout.PropertyField(thicknessFine);
  98. }
  99. EditorGUILayout.PropertyField(jitter);
  100. EditorGUILayout.PropertyField(animatedJitter);
  101. EditorGUILayout.PropertyField(reflectionsMultiplier, new GUIContent("Global Multiplier"));
  102. EditorGUILayout.PropertyField(reflectionsMinIntensity, new GUIContent("Min Intensity"));
  103. EditorGUILayout.PropertyField(reflectionsMaxIntensity, new GUIContent("Max Intensity"));
  104. EditorGUILayout.PropertyField(fresnel);
  105. EditorGUILayout.PropertyField(decay);
  106. EditorGUILayout.PropertyField(specularControl);
  107. if (specularControl.boolValue) {
  108. EditorGUILayout.PropertyField(specularSoftenPower);
  109. }
  110. EditorGUILayout.PropertyField(vignetteSize);
  111. EditorGUILayout.PropertyField(fuzzyness, new GUIContent("Fuzziness"));
  112. EditorGUILayout.PropertyField(contactHardening);
  113. EditorGUILayout.PropertyField(minimumBlur);
  114. EditorGUILayout.PropertyField(blurDownsampling);
  115. EditorGUILayout.PropertyField(blurStrength);
  116. if (reflectionsCount > 0) {
  117. if (!ShinySSRR.isDeferredActive) {
  118. EditorGUILayout.HelpBox("Some settings may be overriden by Reflections scripts on specific objects.", MessageType.Info);
  119. }
  120. EditorGUILayout.Separator();
  121. EditorGUILayout.LabelField("Reflections scripts in Scene", EditorStyles.helpBox);
  122. if (ShinySSRR.isDeferredActive) {
  123. EditorGUILayout.HelpBox("In deferred rendering path, only global SSR settings are used.", MessageType.Warning);
  124. }
  125. for (int k = 0; k < reflectionsCount; k++) {
  126. Reflections refl = reflections[k];
  127. if (refl == null) continue;
  128. EditorGUILayout.BeginHorizontal();
  129. GUI.enabled = refl.gameObject.activeInHierarchy;
  130. if (GUILayout.Button(new GUIContent(refl.enabled ? bulbOnIcon : bulbOffIcon, "Toggle on/off this reflection"), EditorStyles.miniButton, GUILayout.Width(35))) {
  131. refl.enabled = !refl.enabled;
  132. }
  133. GUI.enabled = true;
  134. if (GUILayout.Button(new GUIContent(deleteIcon, "Remove this reflection script"), EditorStyles.miniButton, GUILayout.Width(35))) {
  135. if (EditorUtility.DisplayDialog("Confirmation", "Remove the reflection script on " + refl.gameObject.name + "?", "Ok", "Cancel")) {
  136. DestroyImmediate(refl);
  137. reflections[k] = null;
  138. continue;
  139. }
  140. }
  141. if (GUILayout.Button(new GUIContent(arrowRight, "Select this reflection script"), EditorStyles.miniButton, GUILayout.Width(35), GUILayout.Width(40))) {
  142. Selection.activeObject = refl.gameObject;
  143. EditorGUIUtility.PingObject(refl.gameObject);
  144. GUIUtility.ExitGUI();
  145. }
  146. GUI.enabled = refl.isActiveAndEnabled;
  147. if (!refl.gameObject.activeInHierarchy) {
  148. GUILayout.Label(refl.name + " (hidden gameobject)");
  149. } else {
  150. GUILayout.Label(refl.name);
  151. }
  152. GUI.enabled = true;
  153. EditorGUILayout.EndHorizontal();
  154. }
  155. } else if (reflectionsCount == 0) {
  156. if (!ShinySSRR.isDeferredActive) {
  157. EditorGUILayout.Separator();
  158. EditorGUILayout.LabelField("Reflections in Scene", EditorStyles.helpBox);
  159. EditorGUILayout.HelpBox("In forward rendering path, add a Reflections script to any object or group of objects that you want to get reflections.", MessageType.Info);
  160. }
  161. }
  162. }
  163. }
  164. }