No Description
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.

ShaderGraphLitGUI.cs 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using UnityEditor.Rendering.Universal;
  3. using UnityEditor.Rendering.Universal.ShaderGUI;
  4. using UnityEngine;
  5. using static Unity.Rendering.Universal.ShaderUtils;
  6. namespace UnityEditor
  7. {
  8. // Used for ShaderGraph Lit shaders
  9. class ShaderGraphLitGUI : BaseShaderGUI
  10. {
  11. public MaterialProperty workflowMode;
  12. MaterialProperty[] properties;
  13. // collect properties from the material properties
  14. public override void FindProperties(MaterialProperty[] properties)
  15. {
  16. // save off the list of all properties for shadergraph
  17. this.properties = properties;
  18. var material = materialEditor?.target as Material;
  19. if (material == null)
  20. return;
  21. base.FindProperties(properties);
  22. workflowMode = BaseShaderGUI.FindProperty(Property.SpecularWorkflowMode, properties, false);
  23. }
  24. public static void UpdateMaterial(Material material, MaterialUpdateType updateType)
  25. {
  26. // newly created materials should initialize the globalIlluminationFlags (default is off)
  27. if (updateType == MaterialUpdateType.CreatedNewMaterial)
  28. material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
  29. bool automaticRenderQueue = GetAutomaticQueueControlSetting(material);
  30. BaseShaderGUI.UpdateMaterialSurfaceOptions(material, automaticRenderQueue);
  31. LitGUI.SetupSpecularWorkflowKeyword(material, out bool isSpecularWorkflow);
  32. BaseShaderGUI.UpdateMotionVectorKeywordsAndPass(material);
  33. }
  34. public override void ValidateMaterial(Material material)
  35. {
  36. if (material == null)
  37. throw new ArgumentNullException("material");
  38. UpdateMaterial(material, MaterialUpdateType.ModifiedMaterial);
  39. }
  40. public override void DrawSurfaceOptions(Material material)
  41. {
  42. if (material == null)
  43. throw new ArgumentNullException("material");
  44. // Use default labelWidth
  45. EditorGUIUtility.labelWidth = 0f;
  46. // Detect any changes to the material
  47. if (workflowMode != null)
  48. DoPopup(LitGUI.Styles.workflowModeText, workflowMode, Enum.GetNames(typeof(LitGUI.WorkflowMode)));
  49. base.DrawSurfaceOptions(material);
  50. }
  51. // material main surface inputs
  52. public override void DrawSurfaceInputs(Material material)
  53. {
  54. DrawShaderGraphProperties(material, properties);
  55. }
  56. public override void DrawAdvancedOptions(Material material)
  57. {
  58. // Always show the queue control field. Only show the render queue field if queue control is set to user override
  59. DoPopup(Styles.queueControl, queueControlProp, Styles.queueControlNames);
  60. if (material.HasProperty(Property.QueueControl) && material.GetFloat(Property.QueueControl) == (float)QueueControl.UserOverride)
  61. materialEditor.RenderQueueField();
  62. base.DrawAdvancedOptions(material);
  63. // ignore emission color for shadergraphs, because shadergraphs don't have a hard-coded emission property, it's up to the user
  64. materialEditor.DoubleSidedGIField();
  65. materialEditor.LightmapEmissionFlagsProperty(0, enabled: true, ignoreEmissionColor: true);
  66. }
  67. }
  68. } // namespace UnityEditor