1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using UnityEditor.Rendering.Universal;
- using UnityEditor.Rendering.Universal.ShaderGUI;
- using UnityEngine;
- using static Unity.Rendering.Universal.ShaderUtils;
-
- namespace UnityEditor
- {
- // Used for ShaderGraph Lit shaders
- class ShaderGraphLitGUI : BaseShaderGUI
- {
- public MaterialProperty workflowMode;
-
- MaterialProperty[] properties;
-
- // collect properties from the material properties
- public override void FindProperties(MaterialProperty[] properties)
- {
- // save off the list of all properties for shadergraph
- this.properties = properties;
-
- var material = materialEditor?.target as Material;
- if (material == null)
- return;
-
- base.FindProperties(properties);
- workflowMode = BaseShaderGUI.FindProperty(Property.SpecularWorkflowMode, properties, false);
- }
-
- public static void UpdateMaterial(Material material, MaterialUpdateType updateType)
- {
- // newly created materials should initialize the globalIlluminationFlags (default is off)
- if (updateType == MaterialUpdateType.CreatedNewMaterial)
- material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
-
- bool automaticRenderQueue = GetAutomaticQueueControlSetting(material);
- BaseShaderGUI.UpdateMaterialSurfaceOptions(material, automaticRenderQueue);
- LitGUI.SetupSpecularWorkflowKeyword(material, out bool isSpecularWorkflow);
- BaseShaderGUI.UpdateMotionVectorKeywordsAndPass(material);
- }
-
- public override void ValidateMaterial(Material material)
- {
- if (material == null)
- throw new ArgumentNullException("material");
-
- UpdateMaterial(material, MaterialUpdateType.ModifiedMaterial);
- }
-
- public override void DrawSurfaceOptions(Material material)
- {
- if (material == null)
- throw new ArgumentNullException("material");
-
- // Use default labelWidth
- EditorGUIUtility.labelWidth = 0f;
-
- // Detect any changes to the material
- if (workflowMode != null)
- DoPopup(LitGUI.Styles.workflowModeText, workflowMode, Enum.GetNames(typeof(LitGUI.WorkflowMode)));
- base.DrawSurfaceOptions(material);
- }
-
- // material main surface inputs
- public override void DrawSurfaceInputs(Material material)
- {
- DrawShaderGraphProperties(material, properties);
- }
-
- public override void DrawAdvancedOptions(Material material)
- {
- // Always show the queue control field. Only show the render queue field if queue control is set to user override
- DoPopup(Styles.queueControl, queueControlProp, Styles.queueControlNames);
- if (material.HasProperty(Property.QueueControl) && material.GetFloat(Property.QueueControl) == (float)QueueControl.UserOverride)
- materialEditor.RenderQueueField();
- base.DrawAdvancedOptions(material);
-
- // ignore emission color for shadergraphs, because shadergraphs don't have a hard-coded emission property, it's up to the user
- materialEditor.DoubleSidedGIField();
- materialEditor.LightmapEmissionFlagsProperty(0, enabled: true, ignoreEmissionColor: true);
- }
- }
- } // namespace UnityEditor
|