diff options
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants')
153 files changed, 12781 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs new file mode 100644 index 00000000..4321bc10 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs @@ -0,0 +1,506 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Color", "Constants And Properties", "Color property", null, KeyCode.Alpha5 )] + public sealed class ColorNode : PropertyNode + { + private const string ColorSpaceStr = "Color Space"; + + [SerializeField] +#if UNITY_2018_1_OR_NEWER + [ColorUsage( true, true )] +#else + [ColorUsage( true, true, float.MinValue, float.MinValue, float.MinValue, float.MaxValue )] +#endif + private Color m_defaultValue = new Color( 0, 0, 0, 0 ); + + [SerializeField] +#if UNITY_2018_1_OR_NEWER + [ColorUsage( true, true )] +#else + [ColorUsage( true, true, float.MinValue, float.MinValue, float.MinValue, float.MaxValue )] +#endif + private Color m_materialValue = new Color( 0, 0, 0, 0 ); + + [SerializeField] + private bool m_isHDR = false; + + //[SerializeField] + //private ASEColorSpace m_colorSpace = ASEColorSpace.Auto; +#if !UNITY_2018_1_OR_NEWER + private ColorPickerHDRConfig m_hdrConfig = new ColorPickerHDRConfig( 0, float.MaxValue, 0, float.MaxValue ); +#endif + private GUIContent m_dummyContent; + + private int m_cachedPropertyId = -1; + + private bool m_isEditingFields; + + [SerializeField] + private bool m_autoGammaToLinearConversion = true; + + private const string AutoGammaToLinearConversion = "IsGammaSpace() ? {0} : {1}"; + private const string AutoGammaToLinearStr = "Auto Gamma To Linear"; + + public ColorNode() : base() { } + public ColorNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Color" ); + m_insideSize.Set( 100, 50 ); + m_dummyContent = new GUIContent(); + AddOutputColorPorts( "RGBA" ); + m_drawPreview = false; + m_drawPreviewExpander = false; + m_canExpand = false; + m_showHybridInstancedUI = true; + m_selectedLocation = PreviewLocation.BottomCenter; + m_previewShaderGUID = "6cf365ccc7ae776488ae8960d6d134c3"; + m_srpBatcherCompatible = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputColor" ); + + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetColor( m_cachedPropertyId, m_materialValue ); + else + PreviewMaterial.SetColor( m_cachedPropertyId, m_defaultValue ); + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + m_textLabelWidth = ( m_currentParameterType == PropertyType.Constant ) ? 152 : 105; + +#if UNITY_2018_1_OR_NEWER + m_defaultValue = EditorGUILayoutColorField( Constants.DefaultValueLabelContent, m_defaultValue, false, true, m_isHDR ); +#else + m_defaultValue = EditorGUILayoutColorField( Constants.DefaultValueLabelContent, m_defaultValue, false, true, m_isHDR, m_hdrConfig ); +#endif + if( m_currentParameterType == PropertyType.Constant ) + { + + m_autoGammaToLinearConversion = EditorGUILayoutToggle( AutoGammaToLinearStr, m_autoGammaToLinearConversion ); + } + } + + //public override void DrawMainPropertyBlock() + //{ + // EditorGUILayout.BeginVertical(); + // { + + // PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType ); + // if( parameterType != m_currentParameterType ) + // { + // ChangeParameterType( parameterType ); + // BeginPropertyFromInspectorCheck(); + // } + + // switch( m_currentParameterType ) + // { + // case PropertyType.Property: + // case PropertyType.InstancedProperty: + // { + // ShowPropertyInspectorNameGUI(); + // ShowPropertyNameGUI( true ); + // ShowVariableMode(); + // ShowPrecision(); + // ShowToolbar(); + // } + // break; + // case PropertyType.Global: + // { + // ShowPropertyInspectorNameGUI(); + // ShowPropertyNameGUI( false ); + // ShowVariableMode(); + // ShowPrecision(); + // ShowDefaults(); + // } + // break; + // case PropertyType.Constant: + // { + // ShowPropertyInspectorNameGUI(); + // ShowPrecision(); + // m_colorSpace = (ASEColorSpace)EditorGUILayoutEnumPopup( ColorSpaceStr, m_colorSpace ); + // ShowDefaults(); + // } + // break; + // } + // } + // EditorGUILayout.EndVertical(); + //} + + public override void DrawMaterialProperties() + { + if( m_materialMode ) + EditorGUI.BeginChangeCheck(); +#if UNITY_2018_1_OR_NEWER + m_materialValue = EditorGUILayoutColorField( Constants.MaterialValueLabelContent, m_materialValue, false, true, m_isHDR ); +#else + m_materialValue = EditorGUILayoutColorField( Constants.MaterialValueLabelContent, m_materialValue, false, true, m_isHDR, m_hdrConfig ); +#endif + if( m_materialMode && EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos = m_globalPosition; + m_propertyDrawPos.x = m_remainingBox.x; + m_propertyDrawPos.y = m_remainingBox.y; + m_propertyDrawPos.width = 80 * drawInfo.InvertedZoom; + m_propertyDrawPos.height = m_remainingBox.height; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + //hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if( insideBox ) + { + m_isEditingFields = true; + } + else if( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( !m_isVisible ) + return; + + if( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + EditorGUI.BeginChangeCheck(); +#if UNITY_2018_1_OR_NEWER + m_materialValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR ); +#else + m_materialValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR, m_hdrConfig ); +#endif + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = true; + if( m_currentParameterType != PropertyType.Constant ) + { + BeginDelayedDirtyProperty(); + } + } + } + else + { + EditorGUI.BeginChangeCheck(); +#if UNITY_2018_1_OR_NEWER + m_defaultValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR ); +#else + m_defaultValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR, m_hdrConfig ); +#endif + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + BeginDelayedDirtyProperty(); + } + } + } + else if( drawInfo.CurrentEventType == EventType.Repaint ) + { + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + EditorGUIUtility.DrawColorSwatch( m_propertyDrawPos, m_materialValue ); + else + EditorGUIUtility.DrawColorSwatch( m_propertyDrawPos, m_defaultValue ); + + GUI.Label( m_propertyDrawPos, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) ); + } + } + + public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) + { + Color color = m_defaultValue; + //switch( m_colorSpace ) + //{ + // default: + // case ASEColorSpace.Auto: color = m_defaultValue; break; + // case ASEColorSpace.Gamma: color = m_defaultValue.gamma; break; + // case ASEColorSpace.Linear: color = m_defaultValue.linear; break; + //} + + dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( color.r + "," + color.g + "," + color.b + "," + color.a ) ); + + m_outputPorts[ 0 ].SetLocalValue( m_propertyName , dataCollector.PortCategory); + m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".r", dataCollector.PortCategory ); + m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".g", dataCollector.PortCategory ); + m_outputPorts[ 3 ].SetLocalValue( m_propertyName + ".b", dataCollector.PortCategory ); + m_outputPorts[ 4 ].SetLocalValue( m_propertyName + ".a", dataCollector.PortCategory ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if( m_currentParameterType != PropertyType.Constant ) + return GetOutputVectorItem( 0, outputId, PropertyData( dataCollector.PortCategory ) ); + + // Constant Only Code + + if( m_outputPorts[ outputId ].IsLocalValue(dataCollector.PortCategory) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + if( m_autoGammaToLinearConversion ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue(dataCollector.PortCategory) ); + + Color linear = m_defaultValue.linear; + + string colorGamma = m_precisionString + "(" + m_defaultValue.r + "," + m_defaultValue.g + "," + m_defaultValue.b + "," + m_defaultValue.a + ")"; + string colorLinear = m_precisionString + "(" + linear.r + "," + linear.g + "," + linear.b + "," + m_defaultValue.a + ")"; + + string result = string.Format( AutoGammaToLinearConversion, colorGamma, colorLinear ); + RegisterLocalVariable( 0, result, ref dataCollector, "color" + OutputId ); + return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + else + { + if( CheckLocalVariable( ref dataCollector ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + Color color = m_defaultValue; + //switch( m_colorSpace ) + //{ + // default: + // case ASEColorSpace.Auto: color = m_defaultValue; break; + // case ASEColorSpace.Gamma: color = m_defaultValue.gamma; break; + // case ASEColorSpace.Linear: color = m_defaultValue.linear; break; + //} + string result = string.Empty; + + switch( outputId ) + { + case 0: + { + result = m_precisionString + "(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; + } + break; + + case 1: + { + result = color.r.ToString(); + } + break; + case 2: + { + result = color.g.ToString(); + } + break; + case 3: + { + result = color.b.ToString(); + } + break; + case 4: + { + result = color.a.ToString(); + } + break; + } + return result; + } + } + + protected override void OnAtrributesChanged() + { + CheckIfHDR(); + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + CheckIfHDR(); + } + + void CheckIfHDR() + { + int count = m_selectedAttribs.Count; + bool hdrBuffer = m_isHDR; + m_isHDR = false; + for( int i = 0; i < count; i++ ) + { + if( m_selectedAttribs[ i ] == 1 /*HDR Property ID*/) + { + m_isHDR = true; + break; + } + } + + if( hdrBuffer && !m_isHDR ) + { + bool fireDirtyProperty = false; + + if( m_defaultValue.r > 1 || m_defaultValue.g > 1 || m_defaultValue.b > 1 ) + { + float defaultColorLength = Mathf.Sqrt( m_defaultValue.r * m_defaultValue.r + m_defaultValue.g * m_defaultValue.g + m_defaultValue.b * m_defaultValue.b ); + m_defaultValue.r /= defaultColorLength; + m_defaultValue.g /= defaultColorLength; + m_defaultValue.b /= defaultColorLength; + fireDirtyProperty = true; + } + + if( m_materialValue.r > 1 || m_materialValue.g > 1 || m_materialValue.b > 1 ) + { + float materialColorLength = Mathf.Sqrt( m_materialValue.r * m_materialValue.r + m_materialValue.g * m_materialValue.g + m_materialValue.b * m_materialValue.b ); + m_materialValue.r /= materialColorLength; + m_materialValue.g /= materialColorLength; + m_materialValue.b /= materialColorLength; + fireDirtyProperty = true; + } + + if( fireDirtyProperty ) + BeginDelayedDirtyProperty(); + } + } + + public override string GetPropertyValue() + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Color) = (" + m_defaultValue.r + "," + m_defaultValue.g + "," + m_defaultValue.b + "," + m_defaultValue.a + ")"; + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetColor( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( m_materialMode && fetchMaterialValues ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + MaterialValue = mat.GetColor( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + MaterialValue = material.GetColor( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToColor( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + { + m_materialValue = IOUtils.StringToColor( GetCurrentParam( ref nodeParams ) ); + } + + if( UIUtils.CurrentShaderVersion() > 15900 ) + { + m_autoGammaToLinearConversion = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + else + { + m_autoGammaToLinearConversion = false; + } + //if( UIUtils.CurrentShaderVersion() > 14202 ) + //{ + // m_colorSpace = (ASEColorSpace)Enum.Parse( typeof( ASEColorSpace ), GetCurrentParam( ref nodeParams ) ); + //} + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.ColorToString( m_defaultValue ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.ColorToString( m_materialValue ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoGammaToLinearConversion ); + //IOUtils.AddFieldValueToString( ref nodeInfo, m_colorSpace ); + } + + public override void SetGlobalValue() { Shader.SetGlobalColor( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalColor( m_propertyName ); } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue.r.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.g.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.b.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.a.ToString( Constants.PropertyVectorFormatLabel ) : + m_defaultValue.r.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.g.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.b.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.a.ToString( Constants.PropertyVectorFormatLabel ); + } + + private Color MaterialValue + { + set + { + if( !m_isHDR && ( value.r > 1 || value.g > 1 || value.r > 1 ) ) + { + float materialColorLength = Mathf.Sqrt( value.r * value.r + value.g * value.g + value.b * value.b ); + m_materialValue.r = value.r / materialColorLength; + m_materialValue.g = value.g / materialColorLength; + m_materialValue.b = value.b / materialColorLength; + m_materialValue.a = value.a; + } + else + { + m_materialValue = value; + } + } + } + + public Color Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs.meta new file mode 100644 index 00000000..1a21bb5c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ColorNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4b99bcf4cd965c648bbbc1de0d1b152a +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs new file mode 100644 index 00000000..d224465f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs @@ -0,0 +1,486 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +// +// Custom Node Global Array +// Donated by Johann van Berkel + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Global Array", "Constants And Properties", "The node returns a value from a global array, which you can configure by entering the name of the array in the node's settings.", null, KeyCode.None, true, false, null, null, "Johann van Berkel" )] + public sealed class GlobalArrayNode : ParentNode + { + private const string DefaultArrayName = "MyGlobalArray"; + private const string TypeStr = "Type"; + private const string AutoRangeCheckStr = "Range Check"; + private const string ArrayFormatStr = "{0}[{1}]"; + private const string JaggedArrayFormatStr = "{0}[{1}][{2}]"; + private const string IsJaggedStr = "Is Jagged"; + private const string AutoRegisterStr = "Auto-Register"; + + private readonly string[] AvailableTypesLabel = { "Float", "Color", "Vector4", "Matrix4" }; + private readonly WirePortDataType[] AvailableTypesValues = { WirePortDataType.FLOAT, WirePortDataType.COLOR, WirePortDataType.FLOAT4, WirePortDataType.FLOAT4x4 }; + + [SerializeField] + private string m_name = DefaultArrayName; + + [SerializeField] + private int m_indexX = 0; + + [SerializeField] + private int m_indexY = 0; + + [SerializeField] + private int m_arrayLengthX = 1; + + [SerializeField] + private int m_arrayLengthY = 1; + + [SerializeField] + private int m_type = 0; + + [SerializeField] + private bool m_autoRangeCheck = false; + + [SerializeField] + private bool m_isJagged = false; + + [SerializeField] + private bool m_autoRegister = false; + + ////////////////////////////////////////////////////////////////// + private readonly Color ReferenceHeaderColor = new Color( 0.6f, 3.0f, 1.25f, 1.0f ); + + [SerializeField] + private TexReferenceType m_referenceType = TexReferenceType.Object; + + [SerializeField] + private int m_referenceArrayId = -1; + + [SerializeField] + private int m_referenceNodeId = -1; + + private GlobalArrayNode m_referenceNode = null; + + private bool m_updated = false; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + + AddInputPort( WirePortDataType.INT, false, "Index", -1, MasterNodePortCategory.Fragment, 0 ); + AddInputPort( WirePortDataType.INT, false, "Index Y", -1, MasterNodePortCategory.Fragment, 2 ); + AddInputPort( WirePortDataType.INT, false, "Array Length", -1, MasterNodePortCategory.Fragment, 1 ); + AddInputPort( WirePortDataType.INT, false, "Array Length Y", -1, MasterNodePortCategory.Fragment, 3 ); + + AddOutputPort( WirePortDataType.FLOAT, "Out" ); + + m_textLabelWidth = 95; + SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) ); + UpdatePorts(); + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + UIUtils.CurrentWindow.OutsideGraph.GlobalArrayNodes.AddNode( this ); + } + + public override void Destroy() + { + base.Destroy(); + UIUtils.CurrentWindow.OutsideGraph.GlobalArrayNodes.RemoveNode( this ); + } + + void UpdatePorts() + { + InputPort indexXPort = GetInputPortByUniqueId( 0 ); + InputPort arrayLengthPortX = GetInputPortByUniqueId( 1 ); + InputPort indexYPort = GetInputPortByUniqueId( 2 ); + InputPort arrayLengthPortY = GetInputPortByUniqueId( 3 ); + if( m_referenceType == TexReferenceType.Object ) + { + m_headerColorModifier = Color.white; + SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) ); + arrayLengthPortX.Visible = true; + if( m_isJagged ) + { + indexXPort.Name = "Index X"; + arrayLengthPortX.Name = "Array Length X"; + indexYPort.Visible = true; + arrayLengthPortY.Visible = true; + } + else + { + indexXPort.Name = "Index"; + arrayLengthPortX.Name = "Array Length"; + indexYPort.Visible = false; + arrayLengthPortY.Visible = false; + } + } + else if( m_referenceNodeId > -1 ) + { + m_headerColorModifier = ReferenceHeaderColor; + if( m_referenceNode == null ) + m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode; + + if( m_referenceNode != null ) + { + SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_referenceNode.DataToArray ) ); + arrayLengthPortX.Visible = false; + arrayLengthPortY.Visible = false; + if( m_referenceNode.IsJagged ) + { + indexXPort.Name = "Index X"; + indexYPort.Visible = true; + } + else + { + indexXPort.Name = "Index"; + indexYPort.Visible = false; + } + } + } + m_sizeIsDirty = true; + } + + void DrawObjectProperties() + { + EditorGUI.BeginChangeCheck(); + m_name = EditorGUILayoutStringField( "Name", m_name ); + if( EditorGUI.EndChangeCheck() ) + { + m_updated = true; + m_name = UIUtils.RemoveInvalidCharacters( m_name ); + if( string.IsNullOrEmpty( m_name ) ) + m_name = DefaultArrayName; + UIUtils.UpdateGlobalArrayDataNode( UniqueId, m_name ); + SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) ); + } + + + m_autoRegister = EditorGUILayoutToggle( AutoRegisterStr, m_autoRegister ); + + EditorGUI.BeginChangeCheck(); + m_isJagged = EditorGUILayoutToggle( IsJaggedStr, m_isJagged ); + if( EditorGUI.EndChangeCheck() ) + { + m_updated = true; + UpdatePorts(); + } + + InputPort indexXPort = GetInputPortByUniqueId( 0 ); + if( !indexXPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_indexX = EditorGUILayoutIntField( indexXPort.Name, m_indexX ); + if( EditorGUI.EndChangeCheck() ) + { + m_indexX = Mathf.Clamp( m_indexX, 0, ( m_arrayLengthX - 1 ) ); + } + } + + if( m_isJagged ) + { + InputPort indexYPort = GetInputPortByUniqueId( 2 ); + if( !indexYPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_indexY = EditorGUILayoutIntField( indexYPort.Name, m_indexY ); + if( EditorGUI.EndChangeCheck() ) + { + m_indexY = Mathf.Clamp( m_indexY, 0, ( m_arrayLengthY - 1 ) ); + } + } + } + + InputPort arrayLengthXPort = GetInputPortByUniqueId( 1 ); + if( !arrayLengthXPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_arrayLengthX = EditorGUILayoutIntField( arrayLengthXPort.Name, m_arrayLengthX ); + if( EditorGUI.EndChangeCheck() ) + { + m_arrayLengthX = Mathf.Max( 1, m_arrayLengthX ); + } + } + + if( m_isJagged ) + { + InputPort arrayLengthYPort = GetInputPortByUniqueId( 3 ); + if( !arrayLengthYPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_arrayLengthY = EditorGUILayoutIntField( arrayLengthYPort.Name, m_arrayLengthY ); + if( EditorGUI.EndChangeCheck() ) + { + m_arrayLengthY = Mathf.Max( 1, m_arrayLengthY ); + } + } + } + + EditorGUI.BeginChangeCheck(); + m_type = EditorGUILayoutPopup( TypeStr, m_type, AvailableTypesLabel ); + if( EditorGUI.EndChangeCheck() ) + { + m_outputPorts[ 0 ].ChangeType( (WirePortDataType)AvailableTypesValues[ m_type ], false ); + } + + m_autoRangeCheck = EditorGUILayoutToggle( AutoRangeCheckStr, m_autoRangeCheck ); + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + m_updated = false; + if( m_referenceType == TexReferenceType.Instance ) + { + if( m_referenceNodeId > -1 && m_referenceNode == null ) + { + m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode; + if( m_referenceNode == null ) + { + m_referenceNodeId = -1; + } + } + if( m_referenceNode != null && m_referenceNode.Updated) + { + UpdatePorts(); + } + } + } + + void DrawInstancedProperties() + { + string[] arr = UIUtils.GlobalArrayNodeArr(); + bool guiEnabledBuffer = GUI.enabled; + if( arr != null && arr.Length > 0 ) + { + GUI.enabled = true; + } + else + { + m_referenceArrayId = -1; + m_referenceNodeId = -1; + m_referenceNode = null; + GUI.enabled = false; + } + EditorGUI.BeginChangeCheck(); + m_referenceArrayId = EditorGUILayoutPopup( Constants.AvailableReferenceStr, m_referenceArrayId, arr ); + if( EditorGUI.EndChangeCheck() ) + { + m_referenceNode = UIUtils.GetGlobalArrayNode( m_referenceArrayId ); + if( m_referenceNode != null ) + { + m_referenceNodeId = m_referenceNode.UniqueId; + } + UpdatePorts(); + } + + GUI.enabled = guiEnabledBuffer; + + InputPort indexXPort = GetInputPortByUniqueId( 0 ); + if( !indexXPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_indexX = EditorGUILayoutIntField( indexXPort.Name, m_indexX ); + if( EditorGUI.EndChangeCheck() ) + { + m_indexX = Mathf.Clamp( m_indexX, 0, ( m_arrayLengthX - 1 ) ); + } + } + + if( m_isJagged ) + { + InputPort indexYPort = GetInputPortByUniqueId( 2 ); + if( !indexYPort.IsConnected ) + { + EditorGUI.BeginChangeCheck(); + m_indexY = EditorGUILayoutIntField( indexYPort.Name, m_indexY ); + if( EditorGUI.EndChangeCheck() ) + { + m_indexY = Mathf.Clamp( m_indexY, 0, ( m_arrayLengthY - 1 ) ); + } + } + } + } + + public override void DrawProperties() + { + EditorGUI.BeginChangeCheck(); + m_referenceType = (TexReferenceType)EditorGUILayoutPopup( Constants.ReferenceTypeStr, (int)m_referenceType, Constants.ReferenceArrayLabels ); + if( EditorGUI.EndChangeCheck() ) + { + UpdatePorts(); + } + + if( m_referenceType == TexReferenceType.Object ) + DrawObjectProperties(); + else + DrawInstancedProperties(); + } + + public string GetArrayValue( string indexX, string indexY = null ) + { + if( m_isJagged ) + return string.Format( JaggedArrayFormatStr, m_name, indexX, indexY ); + + return string.Format( ArrayFormatStr, m_name, indexX ); + } + + public string GenerateInstancedShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string result = string.Empty; + if( m_referenceNode != null ) + { + InputPort indexXPort = GetInputPortByUniqueId( 0 ); + if( m_referenceNode.IsJagged ) + { + InputPort indexYPort = GetInputPortByUniqueId( 2 ); + string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString(); + string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString(); + result = m_referenceNode.GetArrayValue( arrayIndexX, arrayIndexY ); + } + else + { + string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString(); + result = m_referenceNode.GetArrayValue( arrayIndexX ); + } + } + m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory ); + return result; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + if( m_referenceType == TexReferenceType.Instance ) + return GenerateInstancedShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + string dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, AvailableTypesValues[ m_type ] ); + + InputPort indexXPort = GetInputPortByUniqueId( 0 ); + InputPort arrayLengthXPort = GetInputPortByUniqueId( 1 ); + string result = string.Empty; + + if( m_isJagged ) + { + InputPort indexYPort = GetInputPortByUniqueId( 2 ); + InputPort arrayLengthYPort = GetInputPortByUniqueId( 3 ); + + string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString(); + string arrayLengthX = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString(); + + string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString(); + string arrayLengthY = arrayLengthYPort.IsConnected ? arrayLengthYPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthY.ToString(); + + dataCollector.AddToUniforms( UniqueId, dataType, string.Format( JaggedArrayFormatStr, m_name, arrayLengthX, arrayLengthY ) ); + if( m_autoRangeCheck ) + { + arrayIndexX = string.Format( "clamp({0},0,({1} - 1))", arrayIndexX, arrayLengthX ); + arrayIndexY = string.Format( "clamp({0},0,({1} - 1))", arrayIndexY, arrayLengthY ); + } + result = string.Format( JaggedArrayFormatStr, m_name, arrayIndexX, arrayIndexY ); + } + else + { + + string arrayIndex = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString(); + string arrayLength = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString(); + + + dataCollector.AddToUniforms( UniqueId, dataType, string.Format( ArrayFormatStr, m_name, arrayLength ) ); + + if( m_autoRangeCheck ) + arrayIndex = string.Format( "clamp({0},0,({1} - 1))", arrayIndex, arrayLength ); + + result = string.Format( ArrayFormatStr, m_name, arrayIndex ); + } + + m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + public void CheckIfAutoRegister( ref MasterNodeDataCollector dataCollector ) + { + if( m_referenceType == TexReferenceType.Object && m_autoRegister && m_connStatus != NodeConnectionStatus.Connected ) + { + string dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, AvailableTypesValues[ m_type ] ); + if( m_isJagged ) + { + dataCollector.AddToUniforms( UniqueId, dataType, string.Format( JaggedArrayFormatStr, m_name, m_arrayLengthX, m_arrayLengthY ) ); + } + else + { + dataCollector.AddToUniforms( UniqueId, dataType, string.Format( ArrayFormatStr, m_name, m_arrayLengthX ) ); + } + } + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_name ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_indexX ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_arrayLengthX ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_type ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRangeCheck ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_isJagged ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_indexY ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_arrayLengthY ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRegister ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_referenceType ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_referenceNodeId ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_name = GetCurrentParam( ref nodeParams ); + m_indexX = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_arrayLengthX = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_type = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_autoRangeCheck = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 15801 ) + { + m_isJagged = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + m_indexY = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_arrayLengthY = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_autoRegister = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + m_referenceType = (TexReferenceType)Enum.Parse( typeof( TexReferenceType ), GetCurrentParam( ref nodeParams ) ); + m_referenceNodeId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + } + SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) ); + UpdatePorts(); + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( m_referenceType == TexReferenceType.Instance && m_referenceNodeId > -1 ) + { + m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode; + if( m_referenceNode != null ) + { + m_referenceArrayId = UIUtils.GetGlobalArrayNodeRegisterId( m_referenceNodeId ); + UpdatePorts(); + } + else + { + m_referenceNodeId = -1; + } + } + } + + public bool AutoRegister { get { return m_autoRegister; } } + public bool IsJagged { get { return m_isJagged; } } + public bool Updated { get { return m_updated; } } + public override string DataToArray { get { return m_name; } } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs.meta new file mode 100644 index 00000000..c0171212 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GlobalArrayNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 833b18e1479dbd24c80c5b990e16e2bb +timeCreated: 1499769855 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs new file mode 100644 index 00000000..b8f9437a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs @@ -0,0 +1,191 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Gradient", "Constants And Properties", "Gradient property" )] + public sealed class GradientNode : ParentNode + { + [SerializeField] + private Gradient m_gradient = new Gradient(); + + private string m_functionHeader = "NewGradient( {0}, {1}, {2}," + + " {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}," + + " {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18} )"; + private string m_functionBody = string.Empty; + + private string m_functionHeaderStruct = "Gradient( {0} )"; + private string m_functionBodyStruct = string.Empty; + + public Gradient Gradient { get { return m_gradient; } } + + public GradientNode() : base() { } + public GradientNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_insideSize.Set( 128, m_insideSize.y ); + AddOutputPort( WirePortDataType.OBJECT, Constants.EmptyPortValue ); + m_autoWrapProperties = true; + m_textLabelWidth = 100; + } + + public override void DrawProperties() + { + base.DrawProperties(); + m_gradient = EditorGUILayoutEx.GradientField( "Gradient", m_gradient ); + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( !m_isVisible ) + return; + + m_gradient = EditorGUIEx.GradientField( m_remainingBox, m_gradient ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + m_functionBodyStruct = string.Empty; + m_functionBody = string.Empty; + if( !dataCollector.IsSRP ) + { + GenerateGradientStruct( ref m_functionBodyStruct ); + dataCollector.AddFunctions( m_functionHeaderStruct, m_functionBodyStruct, "0" ); + GenerateGradient( ref m_functionBody ); + } + else + { + dataCollector.AddToIncludes( UniqueId, "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" ); + } + + string[] colors = new string[ 8 ]; + for( int i = 0; i < 8; i++ ) + { + if( i < m_gradient.colorKeys.Length ) + { + colors[ i ] = "float4( "+ m_gradient.colorKeys[ i ].color.r + ", "+ m_gradient.colorKeys[ i ].color.g + ", "+ m_gradient.colorKeys[ i ].color.b + ", "+ m_gradient.colorKeys[ i ].time + " )"; + } + else + { + colors[ i ] = "0"; + } + } + + string[] alphas = new string[ 8 ]; + for( int i = 0; i < 8; i++ ) + { + if( i < m_gradient.alphaKeys.Length ) + { + alphas[ i ] = "float2( " + m_gradient.alphaKeys[ i ].alpha + ", " + m_gradient.alphaKeys[ i ].time + " )"; + } + else + { + alphas[ i ] = "0"; + } + } + + string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, (int)m_gradient.mode, m_gradient.colorKeys.Length, m_gradient.alphaKeys.Length + , colors[ 0 ], colors[ 1 ], colors[ 2 ], colors[ 3 ], colors[ 4 ], colors[ 5 ], colors[ 6 ], colors[ 7 ] + , alphas[ 0 ], alphas[ 1 ], alphas[ 2 ], alphas[ 3 ], alphas[ 4 ], alphas[ 5 ], alphas[ 6 ], alphas[ 7 ] ); + + dataCollector.AddLocalVariable( UniqueId, "Gradient gradient" + UniqueId + " = " + functionResult + ";" ); + + return "gradient" + UniqueId; + } + + public static void GenerateGradientStruct( ref string body ) + { + body = string.Empty; + IOUtils.AddFunctionHeader( ref body, "struct Gradient" ); + IOUtils.AddFunctionLine( ref body, "int type;" ); + IOUtils.AddFunctionLine( ref body, "int colorsLength;" ); + IOUtils.AddFunctionLine( ref body, "int alphasLength;" ); + IOUtils.AddFunctionLine( ref body, "float4 colors[8];" ); + IOUtils.AddFunctionLine( ref body, "float2 alphas[8];" ); + IOUtils.AddSingleLineFunction( ref body, "};\n" ); + } + + public static void GenerateGradient( ref string body ) + { + body = string.Empty; + IOUtils.AddFunctionHeader( ref body, "Gradient NewGradient(int type, int colorsLength, int alphasLength, \n\t\tfloat4 colors0, float4 colors1, float4 colors2, float4 colors3, float4 colors4, float4 colors5, float4 colors6, float4 colors7,\n\t\tfloat2 alphas0, float2 alphas1, float2 alphas2, float2 alphas3, float2 alphas4, float2 alphas5, float2 alphas6, float2 alphas7)" ); + IOUtils.AddFunctionLine( ref body, "Gradient g;" ); + IOUtils.AddFunctionLine( ref body, "g.type = type;" ); + IOUtils.AddFunctionLine( ref body, "g.colorsLength = colorsLength;" ); + IOUtils.AddFunctionLine( ref body, "g.alphasLength = alphasLength;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 0 ] = colors0;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 1 ] = colors1;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 2 ] = colors2;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 3 ] = colors3;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 4 ] = colors4;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 5 ] = colors5;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 6 ] = colors6;" ); + IOUtils.AddFunctionLine( ref body, "g.colors[ 7 ] = colors7;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 0 ] = alphas0;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 1 ] = alphas1;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 2 ] = alphas2;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 3 ] = alphas3;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 4 ] = alphas4;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 5 ] = alphas5;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 6 ] = alphas6;" ); + IOUtils.AddFunctionLine( ref body, "g.alphas[ 7 ] = alphas7;" ); + IOUtils.AddFunctionLine( ref body, "return g;" ); + IOUtils.CloseFunctionBody( ref body ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_gradient.mode = (GradientMode)Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + int colorCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + int alphaCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + + var colorKeys = new GradientColorKey[ colorCount ]; + for( int i = 0; i < colorCount; i++ ) + { + Vector4 colorKey = IOUtils.StringToVector4( GetCurrentParam( ref nodeParams ) ); + colorKeys[ i ].color = colorKey; + colorKeys[ i ].time = colorKey.w; + } + m_gradient.colorKeys = colorKeys; + + var alphaKeys = new GradientAlphaKey[ alphaCount ]; + for( int i = 0; i < alphaCount; i++ ) + { + Vector2 alphaKey = IOUtils.StringToVector2( GetCurrentParam( ref nodeParams ) ); + alphaKeys[ i ].alpha = alphaKey.x; + alphaKeys[ i ].time = alphaKey.y; + } + m_gradient.alphaKeys = alphaKeys; + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, (int)m_gradient.mode ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_gradient.colorKeys.Length ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_gradient.alphaKeys.Length ); + + for( int i = 0; i < m_gradient.colorKeys.Length; i++ ) + { + Vector4 colorKey = new Vector4( m_gradient.colorKeys[ i ].color.r, m_gradient.colorKeys[ i ].color.g, m_gradient.colorKeys[ i ].color.b, m_gradient.colorKeys[ i ].time) ; + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector4ToString( colorKey ) ); + } + + for( int i = 0; i < m_gradient.alphaKeys.Length; i++ ) + { + Vector2 alphaKey = new Vector4( m_gradient.alphaKeys[ i ].alpha, m_gradient.alphaKeys[ i ].time ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector2ToString( alphaKey ) ); + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs.meta new file mode 100644 index 00000000..cb9b560a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/GradientNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 98100a8a545b8ce42bc5657fd40a24a5 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs new file mode 100644 index 00000000..3368c05d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs @@ -0,0 +1,281 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Int", "Constants And Properties", "Int property", null, KeyCode.Alpha0 )] + public sealed class IntNode : PropertyNode + { + [SerializeField] + private int m_defaultValue; + + [SerializeField] + private int m_materialValue; + + private const float LabelWidth = 8; + + private int m_cachedPropertyId = -1; + + private bool m_isEditingFields; + private int m_previousValue; + private string m_fieldText = "0"; + + public IntNode() : base() { } + public IntNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Int" ); + AddOutputPort( WirePortDataType.INT, Constants.EmptyPortValue ); + m_insideSize.Set( 50, 10 ); + m_selectedLocation = PreviewLocation.BottomCenter; + m_drawPrecisionUI = false; + m_showHybridInstancedUI = true; + m_availableAttribs.Add( new PropertyAttributes( "Enum", "[Enum]" ) ); + m_previewShaderGUID = "0f64d695b6ffacc469f2dd31432a232a"; + m_srpBatcherCompatible = true; + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + UIUtils.RegisterFloatIntNode( this ); + } + + public override void Destroy() + { + base.Destroy(); + UIUtils.UnregisterFloatIntNode( this ); + } + + public override void OnDirtyProperty() + { + UIUtils.UpdateFloatIntDataNode( UniqueId, PropertyInspectorName ); + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + OnPropertyNameChanged(); + OnDirtyProperty(); + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputInt" ); + + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetInt( m_cachedPropertyId, m_materialValue ); + else + PreviewMaterial.SetInt( m_cachedPropertyId, m_defaultValue ); + } + + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + m_defaultValue = EditorGUILayoutIntField( Constants.DefaultValueLabel, m_defaultValue ); + } + + public override void DrawMaterialProperties() + { + if( m_materialMode ) + EditorGUI.BeginChangeCheck(); + + m_materialValue = EditorGUILayoutIntField( Constants.MaterialValueLabel, m_materialValue ); + + if( m_materialMode && EditorGUI.EndChangeCheck() ) + { + m_requireMaterialUpdate = true; + } + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( !m_isVisible ) + return; + + if( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + float labelWidth = EditorGUIUtility.labelWidth; + EditorGUIUtility.labelWidth = LabelWidth * drawInfo.InvertedZoom; + + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + EditorGUI.BeginChangeCheck(); + m_materialValue = EditorGUIIntField( m_propertyDrawPos, " ", m_materialValue, UIUtils.MainSkin.textField ); + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = true; + if( m_currentParameterType != PropertyType.Constant ) + BeginDelayedDirtyProperty(); + } + } + else + { + EditorGUI.BeginChangeCheck(); + + m_defaultValue = EditorGUIIntField( m_propertyDrawPos, " ", m_defaultValue, UIUtils.MainSkin.textField ); + + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + BeginDelayedDirtyProperty(); + } + } + EditorGUIUtility.labelWidth = labelWidth; + } + else if( drawInfo.CurrentEventType == EventType.Repaint ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + if( GUI.enabled ) + { + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + } + bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant; + int value = currMode ? m_materialValue : m_defaultValue; + + if( m_previousValue != value ) + { + m_previousValue = value; + m_fieldText = value.ToString(); + } + + GUI.Label( fakeField, m_fieldText, UIUtils.MainSkin.textField ); + GUI.enabled = guiEnabled; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + if( m_currentParameterType != PropertyType.Constant ) + return PropertyData( dataCollector.PortCategory ); + + return m_defaultValue.ToString(); + } + + public override string GetPropertyValue() + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Int) = " + m_defaultValue; + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetInt( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetInt( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetInt( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + m_materialValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_materialValue ); + } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? + m_materialValue.ToString( Mathf.Abs( m_materialValue ) > 1000 ? Constants.PropertyBigIntFormatLabel : Constants.PropertyIntFormatLabel ) : + m_defaultValue.ToString( Mathf.Abs( m_defaultValue ) > 1000 ? Constants.PropertyBigIntFormatLabel : Constants.PropertyIntFormatLabel ); + } + + public override void SetGlobalValue() { Shader.SetGlobalInt( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalInt( m_propertyName ); } + public int Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + + public void SetMaterialValueFromInline( int val ) + { + m_materialValue = val; + m_requireMaterialUpdate = true; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs.meta new file mode 100644 index 00000000..0bbac6ff --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/IntNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 86df2da3da3b1eb4493b968b47030b17 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs new file mode 100644 index 00000000..02266c8b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs @@ -0,0 +1,261 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Matrix3X3", "Constants And Properties", "Matrix3X3 property" )] + public sealed class Matrix3X3Node : MatrixParentNode + { + private string[,] m_fieldText = new string[ 3, 3 ] { { "0", "0", "0" }, { "0", "0", "0" }, { "0", "0", "0" } }; + public Matrix3X3Node() : base() { } + public Matrix3X3Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Matrix" ); + AddOutputPort( WirePortDataType.FLOAT3x3, Constants.EmptyPortValue ); + m_insideSize.Set( Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE * 3 + Constants.FLOAT_WIDTH_SPACING * 2, Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE * 3 + Constants.FLOAT_WIDTH_SPACING * 2 + Constants.OUTSIDE_WIRE_MARGIN ); + //m_defaultValue = new Matrix4x4(); + //m_materialValue = new Matrix4x4(); + m_drawPreview = false; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + EditorGUILayout.LabelField( Constants.DefaultValueLabel ); + for( int row = 0; row < 3; row++ ) + { + EditorGUILayout.BeginHorizontal(); + for( int column = 0; column < 3; column++ ) + { + m_defaultValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_defaultValue[ row, column ], GUILayout.MaxWidth( 76 ) ); + } + EditorGUILayout.EndHorizontal(); + } + } + + public override void DrawMaterialProperties() + { + if( m_materialMode ) + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.LabelField( Constants.MaterialValueLabel ); + for( int row = 0; row < 3; row++ ) + { + EditorGUILayout.BeginHorizontal(); + for( int column = 0; column < 3; column++ ) + { + m_materialValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_materialValue[ row, column ], GUILayout.MaxWidth( 76 ) ); + } + EditorGUILayout.EndHorizontal(); + } + + if( m_materialMode && EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos.position = m_remainingBox.position; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.height = m_insideSize.y * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( !m_isVisible ) + return; + + if( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant; + Matrix4x4 value = currMode ? m_materialValue : m_defaultValue; + + EditorGUI.BeginChangeCheck(); + for( int row = 0; row < 3; row++ ) + { + for( int column = 0; column < 3; column++ ) + { + m_propertyDrawPos.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row ); + value[ row, column ] = EditorGUIFloatField( m_propertyDrawPos, string.Empty, value[ row, column ], UIUtils.MainSkin.textField ); + } + } + + if( currMode ) + { + m_materialValue = value; + } + else + { + m_defaultValue = value; + } + + if( EditorGUI.EndChangeCheck() ) + { + m_requireMaterialUpdate = m_materialMode; + BeginDelayedDirtyProperty(); + } + } + else if( drawInfo.CurrentEventType == EventType.Repaint ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + + bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant; + Matrix4x4 value = currMode ? m_materialValue : m_defaultValue; + for( int row = 0; row < 3; row++ ) + { + for( int column = 0; column < 3; column++ ) + { + Rect fakeField = m_propertyDrawPos; + fakeField.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row ); + if( GUI.enabled ) + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + + if( m_previousValue[ row, column ] != value[ row, column ] ) + { + m_previousValue[ row, column ] = value[ row, column ]; + m_fieldText[ row, column ] = value[ row, column ].ToString(); + } + + GUI.Label( fakeField, m_fieldText[ row, column ], UIUtils.MainSkin.textField ); + } + } + GUI.enabled = guiEnabled; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + if( m_currentParameterType != PropertyType.Constant ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + string localVarName = PropertyData( dataCollector.PortCategory ) + "Local3x3"; + string localVarValue = string.Format( "float3x3({0}._m00,{0}._m01,{0}._m02,{0}._m10,{0}._m11,{0}._m12,{0}._m20,{0}._m21,{0}._m22 )", PropertyData( dataCollector.PortCategory ) ); + RegisterLocalVariable( 0, localVarValue, ref dataCollector, localVarName ); + return localVarName; + } + + Matrix4x4 value = m_defaultValue; + + return m_precisionString + "(" + value[ 0, 0 ] + "," + value[ 0, 1 ] + "," + value[ 0, 2 ] + "," + + +value[ 1, 0 ] + "," + value[ 1, 1 ] + "," + value[ 1, 2 ] + "," + + +value[ 2, 0 ] + "," + value[ 2, 1 ] + "," + value[ 2, 2 ] + ")"; + + } + + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + Shader.SetGlobalMatrix( m_propertyName, m_materialValue ); + //mat.SetMatrix( m_propertyName, m_materialValue ); + } + } + + public override bool GetUniformData( out string dataType, out string dataName, ref bool fullValue ) + { + dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, WirePortDataType.FLOAT4x4 ); + dataName = m_propertyName; + return true; + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetMatrix( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetMatrix( m_propertyName ); + PreviewIsDirty = true; + } + } + + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToMatrix3x3( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix3x3ToString( m_defaultValue ) ); + } + + public override void ReadAdditionalClipboardData( ref string[] nodeParams ) + { + base.ReadAdditionalClipboardData( ref nodeParams ); + m_materialValue = IOUtils.StringToMatrix3x3( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteAdditionalClipboardData( ref string nodeInfo ) + { + base.WriteAdditionalClipboardData( ref nodeInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix3x3ToString( m_materialValue ) ); + } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue[ 0, 0 ].ToString( Mathf.Abs( m_materialValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 1 ].ToString( Mathf.Abs( m_materialValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 2 ].ToString( Mathf.Abs( m_materialValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_materialValue[ 1, 0 ].ToString( Mathf.Abs( m_materialValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 1 ].ToString( Mathf.Abs( m_materialValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 2 ].ToString( Mathf.Abs( m_materialValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_materialValue[ 2, 0 ].ToString( Mathf.Abs( m_materialValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 1 ].ToString( Mathf.Abs( m_materialValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 2 ].ToString( Mathf.Abs( m_materialValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) : + + m_defaultValue[ 0, 0 ].ToString( Mathf.Abs( m_defaultValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 1 ].ToString( Mathf.Abs( m_defaultValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 2 ].ToString( Mathf.Abs( m_defaultValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_defaultValue[ 1, 0 ].ToString( Mathf.Abs( m_defaultValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 1 ].ToString( Mathf.Abs( m_defaultValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 2 ].ToString( Mathf.Abs( m_defaultValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_defaultValue[ 2, 0 ].ToString( Mathf.Abs( m_defaultValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 1 ].ToString( Mathf.Abs( m_defaultValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 2 ].ToString( Mathf.Abs( m_defaultValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ); + } + + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs.meta new file mode 100644 index 00000000..4c852d9d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix3X3Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 01e5a5829caac674fa819ed229de31b6 +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs new file mode 100644 index 00000000..44b99702 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs @@ -0,0 +1,248 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Matrix4X4", "Constants And Properties", "Matrix4X4 property" )] + public sealed class Matrix4X4Node : MatrixParentNode + { + private string[,] m_fieldText = new string[ 4, 4 ] { { "0", "0", "0", "0" }, { "0", "0", "0", "0" }, { "0", "0", "0", "0" }, { "0", "0", "0", "0" } }; + public Matrix4X4Node() : base() { } + public Matrix4X4Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Matrix" ); + AddOutputPort( WirePortDataType.FLOAT4x4, Constants.EmptyPortValue ); + m_insideSize.Set( Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE * 4 + Constants.FLOAT_WIDTH_SPACING * 3, Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE * 4 + Constants.FLOAT_WIDTH_SPACING * 3 + Constants.OUTSIDE_WIRE_MARGIN ); + //m_defaultValue = new Matrix4x4(); + //m_materialValue = new Matrix4x4(); + m_drawPreview = false; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + EditorGUILayout.LabelField( Constants.DefaultValueLabel ); + for ( int row = 0; row < 4; row++ ) + { + EditorGUILayout.BeginHorizontal(); + for ( int column = 0; column < 4; column++ ) + { + m_defaultValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_defaultValue[ row, column ], GUILayout.MaxWidth( 55 ) ); + } + EditorGUILayout.EndHorizontal(); + } + } + + public override void DrawMaterialProperties() + { + if ( m_materialMode ) + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.LabelField( Constants.MaterialValueLabel ); + for ( int row = 0; row < 4; row++ ) + { + EditorGUILayout.BeginHorizontal(); + for ( int column = 0; column < 4; column++ ) + { + m_materialValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_materialValue[ row, column ], GUILayout.MaxWidth( 55 ) ); + } + EditorGUILayout.EndHorizontal(); + } + + if ( m_materialMode && EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos.position = m_remainingBox.position; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if ( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.height = m_insideSize.y * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if ( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if ( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if ( !m_isVisible ) + return; + + if ( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant; + Matrix4x4 value = currMode ? m_materialValue : m_defaultValue; + + EditorGUI.BeginChangeCheck(); + for ( int row = 0; row < 4; row++ ) + { + for ( int column = 0; column < 4; column++ ) + { + m_propertyDrawPos.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row ); + value[ row, column ] = EditorGUIFloatField( m_propertyDrawPos, string.Empty, value[ row, column ], UIUtils.MainSkin.textField ); + } + } + + if ( currMode ) + { + m_materialValue = value; + } + else + { + m_defaultValue = value; + } + + if ( EditorGUI.EndChangeCheck() ) + { + m_requireMaterialUpdate = m_materialMode; + BeginDelayedDirtyProperty(); + } + } + else if ( drawInfo.CurrentEventType == EventType.Repaint ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + + bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant; + Matrix4x4 value = currMode ? m_materialValue : m_defaultValue; + for ( int row = 0; row < 4; row++ ) + { + for ( int column = 0; column < 4; column++ ) + { + Rect fakeField = m_propertyDrawPos; + fakeField.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row ); + if( GUI.enabled ) + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + + if ( m_previousValue[ row, column ] != value[ row, column ] ) + { + m_previousValue[ row, column ] = value[ row, column ]; + m_fieldText[ row, column ] = value[ row, column ].ToString(); + } + + GUI.Label( fakeField, m_fieldText[ row, column ], UIUtils.MainSkin.textField ); + } + } + GUI.enabled = guiEnabled; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + if ( m_currentParameterType != PropertyType.Constant ) + return PropertyData( dataCollector.PortCategory ); + + Matrix4x4 value = m_defaultValue; + + return m_precisionString+"(" + value[ 0, 0 ] + "," + value[ 0, 1 ] + "," + value[ 0, 2 ] + "," + value[ 0, 3 ] + "," + + +value[ 1, 0 ] + "," + value[ 1, 1 ] + "," + value[ 1, 2 ] + "," + value[ 1, 3 ] + "," + + +value[ 2, 0 ] + "," + value[ 2, 1 ] + "," + value[ 2, 2 ] + "," + value[ 2, 3 ] + "," + + +value[ 3, 0 ] + "," + value[ 3, 1 ] + "," + value[ 3, 2 ] + "," + value[ 3, 3 ] + ")"; + + } + + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetMatrix( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat , bool fetchMaterialValues ) + { + base.SetMaterialMode( mat , fetchMaterialValues ); + if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetMatrix( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetMatrix( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToMatrix4x4( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix4x4ToString( m_defaultValue ) ); + } + + public override void ReadAdditionalClipboardData( ref string[] nodeParams ) + { + base.ReadAdditionalClipboardData( ref nodeParams ); + m_materialValue = IOUtils.StringToMatrix4x4( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteAdditionalClipboardData( ref string nodeInfo ) + { + base.WriteAdditionalClipboardData( ref nodeInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix4x4ToString( m_materialValue ) ); + } + + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue[ 0, 0 ].ToString( Mathf.Abs( m_materialValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 1 ].ToString( Mathf.Abs( m_materialValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 2 ].ToString( Mathf.Abs( m_materialValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 3 ].ToString( Mathf.Abs( m_materialValue[ 0, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_materialValue[ 1, 0 ].ToString( Mathf.Abs( m_materialValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 1 ].ToString( Mathf.Abs( m_materialValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 2 ].ToString( Mathf.Abs( m_materialValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 3 ].ToString( Mathf.Abs( m_materialValue[ 1, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_materialValue[ 2, 0 ].ToString( Mathf.Abs( m_materialValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 1 ].ToString( Mathf.Abs( m_materialValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 2 ].ToString( Mathf.Abs( m_materialValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 3 ].ToString( Mathf.Abs( m_materialValue[ 2, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_materialValue[ 3, 0 ].ToString( Mathf.Abs( m_materialValue[ 3, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 1 ].ToString( Mathf.Abs( m_materialValue[ 3, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 2 ].ToString( Mathf.Abs( m_materialValue[ 3, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 3 ].ToString( Mathf.Abs( m_materialValue[ 3, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) : + + m_defaultValue[ 0, 0 ].ToString( Mathf.Abs( m_defaultValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 1 ].ToString( Mathf.Abs( m_defaultValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 2 ].ToString( Mathf.Abs( m_defaultValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 3 ].ToString( Mathf.Abs( m_defaultValue[ 0, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_defaultValue[ 1, 0 ].ToString( Mathf.Abs( m_defaultValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 1 ].ToString( Mathf.Abs( m_defaultValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 2 ].ToString( Mathf.Abs( m_defaultValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 3 ].ToString( Mathf.Abs( m_defaultValue[ 1, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_defaultValue[ 2, 0 ].ToString( Mathf.Abs( m_defaultValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 1 ].ToString( Mathf.Abs( m_defaultValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 2 ].ToString( Mathf.Abs( m_defaultValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 3 ].ToString( Mathf.Abs( m_defaultValue[ 2, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR + + m_defaultValue[ 3, 0 ].ToString( Mathf.Abs( m_defaultValue[ 3, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 1 ].ToString( Mathf.Abs( m_defaultValue[ 3, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 2 ].ToString( Mathf.Abs( m_defaultValue[ 3, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 3 ].ToString( Mathf.Abs( m_defaultValue[ 3, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ); + } + + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs.meta new file mode 100644 index 00000000..10ec1a2f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Matrix4X4Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4fa5db614b9379b4da27edafa0a8f4e9 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs new file mode 100644 index 00000000..85e0504d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs @@ -0,0 +1,86 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + public class MatrixParentNode : PropertyNode + { + private readonly string[] AvailablePropertyTypeLabels = { PropertyType.Constant.ToString(), PropertyType.Global.ToString(), "Instanced" }; + private readonly int[] AvailablePropertyTypeValues = { (int)PropertyType.Constant, (int)PropertyType.Global , (int)PropertyType.InstancedProperty }; + + protected bool m_isEditingFields; + + [SerializeField] + protected Matrix4x4 m_defaultValue = Matrix4x4.identity; + + [SerializeField] + protected Matrix4x4 m_materialValue = Matrix4x4.identity; + + [NonSerialized] + protected Matrix4x4 m_previousValue; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + + public MatrixParentNode() : base() { } + public MatrixParentNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_freeType = false; + m_showVariableMode = true; + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + m_hasLeftDropdown = true; + m_drawAttributes = false; + m_availableAttribs.Clear(); + + if( PaddingTitleLeft == 0 ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + } + + protected void DrawParameterType() + { + PropertyType parameterType = (PropertyType)EditorGUILayoutIntPopup( ParameterTypeStr, (int)m_currentParameterType, AvailablePropertyTypeLabels, AvailablePropertyTypeValues ); + if( parameterType != m_currentParameterType ) + { + ChangeParameterType( parameterType ); + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + PropertyType parameterType = (PropertyType)m_upperLeftWidget.DrawWidget( this, (int)m_currentParameterType, AvailablePropertyTypeLabels, AvailablePropertyTypeValues ); + if( parameterType != m_currentParameterType ) + { + ChangeParameterType( parameterType ); + } + } + + public override void DrawMainPropertyBlock() + { + DrawParameterType(); + base.DrawMainPropertyBlock(); + } + + public override void Destroy() + { + base.Destroy(); + m_upperLeftWidget = null; + } + + public override void SetGlobalValue() { Shader.SetGlobalMatrix( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalMatrix( m_propertyName ); } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs.meta new file mode 100644 index 00000000..ed87f49f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/MatrixParentNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d31dc25864c509a4f967e32079a27d6f +timeCreated: 1507902748 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs new file mode 100644 index 00000000..659a128c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs @@ -0,0 +1,63 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "PI", "Constants And Properties", "PI constant : 3.14159265359" )] + public sealed class PiNode : ParentNode + { + public PiNode() : base() { } + public PiNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, true, "Multiplier" ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_textLabelWidth = 70; + InputPorts[ 0 ].FloatInternalData = 1; + m_useInternalPortData = true; + m_previewShaderGUID = "bf4a65726dab3d445a69fb1d0945c33e"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + string finalValue = string.Empty; + string piString = dataCollector.IsSRP ? "PI" : "UNITY_PI"; + if( !InputPorts[ 0 ].IsConnected && InputPorts[ 0 ].FloatInternalData == 1 ) + { + finalValue = piString; + } else + { + string multiplier = InputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + finalValue = "( " + multiplier + " * " + piString + " )"; + } + + + if ( finalValue.Equals( string.Empty ) ) + { + UIUtils.ShowMessage( UniqueId, "PINode generating empty code", MessageSeverity.Warning ); + } + return finalValue; + } + + //public override void ReadFromString( ref string[] nodeParams ) + //{ + // base.ReadFromString( ref nodeParams ); + + // Removed on version 5004 + //m_value = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + //} + + //public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + //{ + // base.WriteToString( ref nodeInfo, ref connectionsInfo ); + //} + + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs.meta new file mode 100644 index 00000000..64327b84 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7a8a03953b97a594b81b2fb71d4a57ec +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs new file mode 100644 index 00000000..68709954 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs @@ -0,0 +1,1767 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + public enum PropertyType + { + Constant = 0, + Property, + InstancedProperty, + Global + } + + public enum VariableMode + { + Create = 0, + Fetch + } + + [Serializable] + public class PropertyAttributes + { + public string Name; + public string Attribute; + public PropertyAttributes( string name, string attribute ) + { + Name = name; + Attribute = attribute; + } + } + + [Serializable] + public class PropertyNode : ParentNode + { + private const string LongNameEnder = "... )"; + protected int m_longNameSize = 200; + //private const string InstancedPropertyWarning = "Instanced Property option shouldn't be used on official SRP templates as all property variables are already declared as instanced inside a CBuffer.\nPlease consider changing to Property option."; + private string TooltipFormatter = "{0}\n\nName: {1}\nValue: {2}"; + protected string GlobalTypeWarningText = "Global variables must be set via a C# script using the Shader.SetGlobal{0}(...) method.\nPlease note that setting a global variable will affect all shaders which are using it."; + private const string HybridInstancedStr = "Hybrid Instanced"; + private const string AutoRegisterStr = "Auto-Register"; + private const string IgnoreVarDeclarationStr = "Variable Mode"; + private const string IsPropertyStr = "Is Property"; + private const string PropertyNameStr = "Property Name"; + private const string PropertyInspectorStr = "Name"; + protected const string EnumsStr = "Enums"; + protected const string CustomAttrStr = "Custom Attributes"; + protected const string ParameterTypeStr = "Type"; + private const string PropertyTextfieldControlName = "PropertyName"; + private const string PropertyInspTextfieldControlName = "PropertyInspectorName"; + private const string OrderIndexStr = "Order Index"; + protected const double MaxTimestamp = 2; + private const double MaxPropertyTimestamp = 2; + private const double MaxGlobalFetchTimestamp = 2; + protected readonly string[] LabelToolbarTitle = { "Material", "Default" }; + protected readonly string[] EnumModesStr = { "Create Enums", "Use Engine Enum Class" }; + protected readonly int[] EnumModeIntValues = { 0, 1 }; + private const string FetchToCreateDuplicatesMsg = "Reverting property name from '{0}' to '{1}' as it is registered to another property node."; + private const string FetchToCreateOnDuplicateNodeMsg = "Setting new property name '{0}' as '{1}' is registered to another property node."; + [SerializeField] + protected PropertyType m_currentParameterType; + + [SerializeField] + private PropertyType m_lastParameterType; + + [SerializeField] + protected string m_propertyName = string.Empty; + + [SerializeField] + protected string m_propertyInspectorName = string.Empty; + + [SerializeField] + protected string m_precisionString; + protected bool m_drawPrecisionUI = true; + + [SerializeField] + private int m_orderIndex = -1; + + [SerializeField] + protected VariableMode m_variableMode = VariableMode.Create; + + [SerializeField] + protected bool m_autoGlobalName = true; + + [SerializeField] + protected bool m_hybridInstanced = false; + + [SerializeField] + protected bool m_autoRegister = false; + + [SerializeField] + protected bool m_registerPropertyOnInstancing = true; + + [SerializeField] + private List<string> m_enumNames = new List<string>(); + + [SerializeField] + private List<int> m_enumValues = new List<int>(); + + [SerializeField] + private int m_enumCount = 0; + + [SerializeField] + private int m_enumModeInt = 0; + + [SerializeField] + private int m_customAttrCount = 0; + + [SerializeField] + private List<string> m_customAttr = new List<string>(); + + [SerializeField] + private string m_enumClassName = string.Empty; + + private bool m_hasEnum = false; + + protected bool m_showTitleWhenNotEditing = true; + + private int m_orderIndexOffset = 0; + + protected bool m_drawAttributes = true; + + protected bool m_underscoredGlobal = false; + protected bool m_globalDefaultBehavior = true; + + protected bool m_freeName; + protected bool m_freeType; + protected bool m_showVariableMode = false; + protected bool m_propertyNameIsDirty; + + protected bool m_showAutoRegisterUI = true; + + protected bool m_showHybridInstancedUI = false; + + protected bool m_useVarSubtitle = false; + + protected bool m_propertyFromInspector; + protected double m_propertyFromInspectorTimestamp; + + protected bool m_checkDuplicateProperty; + protected double m_checkDuplicatePropertyTimestamp; + + protected double m_globalFetchTimestamp; + + protected bool m_delayedDirtyProperty; + protected double m_delayedDirtyPropertyTimestamp; + + protected string m_defaultPropertyName; + protected string m_oldName = string.Empty; + + private bool m_reRegisterName = false; + protected bool m_allowPropertyDuplicates = false; + //protected bool m_useCustomPrefix = false; + protected string m_customPrefix = null; + + protected int m_propertyTab = 0; + + [SerializeField] + private string m_uniqueName; + + // Property Attributes + private const float ButtonLayoutWidth = 15; + + protected bool m_visibleAttribsFoldout; + protected bool m_visibleEnumsFoldout; + protected bool m_visibleCustomAttrFoldout; + protected List<PropertyAttributes> m_availableAttribs = new List<PropertyAttributes>(); + private string[] m_availableAttribsArr; + + [SerializeField] + private bool[] m_selectedAttribsArr; + + [SerializeField] + protected List<int> m_selectedAttribs = new List<int>(); + + //Title editing + protected bool m_isEditing; + protected bool m_stopEditing; + protected bool m_startEditing; + protected double m_clickTime; + protected double m_doubleClickTime = 0.3; + private Rect m_titleClickArea; + + protected bool m_srpBatcherCompatible = false; + protected bool m_excludeUniform = false; + + [SerializeField] + private bool m_addGlobalToSRPBatcher = false; + + public PropertyNode() : base() { } + public PropertyNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_textLabelWidth = 105; + if( UIUtils.CurrentWindow != null && UIUtils.CurrentWindow.CurrentGraph != null ) + m_orderIndex = UIUtils.GetPropertyNodeAmount(); + m_currentParameterType = PropertyType.Constant; + m_freeType = true; + m_freeName = true; + m_propertyNameIsDirty = true; + m_customPrecision = true; + m_availableAttribs.Add( new PropertyAttributes( "Hide in Inspector", "[HideInInspector]" ) ); + m_availableAttribs.Add( new PropertyAttributes( "HDR", "[HDR]" ) ); + m_availableAttribs.Add( new PropertyAttributes( "Gamma", "[Gamma]" ) ); + m_availableAttribs.Add( new PropertyAttributes( "Per Renderer Data", "[PerRendererData]" ) ); + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + + if( PaddingTitleLeft == 0 && m_freeType ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + + m_hasLeftDropdown = m_freeType; + } + + protected void BeginDelayedDirtyProperty() + { + m_delayedDirtyProperty = true; + m_delayedDirtyPropertyTimestamp = EditorApplication.timeSinceStartup; + } + + public void CheckDelayedDirtyProperty() + { + if( m_delayedDirtyProperty ) + { + if( ( EditorApplication.timeSinceStartup - m_delayedDirtyPropertyTimestamp ) > MaxPropertyTimestamp ) + { + m_delayedDirtyProperty = false; + m_propertyNameIsDirty = true; + m_sizeIsDirty = true; + } + } + } + + public void BeginPropertyFromInspectorCheck() + { + m_propertyFromInspector = true; + m_propertyFromInspectorTimestamp = EditorApplication.timeSinceStartup; + } + + public virtual void CheckPropertyFromInspector( bool forceUpdate = false ) + { + if( m_propertyFromInspector ) + { + if( forceUpdate || ( EditorApplication.timeSinceStartup - m_propertyFromInspectorTimestamp ) > MaxTimestamp ) + { + m_propertyFromInspector = false; + bool autoGlobal = m_autoGlobalName || m_currentParameterType == PropertyType.Global; + RegisterPropertyName( true, m_propertyInspectorName, autoGlobal, m_underscoredGlobal ); + m_propertyNameIsDirty = true; + } + } + } + + public void CheckDuplicateProperty() + { + if( m_checkDuplicateProperty && + ( EditorApplication.timeSinceStartup - m_checkDuplicatePropertyTimestamp ) > MaxTimestamp ) + { + m_checkDuplicateProperty = false; + m_propertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, false ); + + if( UIUtils.IsNumericName( m_propertyName ) ) + { + UIUtils.ShowMessage( UniqueId, string.Format("Invalid property name '{0}' as it cannot start with numbers. Reverting to previous name.", m_propertyName ), MessageSeverity.Warning ); + m_propertyName = m_oldName; + GUI.FocusControl( string.Empty ); + return; + } + + if( !m_propertyName.Equals( m_oldName ) ) + { + if( UIUtils.IsUniformNameAvailable( m_propertyName ) || m_allowPropertyDuplicates ) + { + UIUtils.ReleaseUniformName( UniqueId, m_oldName ); + + m_oldName = m_propertyName; + m_propertyNameIsDirty = true; + m_reRegisterName = false; + UIUtils.RegisterUniformName( UniqueId, m_propertyName ); + OnPropertyNameChanged(); + } + else + { + GUI.FocusControl( string.Empty ); + RegisterFirstAvailablePropertyName( true, true ); + UIUtils.ShowMessage( UniqueId, string.Format( "Duplicate property name found on edited node.\nAssigning first valid one {0}", m_propertyName ) ); + } + } + } + } + + protected override void OnUniqueIDAssigned() + { + if( m_variableMode == VariableMode.Create ) + RegisterFirstAvailablePropertyName( false ); + + if( m_nodeAttribs != null ) + m_uniqueName = m_nodeAttribs.Name + UniqueId; + + UIUtils.RegisterRawPropertyNode( this ); + } + + public bool CheckLocalVariable( ref MasterNodeDataCollector dataCollector ) + { + bool addToLocalValue = false; + int count = 0; + for( int i = 0; i < m_outputPorts.Count; i++ ) + { + if( m_outputPorts[ i ].IsConnected ) + { + if( m_outputPorts[ i ].ConnectionCount > 1 ) + { + addToLocalValue = true; + break; + } + count += 1; + if( count > 1 ) + { + addToLocalValue = true; + break; + } + } + } + + if( addToLocalValue ) + { + ConfigureLocalVariable( ref dataCollector ); + } + + return addToLocalValue; + } + + public virtual void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) { } + public virtual void CopyDefaultsToMaterial() { } + + public override void SetupFromCastObject( UnityEngine.Object obj ) + { + RegisterPropertyName( true, obj.name, true, m_underscoredGlobal ); + } + + public void ChangeParameterType( PropertyType parameterType ) + { + Undo.RegisterCompleteObjectUndo( m_containerGraph.ParentWindow, Constants.UndoChangePropertyTypeNodesId ); + Undo.RegisterCompleteObjectUndo( m_containerGraph, Constants.UndoChangePropertyTypeNodesId ); + Undo.RecordObject( this, Constants.UndoChangePropertyTypeNodesId ); + + if( m_currentParameterType == PropertyType.Constant || m_currentParameterType == PropertyType.Global ) + { + CopyDefaultsToMaterial(); + } + + if( parameterType == PropertyType.InstancedProperty ) + { + //if( m_containerGraph.IsSRP ) + //{ + // UIUtils.ShowMessage( InstancedPropertyWarning,MessageSeverity.Warning ); + //} + + UIUtils.CurrentWindow.OutsideGraph.AddInstancePropertyCount(); + } + else if( m_currentParameterType == PropertyType.InstancedProperty ) + { + UIUtils.CurrentWindow.OutsideGraph.RemoveInstancePropertyCount(); + } + + if( ( parameterType == PropertyType.Property || parameterType == PropertyType.InstancedProperty ) + && m_currentParameterType != PropertyType.Property && m_currentParameterType != PropertyType.InstancedProperty ) + { + UIUtils.RegisterPropertyNode( this ); + } + + if( ( parameterType != PropertyType.Property && parameterType != PropertyType.InstancedProperty ) + && ( m_currentParameterType == PropertyType.Property || m_currentParameterType == PropertyType.InstancedProperty ) ) + { + UIUtils.UnregisterPropertyNode( this ); + } + + m_currentParameterType = parameterType; + if( parameterType == PropertyType.Constant ) + { + CurrentVariableMode = VariableMode.Create; + } + + } + + void InitializeAttribsArray() + { + m_availableAttribsArr = new string[ m_availableAttribs.Count ]; + m_selectedAttribsArr = new bool[ m_availableAttribs.Count ]; + for( int i = 0; i < m_availableAttribsArr.Length; i++ ) + { + m_availableAttribsArr[ i ] = m_availableAttribs[ i ].Name; + m_selectedAttribsArr[ i ] = false; + + if( m_selectedAttribs.FindIndex( x => x == i ) > -1 ) + { + m_selectedAttribsArr[ i ] = true; + m_visibleAttribsFoldout = true; + } + } + } + + protected virtual void OnAtrributesChanged() { CheckEnumAttribute(); } + void DrawAttributesAddRemoveButtons() + { + if( m_availableAttribsArr == null ) + { + InitializeAttribsArray(); + } + + int attribCount = m_selectedAttribs.Count; + // Add new port + if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + { + m_visibleAttribsFoldout = true; + m_selectedAttribs.Add( 0 ); + OnAtrributesChanged(); + } + + //Remove port + if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + { + if( attribCount > 0 ) + { + m_selectedAttribs.RemoveAt( attribCount - 1 ); + OnAtrributesChanged(); + } + } + } + + void CheckEnumAttribute() + { + m_hasEnum = false; + foreach( var item in m_selectedAttribs ) + { + if( m_availableAttribsArr[ item ].Equals( "Enum" ) ) + m_hasEnum = true; + } + } + void DrawEnumAddRemoveButtons() + { + // Add new port + if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) && m_enumModeInt == 0 ) + { + m_enumNames.Add( "Option" + ( m_enumValues.Count + 1 ) ); + m_enumValues.Add( m_enumValues.Count ); + m_enumCount++; + m_visibleEnumsFoldout = true; + } + + //Remove port + if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) && m_enumModeInt == 0 ) + { + if( m_enumNames.Count - 1 > -1 ) + { + m_enumNames.RemoveAt( m_enumNames.Count - 1 ); + m_enumValues.RemoveAt( m_enumValues.Count - 1 ); + m_enumCount--; + } + } + } + + protected void DrawEnums() + { + m_enumModeInt = EditorGUILayout.IntPopup( "Mode", m_enumModeInt, EnumModesStr, EnumModeIntValues ); + + if( m_enumModeInt == 0 ) + { + if( m_enumNames.Count == 0 ) + EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info ); + + float cacheLabelSize = EditorGUIUtility.labelWidth; + EditorGUIUtility.labelWidth = 50; + + for( int i = 0; i < m_enumNames.Count; i++ ) + { + EditorGUI.BeginChangeCheck(); + EditorGUILayout.BeginHorizontal(); + m_enumNames[ i ] = EditorGUILayoutTextField( "Name", m_enumNames[ i ] ); + m_enumValues[ i ] = EditorGUILayoutIntField( "Value", m_enumValues[ i ], GUILayout.Width( 100 ) ); + EditorGUILayout.EndHorizontal(); + if( EditorGUI.EndChangeCheck() ) + { + m_enumNames[ i ] = UIUtils.RemoveInvalidEnumCharacters( m_enumNames[ i ] ); + if( string.IsNullOrEmpty( m_enumNames[ i ] ) ) + { + m_enumNames[ i ] = "Option" + ( i + 1 ); + } + } + } + + EditorGUIUtility.labelWidth = cacheLabelSize; + if( m_enumNames.Count > 0 ) + { + EditorGUILayout.BeginHorizontal(); + GUILayout.Label( " " ); + DrawEnumAddRemoveButtons(); + EditorGUILayout.EndHorizontal(); + } + } + else + { + EditorGUILayout.BeginHorizontal(); + m_enumClassName = EditorGUILayoutTextField( "Class Name", m_enumClassName ); + + if( GUILayout.Button( string.Empty, UIUtils.InspectorPopdropdownFallback, GUILayout.Width( 17 ), GUILayout.Height( 19 ) ) ) + { + GenericMenu menu = new GenericMenu(); + AddMenuItem( menu, "UnityEngine.Rendering.CullMode" ); + AddMenuItem( menu, "UnityEngine.Rendering.ColorWriteMask" ); + AddMenuItem( menu, "UnityEngine.Rendering.CompareFunction" ); + AddMenuItem( menu, "UnityEngine.Rendering.StencilOp" ); + AddMenuItem( menu, "UnityEngine.Rendering.BlendMode" ); + AddMenuItem( menu, "UnityEngine.Rendering.BlendOp" ); + menu.ShowAsContext(); + } + EditorGUILayout.EndHorizontal(); + } + } + + private void AddMenuItem( GenericMenu menu, string newClass ) + { + menu.AddItem( new GUIContent( newClass ), m_enumClassName.Equals( newClass ), OnSelection, newClass ); + } + + private void OnSelection( object newClass ) + { + m_enumClassName = (string)newClass; + } + + protected void DrawCustomAttrAddRemoveButtons() + { + // Add new port + if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + { + m_customAttr.Add( "" ); + m_customAttrCount++; + //m_enumCount++; + m_visibleCustomAttrFoldout = true; + } + + //Remove port + if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + { + if( m_customAttr.Count - 1 > -1 ) + { + m_customAttr.RemoveAt( m_customAttr.Count - 1 ); + m_customAttrCount--; + } + } + } + + protected void DrawCustomAttributes() + { + for( int i = 0; i < m_customAttrCount; i++ ) + { + EditorGUI.BeginChangeCheck(); + m_customAttr[ i ] = EditorGUILayoutTextField( "Attribute " + i, m_customAttr[ i ] ); + if( EditorGUI.EndChangeCheck() ) + { + m_customAttr[ i ] = UIUtils.RemoveInvalidAttrCharacters( m_customAttr[ i ] ); + } + } + + if( m_customAttrCount <= 0 ) + { + EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info ); + return; + } + + EditorGUILayout.BeginHorizontal(); + GUILayout.Label( " " ); + DrawCustomAttrAddRemoveButtons(); + EditorGUILayout.EndHorizontal(); + } + + public virtual void DrawAttributes() + { + int attribCount = m_selectedAttribs.Count; + EditorGUI.BeginChangeCheck(); + if( m_availableAttribsArr == null ) + { + InitializeAttribsArray(); + } + for( int i = 0; i < m_availableAttribsArr.Length; i++ ) + { + m_selectedAttribsArr[ i ] = EditorGUILayoutToggleLeft( m_availableAttribsArr[ i ], m_selectedAttribsArr[ i ] ); + } + if( EditorGUI.EndChangeCheck() ) + { + m_selectedAttribs.Clear(); + for( int i = 0; i < m_selectedAttribsArr.Length; i++ ) + { + if( m_selectedAttribsArr[ i ] ) + m_selectedAttribs.Add( i ); + } + + OnAtrributesChanged(); + } + + bool customAttr = EditorGUILayoutToggleLeft( "Custom", m_customAttrCount == 0 ? false : true ); + if( !customAttr ) + { + m_customAttrCount = 0; + } + else if( customAttr && m_customAttrCount < 1 ) + { + if( m_customAttr.Count == 0 ) + m_customAttr.Add( "" ); + + m_customAttrCount = m_customAttr.Count; + } + //m_customAttrCount = EditorGUILayoutToggleLeft( "Custom Attribute", m_customAttrCount == 0 ? false : true ) == 0 ? false : true; + + //if( attribCount == 0 ) + //{ + // EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info ); + //} + + //bool actionAllowed = true; + //int deleteItem = -1; + + //for ( int i = 0; i < attribCount; i++ ) + //{ + // EditorGUI.BeginChangeCheck(); + // { + // m_selectedAttribs[ i ] = EditorGUILayoutPopup( m_selectedAttribs[ i ], m_availableAttribsArr ); + // } + // if ( EditorGUI.EndChangeCheck() ) + // { + // OnAtrributesChanged(); + // } + + // EditorGUILayout.BeginHorizontal(); + // GUILayout.Label( " " ); + // // Add After + // if ( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + // { + // if ( actionAllowed ) + // { + // m_selectedAttribs.Insert( i, m_selectedAttribs[ i ] ); + // actionAllowed = false; + // OnAtrributesChanged(); + // } + // } + + // // Remove Current + // if ( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) ) + // { + // if ( actionAllowed ) + // { + // actionAllowed = false; + // deleteItem = i; + // } + // } + // EditorGUILayout.EndHorizontal(); + //} + //if ( deleteItem > -1 ) + //{ + // m_selectedAttribs.RemoveAt( deleteItem ); + // OnAtrributesChanged(); + //} + } + public virtual void DrawMainPropertyBlock() + { + EditorGUILayout.BeginVertical(); + { + if( m_freeType ) + { + PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType ); + if( parameterType != m_currentParameterType ) + { + ChangeParameterType( parameterType ); + BeginPropertyFromInspectorCheck(); + } + } + + if( m_freeName ) + { + switch( m_currentParameterType ) + { + case PropertyType.Property: + case PropertyType.InstancedProperty: + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( true ); + ShowVariableMode(); + ShowHybridInstanced(); + ShowAutoRegister(); + ShowPrecision(); + ShowToolbar(); + } + break; + case PropertyType.Global: + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( false ); + ShowVariableMode(); + ShowAutoRegister(); + ShowPrecision(); + ShowDefaults(); + } + break; + case PropertyType.Constant: + { + ShowPropertyInspectorNameGUI(); + ShowPrecision(); + ShowDefaults(); + } + break; + } + } + } + EditorGUILayout.EndVertical(); + } + + public void DrawMainPropertyBlockNoPrecision() + { + EditorGUILayout.BeginVertical(); + { + if( m_freeType ) + { + PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType ); + if( parameterType != m_currentParameterType ) + { + ChangeParameterType( parameterType ); + BeginPropertyFromInspectorCheck(); + } + } + + if( m_freeName ) + { + switch( m_currentParameterType ) + { + case PropertyType.Property: + case PropertyType.InstancedProperty: + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( true ); + ShowToolbar(); + } + break; + case PropertyType.Global: + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( false ); + ShowDefaults(); + } + break; + case PropertyType.Constant: + { + ShowPropertyInspectorNameGUI(); + ShowDefaults(); + } + break; + } + } + } + EditorGUILayout.EndVertical(); + } + + public override void DrawProperties() + { + base.DrawProperties(); + if( m_freeType || m_freeName ) + { + NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, DrawMainPropertyBlock ); + if( m_drawAttributes ) + NodeUtils.DrawPropertyGroup( ref m_visibleAttribsFoldout, Constants.AttributesLaberStr, DrawAttributes ); + + if( m_hasEnum ) + { + if( m_enumModeInt == 0 ) + NodeUtils.DrawPropertyGroup( ref m_visibleEnumsFoldout, EnumsStr, DrawEnums, DrawEnumAddRemoveButtons ); + else + NodeUtils.DrawPropertyGroup( ref m_visibleEnumsFoldout, EnumsStr, DrawEnums ); + } + + if( m_drawAttributes && m_customAttrCount > 0 ) + NodeUtils.DrawPropertyGroup( ref m_visibleCustomAttrFoldout, CustomAttrStr, DrawCustomAttributes, DrawCustomAttrAddRemoveButtons ); + + CheckPropertyFromInspector(); + } + } + + public void ShowPrecision() + { + if( m_drawPrecisionUI ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType == PropertyType.Constant || m_variableMode == VariableMode.Create; + EditorGUI.BeginChangeCheck(); + DrawPrecisionProperty(); + if( EditorGUI.EndChangeCheck() ) + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + GUI.enabled = guiEnabled; + + } + } + + public void ShowToolbar() + { + //if ( !CanDrawMaterial ) + //{ + // ShowDefaults(); + // return; + //} + + EditorGUILayout.BeginHorizontal(); + GUILayout.Space( 20 ); + m_propertyTab = GUILayout.Toolbar( m_propertyTab, LabelToolbarTitle ); + EditorGUILayout.EndHorizontal(); + switch( m_propertyTab ) + { + default: + case 0: + { + EditorGUI.BeginChangeCheck(); + DrawMaterialProperties(); + if( EditorGUI.EndChangeCheck() ) + { + BeginDelayedDirtyProperty(); + } + } + break; + case 1: + { + ShowDefaults(); + } + break; + } + } + + public void ShowDefaults() + { + EditorGUI.BeginChangeCheck(); + DrawSubProperties(); + if( EditorGUI.EndChangeCheck() ) + { + BeginDelayedDirtyProperty(); + } + if( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior ) + { + if( DebugConsoleWindow.DeveloperMode ) + { + ShowGlobalValueButton(); + } + EditorGUILayout.HelpBox( GlobalTypeWarningText, MessageType.Warning ); + } + } + + public void ShowPropertyInspectorNameGUI() + { + EditorGUI.BeginChangeCheck(); + m_propertyInspectorName = EditorGUILayoutTextField( PropertyInspectorStr, m_propertyInspectorName ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_propertyInspectorName.Length > 0 ) + { + BeginPropertyFromInspectorCheck(); + } + } + } + + public void ShowPropertyNameGUI( bool isProperty ) + { + bool guiEnabledBuffer = GUI.enabled; + if( isProperty ) + { + EditorGUILayout.BeginHorizontal(); + GUI.enabled = !m_autoGlobalName; + EditorGUI.BeginChangeCheck(); + m_propertyName = EditorGUILayoutTextField( PropertyNameStr, m_propertyName ); + if( EditorGUI.EndChangeCheck() ) + { + //BeginPropertyFromInspectorCheck(); + m_checkDuplicateProperty = true; + m_checkDuplicatePropertyTimestamp = EditorApplication.timeSinceStartup; + } + GUI.enabled = guiEnabledBuffer; + EditorGUI.BeginChangeCheck(); + m_autoGlobalName = GUILayout.Toggle( m_autoGlobalName, ( m_autoGlobalName ? UIUtils.LockIconOpen : UIUtils.LockIconClosed ), "minibutton", GUILayout.Width( 22 ) ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_autoGlobalName ) + BeginPropertyFromInspectorCheck(); + } + EditorGUILayout.EndHorizontal(); + } + else + { + GUI.enabled = false; + m_propertyName = EditorGUILayoutTextField( PropertyNameStr, m_propertyName ); + GUI.enabled = guiEnabledBuffer; + } + } + + public void ShowVariableMode() + { + if( m_showVariableMode || m_freeType ) + CurrentVariableMode = (VariableMode)EditorGUILayoutEnumPopup( IgnoreVarDeclarationStr, m_variableMode ); + } + + public void ShowHybridInstanced() + { + if( m_showHybridInstancedUI && CurrentParameterType == PropertyType.Property && (m_containerGraph.IsSRP || m_containerGraph.CurrentShaderFunction != null) ) + { + m_hybridInstanced = EditorGUILayoutToggle( HybridInstancedStr, m_hybridInstanced ); + } + } + + public void ShowAutoRegister() + { + if( m_showAutoRegisterUI && CurrentParameterType != PropertyType.Constant ) + { + m_autoRegister = EditorGUILayoutToggle( AutoRegisterStr, m_autoRegister ); + } + } + + public virtual string GetPropertyValStr() { return string.Empty; } + + public override bool OnClick( Vector2 currentMousePos2D ) + { + bool singleClick = base.OnClick( currentMousePos2D ); + m_propertyTab = m_materialMode ? 0 : 1; + return singleClick; + } + + public override void OnNodeDoubleClicked( Vector2 currentMousePos2D ) + { + if( currentMousePos2D.y - m_globalPosition.y > ( Constants.NODE_HEADER_HEIGHT + Constants.NODE_HEADER_EXTRA_HEIGHT ) * ContainerGraph.ParentWindow.CameraDrawInfo.InvertedZoom ) + { + ContainerGraph.ParentWindow.ParametersWindow.IsMaximized = !ContainerGraph.ParentWindow.ParametersWindow.IsMaximized; + } + } + + public override void DrawTitle( Rect titlePos ) + { + //base.DrawTitle( titlePos ); + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + // Custom Editable Title + if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 ) + { + if( !m_isEditing && ( ( !ContainerGraph.ParentWindow.MouseInteracted && drawInfo.CurrentEventType == EventType.MouseDown && m_titleClickArea.Contains( drawInfo.MousePosition ) ) ) ) + { + if( ( EditorApplication.timeSinceStartup - m_clickTime ) < m_doubleClickTime ) + m_startEditing = true; + else + GUI.FocusControl( null ); + m_clickTime = EditorApplication.timeSinceStartup; + } + else if( m_isEditing && ( ( drawInfo.CurrentEventType == EventType.MouseDown && !m_titleClickArea.Contains( drawInfo.MousePosition ) ) || !EditorGUIUtility.editingTextField ) ) + { + m_stopEditing = true; + } + + if( m_isEditing || m_startEditing ) + { + EditorGUI.BeginChangeCheck(); + GUI.SetNextControlName( m_uniqueName ); + m_propertyInspectorName = EditorGUITextField( m_titleClickArea, string.Empty, m_propertyInspectorName, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) ); + if( EditorGUI.EndChangeCheck() ) + { + SetClippedTitle( m_propertyInspectorName, m_longNameSize ); + m_sizeIsDirty = true; + m_isDirty = true; + if( m_propertyInspectorName.Length > 0 ) + { + BeginPropertyFromInspectorCheck(); + } + } + + if( m_startEditing ) + EditorGUI.FocusTextInControl( m_uniqueName ); + //if( m_stopEditing ) + // GUI.FocusControl( null ); + } + + if( drawInfo.CurrentEventType == EventType.Repaint ) + { + if( m_startEditing ) + { + m_startEditing = false; + m_isEditing = true; + } + + if( m_stopEditing ) + { + m_stopEditing = false; + m_isEditing = false; + GUI.FocusControl( null ); + } + } + + + if( m_freeType ) + { + if( m_dropdownEditing ) + { + PropertyType parameterType = (PropertyType)EditorGUIEnumPopup( m_dropdownRect, m_currentParameterType, UIUtils.PropertyPopUp ); + if( parameterType != m_currentParameterType ) + { + ChangeParameterType( parameterType ); + BeginPropertyFromInspectorCheck(); + DropdownEditing = false; + } + } + } + } + + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + //base.OnNodeLayout( drawInfo ); + if( m_reRegisterName ) + { + m_reRegisterName = false; + UIUtils.RegisterUniformName( UniqueId, m_propertyName ); + } + + CheckDelayedDirtyProperty(); + + if( m_currentParameterType != m_lastParameterType || m_propertyNameIsDirty ) + { + m_lastParameterType = m_currentParameterType; + m_propertyNameIsDirty = false; + OnDirtyProperty(); + if( m_currentParameterType != PropertyType.Constant ) + { + SetClippedTitle( m_propertyInspectorName, m_longNameSize ); + //bool globalHandler = false; + //if( globalHandler ) + //{ + string currValue = ( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior ) ? "<GLOBAL>" : GetPropertyValStr(); + SetClippedAdditionalTitle( string.Format( m_useVarSubtitle ? Constants.SubTitleVarNameFormatStr : Constants.SubTitleValueFormatStr, currValue ), m_longNameSize, LongNameEnder ); + //} + //else + //{ + // if( m_currentParameterType == PropertyType.Global ) + // { + // SetAdditonalTitleText( "Global" ); + // } + // else + // { + // SetAdditonalTitleText( string.Format( m_useVarSubtitle ? Constants.SubTitleVarNameFormatStr : Constants.SubTitleValueFormatStr, GetPropertyValStr() ) ); + // } + //} + } + else + { + SetClippedTitle( m_propertyInspectorName, m_longNameSize ); + SetClippedAdditionalTitle( string.Format( Constants.SubTitleConstFormatStr, GetPropertyValStr() ), m_longNameSize, LongNameEnder ); + } + } + + CheckPropertyFromInspector(); + CheckDuplicateProperty(); + // RUN LAYOUT CHANGES AFTER TITLES CHANGE + base.OnNodeLayout( drawInfo ); + + m_titleClickArea = m_titlePos; + m_titleClickArea.height = Constants.NODE_HEADER_HEIGHT; + } + + public override void OnNodeRepaint( DrawInfo drawInfo ) + { + base.OnNodeRepaint( drawInfo ); + + if( !m_isVisible ) + return; + + // Fixed Title ( only renders when not editing ) + if( m_showTitleWhenNotEditing && !m_isEditing && !m_startEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 ) + { + GUI.Label( m_titleClickArea, m_content, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) ); + } + } + + public void RegisterFirstAvailablePropertyName( bool releaseOldOne, bool appendIndexToCurrOne = false ) + { + if( releaseOldOne ) + UIUtils.ReleaseUniformName( UniqueId, m_oldName ); + + if( m_isNodeBeingCopied || appendIndexToCurrOne ) + { + if( string.IsNullOrEmpty( m_propertyName ) ) + return; + + string newPropertyName = UIUtils.GetUniqueUniformName( m_propertyName ); + if( newPropertyName != m_propertyName ) + { + UIUtils.RegisterUniformName( UniqueId, newPropertyName ); + m_propertyName = newPropertyName; + } + else + { + if( UIUtils.IsUniformNameAvailable( m_propertyName ) ) + UIUtils.RegisterUniformName( UniqueId, m_propertyName ); + else + UIUtils.GetFirstAvailableName( UniqueId, m_outputPorts[ 0 ].DataType, out m_propertyName, out m_propertyInspectorName, !string.IsNullOrEmpty( m_customPrefix ), m_customPrefix ); + } + + } + else + { + UIUtils.GetFirstAvailableName( UniqueId, m_outputPorts[ 0 ].DataType, out m_propertyName, out m_propertyInspectorName, !string.IsNullOrEmpty( m_customPrefix ), m_customPrefix ); + } + m_oldName = m_propertyName; + m_propertyNameIsDirty = true; + m_reRegisterName = false; + OnPropertyNameChanged(); + } + + public void SetRawPropertyName( string name ) + { + m_propertyName = name; + } + + public void RegisterPropertyName( bool releaseOldOne, string newName, bool autoGlobal = true, bool forceUnderscore = false ) + { + if( m_currentParameterType != PropertyType.Constant && m_variableMode == VariableMode.Fetch ) + { + string localPropertyName = string.Empty; + if( autoGlobal ) + localPropertyName = UIUtils.GeneratePropertyName( newName, m_currentParameterType, forceUnderscore ); + else + { + localPropertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, forceUnderscore ); + if( UIUtils.IsNumericName( localPropertyName ) ) + { + m_propertyName = m_oldName; + } + + } + + m_propertyName = localPropertyName; + m_propertyInspectorName = newName; + m_propertyNameIsDirty = true; + m_reRegisterName = false; + OnPropertyNameChanged(); + return; + } + + string propertyName = string.Empty; + if( autoGlobal ) + propertyName = UIUtils.GeneratePropertyName( newName, m_currentParameterType, forceUnderscore ); + else + { + propertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, forceUnderscore ); + if( UIUtils.IsNumericName( propertyName ) ) + { + m_propertyName = m_oldName; + } + } + + if( m_propertyName.Equals( propertyName ) ) + return; + + if( UIUtils.IsUniformNameAvailable( propertyName ) || m_allowPropertyDuplicates ) + { + if( releaseOldOne ) + UIUtils.ReleaseUniformName( UniqueId, m_oldName ); + + m_oldName = propertyName; + m_propertyName = propertyName; + if( autoGlobal ) + m_propertyInspectorName = newName; + m_propertyNameIsDirty = true; + m_reRegisterName = false; + UIUtils.RegisterUniformName( UniqueId, propertyName ); + OnPropertyNameChanged(); + } + else + { + GUI.FocusControl( string.Empty ); + RegisterFirstAvailablePropertyName( releaseOldOne ); + UIUtils.ShowMessage( UniqueId, string.Format( "Duplicate name found on edited node.\nAssigning first valid one {0}", m_propertyInspectorName ) ); + } + } + + protected string CreateLocalVarDec( string value ) + { + return string.Format( Constants.PropertyLocalVarDec, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName, value ); + } + + public virtual void CheckIfAutoRegister( ref MasterNodeDataCollector dataCollector ) + { + if( CurrentParameterType != PropertyType.Constant && m_autoRegister && m_connStatus != NodeConnectionStatus.Connected ) + { + RegisterProperty( ref dataCollector ); + } + } + + virtual protected void RegisterProperty( ref MasterNodeDataCollector dataCollector ) + { + CheckPropertyFromInspector( true ); + if( m_propertyName.Length == 0 ) + { + RegisterFirstAvailablePropertyName( false ); + } + + switch( CurrentParameterType ) + { + case PropertyType.Property: + { + //Debug.Log( this.GetInstanceID()+" "+ OrderIndex+" "+GetPropertyValue() ); + dataCollector.AddToProperties( UniqueId, GetPropertyValue(), OrderIndex ); + string dataType = string.Empty; + string dataName = string.Empty; + bool fullValue = false; + if( m_variableMode == VariableMode.Create && GetUniformData( out dataType, out dataName, ref fullValue ) ) + { + if( fullValue ) + { + dataCollector.AddToUniforms( UniqueId, dataName, m_srpBatcherCompatible ); + } + else + { + dataCollector.AddToUniforms( UniqueId, dataType, dataName, m_srpBatcherCompatible, m_excludeUniform ); + } + } + + if( m_hybridInstanced && dataCollector.IsTemplate && dataCollector.IsSRP ) + { + dataCollector.AddToDotsProperties( m_outputPorts[ 0 ].DataType, UniqueId, m_propertyName, OrderIndex, CurrentPrecisionType ); + } + //dataCollector.AddToUniforms( m_uniqueId, GetUniformValue() ); + } + break; + case PropertyType.InstancedProperty: + { + dataCollector.AddToPragmas( UniqueId, IOUtils.InstancedPropertiesHeader ); + + if( m_registerPropertyOnInstancing ) + dataCollector.AddToProperties( UniqueId, GetPropertyValue(), OrderIndex ); + + dataCollector.AddToInstancedProperties( m_outputPorts[ 0 ].DataType, UniqueId, GetInstancedUniformValue( dataCollector.IsTemplate, dataCollector.IsSRP ), OrderIndex ); + } + break; + case PropertyType.Global: + { + string dataType = string.Empty; + string dataName = string.Empty; + bool fullValue = false; + if( m_variableMode == VariableMode.Create && GetUniformData( out dataType, out dataName, ref fullValue ) ) + { + if( fullValue ) + { + dataCollector.AddToUniforms( UniqueId, dataName, m_addGlobalToSRPBatcher ); + } + else + { + dataCollector.AddToUniforms( UniqueId, dataType, dataName, m_addGlobalToSRPBatcher, m_excludeUniform ); + } + } + //dataCollector.AddToUniforms( m_uniqueId, GetUniformValue() ); + } + break; + case PropertyType.Constant: break; + } + dataCollector.AddPropertyNode( this ); + if( m_currentParameterType == PropertyType.InstancedProperty && !m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + { + string instancedVar = dataCollector.IsSRP ? + //m_propertyName : + string.Format( IOUtils.LWSRPInstancedPropertiesData, dataCollector.InstanceBlockName, m_propertyName ) : + string.Format( IOUtils.InstancedPropertiesData, m_propertyName ); + + bool insideSF = InsideShaderFunction; + ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph; + if( insideSF ) + ContainerGraph.ParentWindow.CustomGraph = this.ContainerGraph; + + RegisterLocalVariable( 0, instancedVar, ref dataCollector, m_propertyName + "_Instance" ); + + if( insideSF ) + ContainerGraph.ParentWindow.CustomGraph = cachedGraph; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + RegisterProperty( ref dataCollector ); + return string.Empty; + } + + public override void Destroy() + { + base.Destroy(); + UIUtils.UnregisterRawPropertyNode( this ); + if( !string.IsNullOrEmpty( m_propertyName ) && UniqueId >= 0 ) + UIUtils.ReleaseUniformName( UniqueId, m_propertyName ); + + if( m_currentParameterType == PropertyType.InstancedProperty ) + { + UIUtils.CurrentWindow.OutsideGraph.RemoveInstancePropertyCount(); + UIUtils.UnregisterPropertyNode( this ); + } + + if( m_currentParameterType == PropertyType.Property ) + { + UIUtils.UnregisterPropertyNode( this ); + } + + if( m_availableAttribs != null ) + m_availableAttribs.Clear(); + + m_availableAttribs = null; + } + + string BuildEnum() + { + string result = "[Enum("; + if( m_enumModeInt == 0 ) + { + for( int i = 0; i < m_enumNames.Count; i++ ) + { + result += m_enumNames[ i ] + "," + m_enumValues[ i ]; + if( i + 1 < m_enumNames.Count ) + result += ","; + } + } + else + { + result += m_enumClassName; + } + result += ")]"; + return result; + } + + public string PropertyAttributes + { + get + { + int attribCount = m_selectedAttribs.Count; + + if( m_selectedAttribs.Count == 0 && m_customAttrCount == 0 ) + return string.Empty; + + string attribs = string.Empty; + for( int i = 0; i < attribCount; i++ ) + { + if( m_availableAttribs[ m_selectedAttribs[ i ] ].Name.Equals( "Enum" ) ) + attribs += BuildEnum(); + else + attribs += m_availableAttribs[ m_selectedAttribs[ i ] ].Attribute; + } + + for( int i = 0; i < m_customAttrCount; i++ ) + { + if( !string.IsNullOrEmpty( m_customAttr[ i ] ) ) + attribs += "[" + m_customAttr[ i ] + "]"; + } + return attribs; + } + } + public virtual void OnDirtyProperty() { } + public virtual void OnPropertyNameChanged() { UIUtils.UpdatePropertyDataNode( UniqueId, PropertyInspectorName ); } + public virtual void DrawSubProperties() { } + public virtual void DrawMaterialProperties() { } + + public virtual string GetPropertyValue() { return string.Empty; } + + public string GetInstancedUniformValue( bool isTemplate, bool isSRP ) + { + if( isTemplate ) + { + if( isSRP ) + { + return string.Format( IOUtils.LWSRPInstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName ); + //return GetUniformValue(); + } + else + { + return string.Format( IOUtils.InstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName ); + } + } + else + return string.Format( IOUtils.InstancedPropertiesElementTabs, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName ); + } + + public string GetInstancedUniformValue( bool isTemplate, bool isSRP, WirePortDataType dataType, string value ) + { + if( isTemplate ) + { + if( isSRP ) + { + //return GetUniformValue( dataType, value ); + return string.Format( IOUtils.LWSRPInstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value ); + } + else + { + return string.Format( IOUtils.InstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value ); + } + } + else + return string.Format( IOUtils.InstancedPropertiesElementTabs, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value ); + } + + public virtual string GetUniformValue() + { + bool excludeUniformKeyword = ( m_currentParameterType == PropertyType.InstancedProperty ) || + m_containerGraph.IsSRP; + int index = excludeUniformKeyword ? 1 : 0; + return string.Format( Constants.UniformDec[ index ], UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName ); + } + + public string GetUniformValue( WirePortDataType dataType, string value ) + { + bool excludeUniformKeyword = ( m_currentParameterType == PropertyType.InstancedProperty ) || + m_containerGraph.IsSRP; + int index = excludeUniformKeyword ? 1 : 0; + return string.Format( Constants.UniformDec[ index ], UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value ); + } + + public virtual bool GetUniformData( out string dataType, out string dataName, ref bool fullValue ) + { + dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + dataName = m_propertyName; + fullValue = false; + return true; + } + + public PropertyType CurrentParameterType + { + get { return m_currentParameterType; } + set { m_currentParameterType = value; } + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_currentParameterType ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyName ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyInspectorName ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_orderIndex ); + int attribCount = m_selectedAttribs.Count; + IOUtils.AddFieldValueToString( ref nodeInfo, attribCount ); + if( attribCount > 0 ) + { + for( int i = 0; i < attribCount; i++ ) + { + IOUtils.AddFieldValueToString( ref nodeInfo, m_availableAttribs[ m_selectedAttribs[ i ] ].Attribute ); + } + } + IOUtils.AddFieldValueToString( ref nodeInfo, m_variableMode ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoGlobalName ); + + + IOUtils.AddFieldValueToString( ref nodeInfo, m_enumCount ); + for( int i = 0; i < m_enumCount; i++ ) + { + IOUtils.AddFieldValueToString( ref nodeInfo, m_enumNames[ i ] ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_enumValues[ i ] ); + } + IOUtils.AddFieldValueToString( ref nodeInfo, m_enumModeInt ); + if( m_enumModeInt == 1 ) + IOUtils.AddFieldValueToString( ref nodeInfo, m_enumClassName ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRegister ); + + IOUtils.AddFieldValueToString( ref nodeInfo, m_customAttrCount ); + if( m_customAttrCount > 0 ) + { + for( int i = 0; i < m_customAttrCount; i++ ) + { + IOUtils.AddFieldValueToString( ref nodeInfo, m_customAttr[ i ] ); + } + } + + IOUtils.AddFieldValueToString( ref nodeInfo, m_hybridInstanced ); + } + + int IdForAttrib( string name ) + { + int attribCount = m_availableAttribs.Count; + for( int i = 0; i < attribCount; i++ ) + { + if( m_availableAttribs[ i ].Attribute.Equals( name ) ) + return i; + } + return 0; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 2505 ) + { + string property = GetCurrentParam( ref nodeParams ); + m_currentParameterType = property.Equals( "Uniform" ) ? PropertyType.Global : (PropertyType)Enum.Parse( typeof( PropertyType ), property ); + } + else + { + m_currentParameterType = (PropertyType)Enum.Parse( typeof( PropertyType ), GetCurrentParam( ref nodeParams ) ); + } + + if( m_currentParameterType == PropertyType.InstancedProperty ) + { + UIUtils.CurrentWindow.OutsideGraph.AddInstancePropertyCount(); + UIUtils.RegisterPropertyNode( this ); + } + + if( m_currentParameterType == PropertyType.Property ) + { + UIUtils.RegisterPropertyNode( this ); + } + + m_propertyName = GetCurrentParam( ref nodeParams ); + m_propertyInspectorName = GetCurrentParam( ref nodeParams ); + + if( UIUtils.CurrentShaderVersion() > 13 ) + { + m_orderIndex = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + } + + if( UIUtils.CurrentShaderVersion() > 4102 ) + { + int attribAmount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( attribAmount > 0 ) + { + for( int i = 0; i < attribAmount; i++ ) + { + m_selectedAttribs.Add( IdForAttrib( GetCurrentParam( ref nodeParams ) ) ); + } + + m_visibleAttribsFoldout = true; + } + InitializeAttribsArray(); + } + + + if( UIUtils.CurrentShaderVersion() > 14003 ) + { + m_variableMode = (VariableMode)Enum.Parse( typeof( VariableMode ), GetCurrentParam( ref nodeParams ) ); + } + + if( UIUtils.CurrentShaderVersion() > 14201 ) + { + m_autoGlobalName = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + if( UIUtils.CurrentShaderVersion() > 14403 ) + { + m_enumCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + for( int i = 0; i < m_enumCount; i++ ) + { + m_enumNames.Add( GetCurrentParam( ref nodeParams ) ); + m_enumValues.Add( Convert.ToInt32( GetCurrentParam( ref nodeParams ) ) ); + } + } + + if( UIUtils.CurrentShaderVersion() > 14501 ) + { + m_enumModeInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( m_enumModeInt == 1 ) + m_enumClassName = GetCurrentParam( ref nodeParams ); + m_autoRegister = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + + m_customAttrCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + for( int i = 0; i < m_customAttrCount; i++ ) + { + m_customAttr.Add( GetCurrentParam( ref nodeParams ) ); + } + if( m_customAttrCount > 0 ) + { + m_visibleCustomAttrFoldout = true; + m_visibleAttribsFoldout = true; + } + } + + if( UIUtils.CurrentShaderVersion() > 18003 ) + { + m_hybridInstanced = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + + CheckEnumAttribute(); + if( m_enumCount > 0 ) + m_visibleEnumsFoldout = true; + + m_propertyNameIsDirty = true; + m_reRegisterName = false; + + if( !m_isNodeBeingCopied ) + { + if( m_variableMode != VariableMode.Fetch || m_currentParameterType == PropertyType.Constant ) + { + UIUtils.ReleaseUniformName( UniqueId, m_oldName ); + UIUtils.RegisterUniformName( UniqueId, m_propertyName ); + m_oldName = m_propertyName; + } + } + else + { + m_oldName = m_propertyName; + } + + } + + void UpdateTooltip() + { + string currValue = string.Empty; + if( m_currentParameterType != PropertyType.Constant ) + { + currValue = ( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior ) ? "<GLOBAL>" : GetPropertyValStr(); + } + else + { + currValue = GetPropertyValStr(); + } + + m_tooltipText = string.Format( TooltipFormatter, m_nodeAttribs.Description, m_propertyInspectorName, currValue ); + } + + public override void SetClippedTitle( string newText, int maxSize = 170, string endString = "..." ) + { + base.SetClippedTitle( newText, maxSize, endString ); + UpdateTooltip(); + } + + public override void SetClippedAdditionalTitle( string newText, int maxSize = 170, string endString = "..." ) + { + base.SetClippedAdditionalTitle( newText, maxSize, endString ); + UpdateTooltip(); + } + + public override void OnEnable() + { + base.OnEnable(); + m_reRegisterName = true; + } + + public bool CanDrawMaterial { get { return m_materialMode && m_currentParameterType != PropertyType.Constant; } } + public int RawOrderIndex + { + get { return m_orderIndex; } + } + + public int OrderIndex + { + get { return m_orderIndex + m_orderIndexOffset; } + set { m_orderIndex = value; } + } + + public int OrderIndexOffset + { + get { return m_orderIndexOffset; } + set { m_orderIndexOffset = value; } + } + + public VariableMode CurrentVariableMode + { + get { return m_variableMode; } + set + { + if( value != m_variableMode ) + { + m_variableMode = value; + if( value == VariableMode.Fetch ) + { + m_oldName = m_propertyName; + } + else + { + if( !m_propertyName.Equals( m_oldName ) ) + { + if( UIUtils.IsUniformNameAvailable( m_propertyName ) ) + { + UIUtils.ReleaseUniformName( UniqueId, m_oldName ); + UIUtils.RegisterUniformName( UniqueId, m_propertyName ); + } + else + { + UIUtils.ShowMessage( UniqueId, string.Format( FetchToCreateDuplicatesMsg, m_propertyName, m_oldName ), MessageSeverity.Warning ); + m_propertyName = m_oldName; + } + m_propertyNameIsDirty = true; + OnPropertyNameChanged(); + } + else if( UIUtils.CheckUniformNameOwner( m_propertyName ) != UniqueId ) + { + string oldProperty = m_propertyName; + RegisterFirstAvailablePropertyName( false ); + UIUtils.ShowMessage( UniqueId, string.Format( FetchToCreateOnDuplicateNodeMsg, m_propertyName, oldProperty ), MessageSeverity.Warning ); + } + } + } + } + } + + public string PropertyData( MasterNodePortCategory portCategory ) + { + return ( m_currentParameterType == PropertyType.InstancedProperty ) ? m_outputPorts[ 0 ].LocalValue( portCategory ) : m_propertyName; + } + + public override void OnNodeLogicUpdate( DrawInfo drawInfo ) + { + base.OnNodeLogicUpdate( drawInfo ); + if( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior && ( EditorApplication.timeSinceStartup - m_globalFetchTimestamp ) > MaxGlobalFetchTimestamp ) + { + FetchGlobalValue(); + m_globalFetchTimestamp = EditorApplication.timeSinceStartup; + } + } + + public void ShowGlobalValueButton() + { + if( GUILayout.Button( "Set Global Value" ) ) + { + SetGlobalValue(); + } + } + + public override bool CheckFindText( string text ) + { + return base.CheckFindText( text ) || + m_propertyName.IndexOf( text, StringComparison.CurrentCultureIgnoreCase ) >= 0 || + m_propertyInspectorName.IndexOf( text, StringComparison.CurrentCultureIgnoreCase ) >= 0; + } + + //This should only be used on template internal properties + public void PropertyNameFromTemplate( TemplateShaderPropertyData data ) + { + m_propertyName = data.PropertyName; + m_propertyInspectorName = data.PropertyInspectorName; + } + public virtual void GeneratePPSInfo( ref string propertyDeclaration, ref string propertySet ) { } + public virtual void SetGlobalValue() { } + public virtual void FetchGlobalValue() { } + + public virtual string PropertyName { get { return m_propertyName; } } + public virtual string PropertyInspectorName { get { return m_propertyInspectorName; } } + public bool FreeType { get { return m_freeType; } set { m_freeType = value; } } + public bool ReRegisterName { get { return m_reRegisterName; } set { m_reRegisterName = value; } } + public string CustomPrefix { get { return m_customPrefix; } set { m_customPrefix = value; } } + public override void RefreshOnUndo() + { + base.RefreshOnUndo(); + BeginPropertyFromInspectorCheck(); + } + public override string DataToArray { get { return PropertyInspectorName; } } + public bool RegisterPropertyOnInstancing { get { return m_registerPropertyOnInstancing; } set { m_registerPropertyOnInstancing = value; } } + public bool SrpBatcherCompatible { get { return m_srpBatcherCompatible; } } + public bool AddGlobalToSRPBatcher { get { return m_addGlobalToSRPBatcher; } set { m_addGlobalToSRPBatcher = value; } } + public bool AutoRegister { get { return m_autoRegister; } set { m_autoRegister = value; } } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs.meta new file mode 100644 index 00000000..704a2440 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PropertyNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5bbfd66571b12f84983b398231271694 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs new file mode 100644 index 00000000..5c070e2b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs @@ -0,0 +1,530 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Float", "Constants And Properties", "Float property", null, KeyCode.Alpha1 )] + public sealed class RangedFloatNode : PropertyNode + { + private const int OriginalFontSize = 11; + + private const string MinValueStr = "Min"; + private const string MaxValueStr = "Max"; + + private const float LabelWidth = 8; + + [SerializeField] + private float m_defaultValue = 0; + + [SerializeField] + private float m_materialValue = 0; + + [SerializeField] + private float m_min = 0; + + [SerializeField] + private float m_max = 0; + + [SerializeField] + private bool m_floatMode = true; + + private int m_cachedPropertyId = -1; + + private bool m_isEditingFields; + private Vector3 m_previousValue = Vector3.zero; + private string[] m_fieldText = new string[] { "0", "0", "0" }; + + public RangedFloatNode() : base() { } + public RangedFloatNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Float" ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_insideSize.Set( 50, 0 ); + m_showPreview = false; + m_showHybridInstancedUI = true; + m_selectedLocation = PreviewLocation.BottomCenter; + m_availableAttribs.Add( new PropertyAttributes( "Toggle", "[Toggle]" ) ); + m_availableAttribs.Add( new PropertyAttributes( "Int Range", "[IntRange]" ) ); + m_availableAttribs.Add( new PropertyAttributes( "Enum", "[Enum]" ) ); + m_previewShaderGUID = "d9ca47581ac157145bff6f72ac5dd73e"; + m_srpBatcherCompatible = true; + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + UIUtils.RegisterFloatIntNode( this ); + } + + public override void Destroy() + { + base.Destroy(); + UIUtils.UnregisterFloatIntNode( this ); + } + + public override void OnDirtyProperty() + { + UIUtils.UpdateFloatIntDataNode( UniqueId, PropertyInspectorName ); + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + OnPropertyNameChanged(); + OnDirtyProperty(); + } + + public void SetFloatMode( bool value ) + { + if ( m_floatMode == value ) + return; + + m_floatMode = value; + if ( value ) + { + m_insideSize.x = 50;// + ( m_showPreview ? 50 : 0 ); + //m_firstPreviewDraw = true; + } + else + { + m_insideSize.x = 200;// + ( m_showPreview ? 0 : 0 ); + //m_firstPreviewDraw = true; + } + m_sizeIsDirty = true; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + void DrawMinMaxUI() + { + EditorGUI.BeginChangeCheck(); + m_min = EditorGUILayoutFloatField( MinValueStr, m_min ); + m_max = EditorGUILayoutFloatField( MaxValueStr, m_max ); + if ( m_min > m_max ) + m_min = m_max; + + if ( m_max < m_min ) + m_max = m_min; + + if ( EditorGUI.EndChangeCheck() ) + { + SetFloatMode( m_min == m_max ); + } + } + public override void DrawSubProperties() + { + DrawMinMaxUI(); + + if ( m_floatMode ) + { + m_defaultValue = EditorGUILayoutFloatField( Constants.DefaultValueLabel, m_defaultValue ); + } + else + { + m_defaultValue = EditorGUILayoutSlider( Constants.DefaultValueLabel, m_defaultValue, m_min, m_max ); + } + } + + public override void DrawMaterialProperties() + { + DrawMinMaxUI(); + + EditorGUI.BeginChangeCheck(); + + if ( m_floatMode ) + { + m_materialValue = EditorGUILayoutFloatField( Constants.MaterialValueLabel, m_materialValue ); + } + else + { + m_materialValue = EditorGUILayoutSlider( Constants.MaterialValueLabel, m_materialValue, m_min, m_max ); + } + if ( EditorGUI.EndChangeCheck() ) + { + //MarkForPreviewUpdate(); + if ( m_materialMode ) + m_requireMaterialUpdate = true; + } + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if ( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputFloat" ); + + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetFloat( m_cachedPropertyId, m_materialValue ); + else + PreviewMaterial.SetFloat( m_cachedPropertyId, m_defaultValue ); + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + if ( m_floatMode ) + { + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + else + { + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.width = m_outputPorts[ 0 ].Position.x - m_propertyDrawPos.x - (m_outputPorts[ 0 ].LabelSize.x + (Constants.PORT_TO_LABEL_SPACE_X + 3) * drawInfo.InvertedZoom + 2); + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if ( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if ( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if ( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + void DrawFakeFloatMaterial( DrawInfo drawInfo ) + { + if( m_floatMode ) + { + //UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_materialValue, LabelWidth * drawInfo.InvertedZoom ); + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + if( GUI.enabled ) + { + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + } + if( m_previousValue[ 0 ] != m_materialValue ) + { + m_previousValue[ 0 ] = m_materialValue; + m_fieldText[ 0 ] = m_materialValue.ToString(); + } + + GUI.Label( fakeField, m_fieldText[ 0 ], UIUtils.MainSkin.textField ); + } + else + { + DrawFakeSlider( ref m_materialValue, drawInfo ); + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if ( !m_isVisible ) + return; + + if ( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + EditorGUI.BeginChangeCheck(); + if ( m_floatMode ) + { + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_materialValue, LabelWidth * drawInfo.InvertedZoom ); + } + else + { + DrawSlider( ref m_materialValue, drawInfo ); + } + if ( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = true; + if ( m_currentParameterType != PropertyType.Constant ) + { + BeginDelayedDirtyProperty(); + } + } + } + else + { + EditorGUI.BeginChangeCheck(); + + if ( m_floatMode ) + { + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_defaultValue, LabelWidth * drawInfo.InvertedZoom ); + } + else + { + DrawSlider( ref m_defaultValue, drawInfo ); + } + if ( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + BeginDelayedDirtyProperty(); + } + + } + } + else if ( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 ) + { + if( m_currentParameterType == PropertyType.Global ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = false; + DrawFakeFloatMaterial( drawInfo ); + GUI.enabled = guiEnabled; + } + else if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + DrawFakeFloatMaterial( drawInfo ); + } + else + { + if ( m_floatMode ) + { + //UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_defaultValue, LabelWidth * drawInfo.InvertedZoom ); + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + + if ( m_previousValue[ 0 ] != m_defaultValue ) + { + m_previousValue[ 0 ] = m_defaultValue; + m_fieldText[ 0 ] = m_defaultValue.ToString(); + } + + GUI.Label( fakeField, m_fieldText[ 0 ], UIUtils.MainSkin.textField ); + } + else + { + DrawFakeSlider( ref m_defaultValue, drawInfo ); + } + } + } + } + + void DrawFakeSlider( ref float value, DrawInfo drawInfo ) + { + float rangeWidth = 30 * drawInfo.InvertedZoom; + float rangeSpacing = 5 * drawInfo.InvertedZoom; + + //Min + Rect minRect = m_propertyDrawPos; + minRect.width = rangeWidth; + EditorGUIUtility.AddCursorRect( minRect, MouseCursor.Text ); + if ( m_previousValue[ 1 ] != m_min ) + { + m_previousValue[ 1 ] = m_min; + m_fieldText[ 1 ] = m_min.ToString(); + } + GUI.Label( minRect, m_fieldText[ 1 ], UIUtils.MainSkin.textField ); + + //Value Area + Rect valRect = m_propertyDrawPos; + valRect.width = rangeWidth; + valRect.x = m_propertyDrawPos.xMax - rangeWidth - rangeWidth - rangeSpacing; + EditorGUIUtility.AddCursorRect( valRect, MouseCursor.Text ); + if ( m_previousValue[ 0 ] != value ) + { + m_previousValue[ 0 ] = value; + m_fieldText[ 0 ] = value.ToString(); + } + GUI.Label( valRect, m_fieldText[ 0 ], UIUtils.MainSkin.textField ); + + //Max + Rect maxRect = m_propertyDrawPos; + maxRect.width = rangeWidth; + maxRect.x = m_propertyDrawPos.xMax - rangeWidth; + EditorGUIUtility.AddCursorRect( maxRect, MouseCursor.Text ); + if ( m_previousValue[ 2 ] != m_max ) + { + m_previousValue[ 2 ] = m_max; + m_fieldText[ 2 ] = m_max.ToString(); + } + GUI.Label( maxRect, m_fieldText[ 2 ], UIUtils.MainSkin.textField ); + + Rect sliderValRect = m_propertyDrawPos; + sliderValRect.x = minRect.xMax + rangeSpacing; + sliderValRect.xMax = valRect.xMin - rangeSpacing; + Rect sliderBackRect = sliderValRect; + sliderBackRect.height = 5 * drawInfo.InvertedZoom; + sliderBackRect.center = new Vector2( sliderValRect.center.x, Mathf.Round( sliderValRect.center.y ) ); + + + GUI.Label( sliderBackRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SliderStyle ) ); + + sliderValRect.width = 10; + float percent = ( value - m_min) / ( m_max-m_min ); + percent = Mathf.Clamp01( percent ); + sliderValRect.x += percent * (sliderBackRect.width - 10 * drawInfo.InvertedZoom ); + GUI.Label( sliderValRect, string.Empty, UIUtils.RangedFloatSliderThumbStyle ); + } + + void DrawSlider( ref float value, DrawInfo drawInfo ) + { + float rangeWidth = 30 * drawInfo.InvertedZoom; + float rangeSpacing = 5 * drawInfo.InvertedZoom; + + //Min + Rect minRect = m_propertyDrawPos; + minRect.width = rangeWidth; + m_min = EditorGUIFloatField( minRect, m_min, UIUtils.MainSkin.textField ); + + //Value Area + Rect valRect = m_propertyDrawPos; + valRect.width = rangeWidth; + valRect.x = m_propertyDrawPos.xMax - rangeWidth - rangeWidth - rangeSpacing; + value = EditorGUIFloatField( valRect, value, UIUtils.MainSkin.textField ); + + //Max + Rect maxRect = m_propertyDrawPos; + maxRect.width = rangeWidth; + maxRect.x = m_propertyDrawPos.xMax - rangeWidth; + m_max = EditorGUIFloatField( maxRect, m_max, UIUtils.MainSkin.textField ); + + //Value Slider + Rect sliderValRect = m_propertyDrawPos; + sliderValRect.x = minRect.xMax + rangeSpacing; + sliderValRect.xMax = valRect.xMin - rangeSpacing; + Rect sliderBackRect = sliderValRect; + sliderBackRect.height = 5 * drawInfo.InvertedZoom; + sliderBackRect.center = new Vector2( sliderValRect.center.x, Mathf.Round( sliderValRect.center.y )); + GUI.Label( sliderBackRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SliderStyle ) ); + value = GUIHorizontalSlider( sliderValRect, value, m_min, m_max, GUIStyle.none, UIUtils.RangedFloatSliderThumbStyle ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if ( m_currentParameterType != PropertyType.Constant ) + return PropertyData( dataCollector.PortCategory ); + + return IOUtils.Floatify( m_defaultValue ); + } + + public override string GetPropertyValue() + { + if ( m_floatMode ) + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Float) = " + m_defaultValue; + } + else + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Range( " + m_min + " , " + m_max + ")) = " + m_defaultValue; + } + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetFloat( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat , bool fetchMaterialValues ) + { + base.SetMaterialMode( mat , fetchMaterialValues ); + if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetFloat( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetFloat( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + { + m_materialValue = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + } + + m_min = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + m_max = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + SetFloatMode( m_min == m_max ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_materialValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_min ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_max ); + } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? + m_materialValue.ToString( Mathf.Abs( m_materialValue ) > 1000 ? Constants.PropertyBigFloatFormatLabel : Constants.PropertyFloatFormatLabel ) : + m_defaultValue.ToString( Mathf.Abs( m_defaultValue ) > 1000 ? Constants.PropertyBigFloatFormatLabel : Constants.PropertyFloatFormatLabel ); + } + + public override void SetGlobalValue() { Shader.SetGlobalFloat( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalFloat( m_propertyName ); } + public float Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + + public void SetMaterialValueFromInline( float val ) + { + m_materialValue = val; + m_requireMaterialUpdate = true; + } + public override void GeneratePPSInfo( ref string propertyDeclaration, ref string propertySet ) + { + string additionalHeaders = string.Empty; + if( !m_floatMode ) + { + additionalHeaders = string.Format( "Range( {0}, {1} ),", m_min, m_max ); + } + propertyDeclaration += string.Format( ASEPPSHelperTool.PPSPropertyDecFormat, additionalHeaders, PropertyInspectorName, + ASEPPSHelperTool.WireToPPSType[ WirePortDataType.FLOAT ], PropertyName, m_defaultValue ); + + propertySet += string.Format( ASEPPSHelperTool.PPSPropertySetFormat, "Float", PropertyName ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs.meta new file mode 100644 index 00000000..dbf3243f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/RangedFloatNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e81453c5ad3b8224db874b56bf00cad2 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables.meta new file mode 100644 index 00000000..22447d40 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 92f993d3ba8b1394eaf8c4fe308cab11 +folderAsset: yes +timeCreated: 1481126946 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen.meta new file mode 100644 index 00000000..e1fbf68d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8c4b0845954941d4d9809abaa67bdc2b +folderAsset: yes +timeCreated: 1481126947 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs new file mode 100644 index 00000000..0591ba12 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs @@ -0,0 +1,100 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + public enum BuiltInShaderCameraTypes + { + unity_CameraProjection = 0, + unity_CameraInvProjection + } + + [Serializable] + [NodeAttributes( "Projection Matrices", "Camera And Screen", "Camera's Projection/Inverse Projection matrix" )] + public sealed class CameraProjectionNode : ShaderVariablesNode + { + private const string _projMatrixLabelStr = "Projection Matrix"; + private readonly string[] _projMatrixValuesStr = { "Camera Projection", + "Inverse Camera Projection"}; + + + [SerializeField] + private BuiltInShaderCameraTypes m_selectedType = BuiltInShaderCameraTypes.unity_CameraProjection; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, _projMatrixValuesStr[ (int)m_selectedType ], WirePortDataType.FLOAT4x4 ); + m_textLabelWidth = 115; + m_autoWrapProperties = true; + m_hasLeftDropdown = true; + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + if( PaddingTitleLeft == 0 ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + } + + public override void Destroy() + { + base.Destroy(); + m_upperLeftWidget = null; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + EditorGUI.BeginChangeCheck(); + m_selectedType = (BuiltInShaderCameraTypes)m_upperLeftWidget.DrawWidget( this, (int)m_selectedType, _projMatrixValuesStr ); + if( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] ); + SetSaveIsDirty(); + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_selectedType = (BuiltInShaderCameraTypes)EditorGUILayoutPopup( _projMatrixLabelStr, (int)m_selectedType, _projMatrixValuesStr ); + if( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] ); + SetSaveIsDirty(); + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ); + return m_selectedType.ToString(); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_selectedType = (BuiltInShaderCameraTypes)Enum.Parse( typeof( BuiltInShaderCameraTypes ), GetCurrentParam( ref nodeParams ) ); + ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs.meta new file mode 100644 index 00000000..11a1c16b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraProjectionNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f776bdd36b750304c8e0de8ee1f31fc0 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs new file mode 100644 index 00000000..fd23099e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs @@ -0,0 +1,115 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + public enum BuiltInShaderClipPlanesTypes + { + Left = 0, + Right, + Bottom, + Top, + Near, + Far + } + + [Serializable] + [NodeAttributes( "Clip Planes", "Camera And Screen", "Camera World Clip Planes" )] + public sealed class CameraWorldClipPlanes : ShaderVariablesNode + { + [SerializeField] + private BuiltInShaderClipPlanesTypes m_selectedType = BuiltInShaderClipPlanesTypes.Left; + + private const string LabelStr = "Plane"; + private const string ValueStr = "unity_CameraWorldClipPlanes"; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + private int m_planeId; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "ABCD", WirePortDataType.FLOAT4 ); + m_textLabelWidth = 55; + m_autoWrapProperties = true; + m_hasLeftDropdown = true; + SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) ); + m_previewShaderGUID = "6afe5a4ad7bbd0e4ab352c758f543a09"; + } + + public override void OnEnable() + { + base.OnEnable(); + m_planeId = Shader.PropertyToID( "_PlaneId" ); + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + if( PaddingTitleLeft == 0 ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + } + + public override void Destroy() + { + base.Destroy(); + m_upperLeftWidget = null; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + m_upperLeftWidget.DrawWidget<BuiltInShaderClipPlanesTypes>(ref m_selectedType, this, OnWidgetUpdate ); + } + + private readonly Action<ParentNode> OnWidgetUpdate = ( x ) => { + x.SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, ( x as CameraWorldClipPlanes ).Type ) ); + }; + + public BuiltInShaderClipPlanesTypes Type { get { return m_selectedType; } } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_selectedType = ( BuiltInShaderClipPlanesTypes ) EditorGUILayoutEnumPopup( LabelStr, m_selectedType ); + if ( EditorGUI.EndChangeCheck() ) + { + SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) ); + SetSaveIsDirty(); + } + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + PreviewMaterial.SetInt( m_planeId, (int)m_selectedType ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + return ValueStr + "[" + ( int ) m_selectedType + "]"; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_selectedType = ( BuiltInShaderClipPlanesTypes ) Enum.Parse( typeof( BuiltInShaderClipPlanesTypes ), GetCurrentParam( ref nodeParams ) ); + SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs.meta new file mode 100644 index 00000000..3b17b846 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/CameraWorldClipPlanes.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e5a9a010f1c8dda449c8ca7ee9e25869 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs new file mode 100644 index 00000000..c2e93c26 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs @@ -0,0 +1,38 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Ortho Params", "Camera And Screen", "Orthographic Parameters" )] + public sealed class OrthoParams : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "Ortho Cam Width" ); + ChangeOutputName( 2, "Ortho Cam Height" ); + ChangeOutputName( 3, "Unused" ); + ChangeOutputName( 4, "Projection Mode" ); + m_value = "unity_OrthoParams"; + m_previewShaderGUID = "88a910ece3dce224793e669bb1bc158d"; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + + if( !m_outputPorts[ 3 ].IsConnected ) + { + m_outputPorts[ 3 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs.meta new file mode 100644 index 00000000..d406a63e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/OrthoParams.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f9431cdf8e81c1d4f902b3fa7d04f7ac +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs new file mode 100644 index 00000000..9e4357b7 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Projection Params", "Camera And Screen", "Projection Near/Far parameters" )] + public sealed class ProjectionParams : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "Flipped" ); + ChangeOutputName( 2, "Near Plane" ); + ChangeOutputName( 3, "Far Plane" ); + ChangeOutputName( 4, "1/Far Plane" ); + m_value = "_ProjectionParams"; + m_previewShaderGUID = "97ae846cb0a6b044388fad3bc03bb4c2"; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs.meta new file mode 100644 index 00000000..8e87d5a2 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ProjectionParams.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ba1ca8bace2c2dd4dafac6f73f4dfb1b +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs new file mode 100644 index 00000000..5446ac2f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Screen Params", "Camera And Screen", "Camera's Render Target size parameters" )] + public sealed class ScreenParams : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "RT Width" ); + ChangeOutputName( 2, "RT Height" ); + ChangeOutputName( 3, "1+1/Width" ); + ChangeOutputName( 4, "1+1/Height" ); + m_value = "_ScreenParams"; + m_previewShaderGUID = "78173633b803de4419206191fed3d61e"; + } + + //public override void RefreshExternalReferences() + //{ + // base.RefreshExternalReferences(); + // if( !m_outputPorts[ 0 ].IsConnected ) + // { + // m_outputPorts[ 0 ].Visible = false; + // m_sizeIsDirty = true; + // } + //} + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs.meta new file mode 100644 index 00000000..f43db824 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ScreenParams.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2e593f23857d59643b5b5f6dd6264e1b +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs new file mode 100644 index 00000000..2342f158 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs @@ -0,0 +1,28 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "World Space Camera Pos", "Camera And Screen", "World Space Camera position" )] + public sealed class WorldSpaceCameraPos : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "XYZ", WirePortDataType.FLOAT3 ); + AddOutputPort( WirePortDataType.FLOAT, "X" ); + AddOutputPort( WirePortDataType.FLOAT, "Y" ); + AddOutputPort( WirePortDataType.FLOAT, "Z" ); + + m_value = "_WorldSpaceCameraPos"; + m_previewShaderGUID = "6b0c78411043dd24dac1152c84bb63ba"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + return GetOutputVectorItem( 0, outputId, base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ) ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs.meta new file mode 100644 index 00000000..8a47447f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/WorldSpaceCameraPos.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 972d92a6008896f4292a61726e18f667 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs new file mode 100644 index 00000000..4fcb5e19 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs @@ -0,0 +1,31 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Z-Buffer Params", "Camera And Screen", "Linearized Z buffer values" )] + public sealed class ZBufferParams : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "1-far/near" ); + ChangeOutputName( 2, "far/near" ); + ChangeOutputName( 3, "[0]/far" ); + ChangeOutputName( 4, "[1]/far" ); + m_value = "_ZBufferParams"; + m_previewShaderGUID = "56c42c106bcb497439187f5bb6b6f94d"; + } + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs.meta new file mode 100644 index 00000000..e8b668c8 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/CameraAndScreen/ZBufferParams.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2765a41106f478f4982e859b978bdec4 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs new file mode 100644 index 00000000..d74d8a5f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs @@ -0,0 +1,39 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + public class ConstVecShaderVariable : ShaderVariablesNode + { + [SerializeField] + protected string m_value; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, " ", WirePortDataType.FLOAT4 ); + AddOutputPort( WirePortDataType.FLOAT, "0" ); + AddOutputPort( WirePortDataType.FLOAT, "1" ); + AddOutputPort( WirePortDataType.FLOAT, "2" ); + AddOutputPort( WirePortDataType.FLOAT, "3" ); + } + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + switch ( outputId ) + { + case 0: return m_value; + case 1: return ( m_value + ".x" ); + case 2: return ( m_value + ".y" ); + case 3: return ( m_value + ".z" ); + case 4: return ( m_value + ".w" ); + } + + UIUtils.ShowMessage( UniqueId, "ConstVecShaderVariable generating empty code", MessageSeverity.Warning ); + return string.Empty; + } + + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs.meta new file mode 100644 index 00000000..97976c8a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstVecShaderVariable.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9102c0b554fd5ad4785acf870dcc17eb +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs new file mode 100644 index 00000000..ff6279e7 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs @@ -0,0 +1,35 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + public class ConstantShaderVariable : ShaderVariablesNode + { + [SerializeField] + protected string m_value; + + [SerializeField] + protected string m_HDValue = string.Empty; + + [SerializeField] + protected string m_LWValue = string.Empty; + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + if( dataCollector.IsTemplate ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_HDValue ) ) + return m_HDValue; + + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_LWValue )) + return m_LWValue; + } + return m_value; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs.meta new file mode 100644 index 00000000..55110165 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ConstantShaderVariable.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 266391c3c4308014e9ce246e5484b917 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient.meta new file mode 100644 index 00000000..e0c69e86 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 78eb7b1e34d423c40a949c9e75b5f24a +folderAsset: yes +timeCreated: 1481126946 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs new file mode 100644 index 00000000..2af78f78 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs @@ -0,0 +1,126 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + public enum BuiltInFogAndAmbientColors + { + UNITY_LIGHTMODEL_AMBIENT = 0, + unity_AmbientSky, + unity_AmbientEquator, + unity_AmbientGround, + unity_FogColor + } + + [Serializable] + [NodeAttributes( "Fog And Ambient Colors", "Light", "Fog and Ambient colors" )] + public sealed class FogAndAmbientColorsNode : ShaderVariablesNode + { + private const string ColorLabelStr = "Color"; + private readonly string[] ColorValuesStr = { + "Ambient light ( Legacy )", + "Sky ambient light", + "Equator ambient light", + "Ground ambient light", + "Fog" + }; + + [SerializeField] + private BuiltInFogAndAmbientColors m_selectedType = BuiltInFogAndAmbientColors.UNITY_LIGHTMODEL_AMBIENT; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, ColorValuesStr[ ( int ) m_selectedType ], WirePortDataType.COLOR ); + m_textLabelWidth = 50; + m_autoWrapProperties = true; + m_hasLeftDropdown = true; + m_previewShaderGUID = "937c7bde062f0f942b600d9950d2ebb2"; + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + if( PaddingTitleLeft == 0 ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + m_previewMaterialPassId = (int)m_selectedType; + } + + public override void Destroy() + { + base.Destroy(); + m_upperLeftWidget = null; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + EditorGUI.BeginChangeCheck(); + m_selectedType = (BuiltInFogAndAmbientColors)m_upperLeftWidget.DrawWidget( this, (int)m_selectedType, ColorValuesStr ); + if( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, ColorValuesStr[ (int)m_selectedType ] ); + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_selectedType = ( BuiltInFogAndAmbientColors ) EditorGUILayoutPopup( ColorLabelStr, ( int ) m_selectedType, ColorValuesStr ); + + if ( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, ColorValuesStr[ ( int ) m_selectedType ] ); + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + if( dataCollector.IsTemplate && dataCollector.CurrentSRPType == TemplateSRPType.HD ) + { + switch( m_selectedType ) + { + case BuiltInFogAndAmbientColors.unity_AmbientSky: + return "_Ambient_ColorSky"; + case BuiltInFogAndAmbientColors.unity_AmbientEquator: + return "_Ambient_Equator"; + case BuiltInFogAndAmbientColors.unity_AmbientGround: + return "_Ambient_Ground"; + case BuiltInFogAndAmbientColors.unity_FogColor: + return "_FogColor"; + } + } + return m_selectedType.ToString(); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_selectedType = ( BuiltInFogAndAmbientColors ) Enum.Parse( typeof( BuiltInFogAndAmbientColors ), GetCurrentParam( ref nodeParams ) ); + ChangeOutputName( 0, ColorValuesStr[ ( int ) m_selectedType ] ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs.meta new file mode 100644 index 00000000..f2ab7d02 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogAndAmbientColorsNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e2bdfc2fa6fcd0640b01a8b7448a1a11 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs new file mode 100644 index 00000000..63a635d1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Fog Params", "Light", "Parameters for fog calculation" )] + public sealed class FogParamsNode : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "Density/Sqrt(Ln(2))" ); + ChangeOutputName( 2, "Density/Ln(2)" ); + ChangeOutputName( 3, "-1/(End-Start)" ); + ChangeOutputName( 4, "End/(End-Start))" ); + m_value = "unity_FogParams"; + m_previewShaderGUID = "42abde3281b1848438c3b53443c91a1e"; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs.meta new file mode 100644 index 00000000..ccc0df5e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/FogAndAmbient/FogParamsNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a3d8c31159e07bc419a7484ab5e894ed +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting.meta new file mode 100644 index 00000000..86287e65 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 47f503bcb5935b649beee3296dd40260 +folderAsset: yes +timeCreated: 1481126946 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs new file mode 100644 index 00000000..d985714c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs @@ -0,0 +1,197 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + + public enum ASEStandardSurfaceWorkflow + { + Metallic = 0, + Specular + } + + [Serializable] + [NodeAttributes( "Standard Surface Light", "Light", "Provides a way to create a standard surface light model in custom lighting mode", NodeAvailabilityFlags = (int)NodeAvailability.CustomLighting )] + public sealed class CustomStandardSurface : ParentNode + { + private const string WorkflowStr = "Workflow"; + + [SerializeField] + private ASEStandardSurfaceWorkflow m_workflow = ASEStandardSurfaceWorkflow.Metallic; + + [SerializeField] + private ViewSpace m_normalSpace = ViewSpace.Tangent; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, "Albedo" ); + AddInputPort( WirePortDataType.FLOAT3, false, "Normal" ); + m_inputPorts[ 1 ].Vector3InternalData = Vector3.forward; + AddInputPort( WirePortDataType.FLOAT3, false, "Emission" ); + AddInputPort( WirePortDataType.FLOAT, false, "Metallic" ); + AddInputPort( WirePortDataType.FLOAT, false, "Smoothness" ); + AddInputPort( WirePortDataType.FLOAT, false, "Occlusion" ); + m_inputPorts[ 5 ].FloatInternalData = 1; + AddOutputPort( WirePortDataType.FLOAT3, "RGB" ); + m_autoWrapProperties = true; + m_textLabelWidth = 100; + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = "This node only returns correct information using a custom light model, otherwise returns 0"; + } + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + if( m_inputPorts[ 1 ].IsConnected && m_normalSpace == ViewSpace.Tangent ) + dataCollector.DirtyNormal = true; + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_workflow = (ASEStandardSurfaceWorkflow)EditorGUILayoutEnumPopup( WorkflowStr, m_workflow ); + if( EditorGUI.EndChangeCheck() ) + { + UpdateSpecularMetallicPorts(); + } + + EditorGUI.BeginChangeCheck(); + m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace ); + if( EditorGUI.EndChangeCheck() ) + { + UpdatePort(); + } + } + + private void UpdatePort() + { + if( m_normalSpace == ViewSpace.World ) + m_inputPorts[ 1 ].Name = "World Normal"; + else + m_inputPorts[ 1 ].Name = "Normal"; + + m_sizeIsDirty = true; + } + + void UpdateSpecularMetallicPorts() + { + if( m_workflow == ASEStandardSurfaceWorkflow.Specular ) + m_inputPorts[ 3 ].ChangeProperties( "Specular", WirePortDataType.FLOAT3, false ); + else + m_inputPorts[ 3 ].ChangeProperties( "Metallic", WirePortDataType.FLOAT, false ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting ) + return "float3(0,0,0)"; + + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + string specularMode = string.Empty; + if( m_workflow == ASEStandardSurfaceWorkflow.Specular ) + specularMode = "Specular"; + + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + + if( dataCollector.DirtyNormal ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + dataCollector.ForceNormal = true; + } + + dataCollector.AddLocalVariable( UniqueId, "SurfaceOutputStandard" + specularMode + " s" + OutputId + " = (SurfaceOutputStandard" + specularMode + " ) 0;" ); + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Albedo = " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + ";" ); + + string normal = string.Empty; + + if( m_inputPorts[ 1 ].IsConnected ) + { + normal = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + if( m_normalSpace == ViewSpace.Tangent ) + { + normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )"; + } + } + else + { + normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ); + } + + + + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Normal = "+ normal + ";" ); + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Emission = " + m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ) + ";" ); + if( m_workflow == ASEStandardSurfaceWorkflow.Specular ) + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Specular = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ";" ); + else + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Metallic = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ";" ); + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Smoothness = " + m_inputPorts[ 4 ].GeneratePortInstructions( ref dataCollector ) + ";" ); + dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Occlusion = " + m_inputPorts[ 5 ].GeneratePortInstructions( ref dataCollector ) + ";\n" ); + + dataCollector.AddLocalVariable( UniqueId, "data.light = gi.light;\n", true ); + + dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi;" ); + dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDBASE", true ); + + dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( s" + OutputId + ".Smoothness, data.worldViewDir, s" + OutputId + ".Normal, float3(0,0,0));" ); + dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGlobalIllumination( data, s" + OutputId + ".Occlusion, s" + OutputId + ".Normal, g" + OutputId + " );" ); + dataCollector.AddLocalVariable( UniqueId, "#endif\n", true ); + dataCollector.AddLocalVariable( UniqueId, "float3 surfResult" + OutputId + " = LightingStandard" + specularMode + " ( s" + OutputId + ", viewDir, gi" + OutputId + " ).rgb;" ); + //Emission must be always added to trick Unity, so it knows what needs to be created p.e. world pos + dataCollector.AddLocalVariable( UniqueId, "surfResult" + OutputId + " += s" + OutputId + ".Emission;\n" ); + + m_outputPorts[ 0 ].SetLocalValue( "surfResult" + OutputId, dataCollector.PortCategory ); + + //Remove emission contribution from Forward Add + dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDADD//" + OutputId ); + dataCollector.AddLocalVariable( UniqueId, string.Format( "surfResult{0} -= s{0}.Emission;", OutputId )); + dataCollector.AddLocalVariable( UniqueId, "#endif//" + OutputId ); + + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader || ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) ) + m_showErrorMessage = true; + else + m_showErrorMessage = false; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 13204 ) + { + m_workflow = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ) ? ASEStandardSurfaceWorkflow.Specular : ASEStandardSurfaceWorkflow.Metallic; + } + else + { + m_workflow = (ASEStandardSurfaceWorkflow)Enum.Parse( typeof( ASEStandardSurfaceWorkflow ), GetCurrentParam( ref nodeParams ) ); + } + UpdateSpecularMetallicPorts(); + + if( UIUtils.CurrentShaderVersion() >= 14402 ) + { + m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) ); + } + UpdatePort(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_workflow ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta new file mode 100644 index 00000000..172f37cd --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 78916999fd7bc3c4e9767bc9cf0698c0 +timeCreated: 1500054866 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs new file mode 100644 index 00000000..c58da735 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs @@ -0,0 +1,366 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Indirect Diffuse Light", "Light", "Indirect Lighting", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )] + public sealed class IndirectDiffuseLighting : ParentNode + { + [SerializeField] + private ViewSpace m_normalSpace = ViewSpace.Tangent; + + private int m_cachedIntensityId = -1; + + + private readonly string LWIndirectDiffuseHeader = "ASEIndirectDiffuse( {0}, {1})"; + private readonly string[] LWIndirectDiffuseBody = + { + "float3 ASEIndirectDiffuse( float2 uvStaticLightmap, float3 normalWS )\n", + "{\n", + "#ifdef LIGHTMAP_ON\n", + "\treturn SampleLightmap( uvStaticLightmap, normalWS );\n", + "#else\n", + "\treturn SampleSH(normalWS);\n", + "#endif\n", + "}\n" + }; + + + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, "Normal" ); + AddOutputPort( WirePortDataType.FLOAT3, "RGB" ); + m_inputPorts[ 0 ].Vector3InternalData = Vector3.forward; + m_autoWrapProperties = true; + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = "This node only returns correct information using a custom light model, otherwise returns 0"; + m_previewShaderGUID = "b45d57fa606c1ea438fe9a2c08426bc7"; + m_drawPreviewAsSphere = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + m_previewMaterialPassId = 1; + else + m_previewMaterialPassId = 2; + } + else + { + m_previewMaterialPassId = 0; + } + + if( m_cachedIntensityId == -1 ) + m_cachedIntensityId = Shader.PropertyToID( "_Intensity" ); + + PreviewMaterial.SetFloat( m_cachedIntensityId, RenderSettings.ambientIntensity ); + } + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + // This needs to be rechecked + //if( m_inputPorts[ 0 ].IsConnected ) + dataCollector.DirtyNormal = true; + } + + public override void DrawProperties() + { + base.DrawProperties(); + + EditorGUI.BeginChangeCheck(); + m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace ); + if( EditorGUI.EndChangeCheck() ) + { + UpdatePort(); + } + } + + private void UpdatePort() + { + if( m_normalSpace == ViewSpace.World ) + m_inputPorts[ 0 ].ChangeProperties( "World Normal", m_inputPorts[ 0 ].DataType, false ); + else + m_inputPorts[ 0 ].ChangeProperties( "Normal", m_inputPorts[ 0 ].DataType, false ); + + m_sizeIsDirty = true; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) ) + m_showErrorMessage = true; + else + m_showErrorMessage = false; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + string finalValue = string.Empty; + + if( dataCollector.IsTemplate && dataCollector.IsFragmentCategory ) + { + if( !dataCollector.IsSRP ) + { + dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib ); + + string texcoord1 = string.Empty; + string texcoord2 = string.Empty; + + if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) ) + texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName; + else + texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ); + + if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) ) + texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName; + else + texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false ); + + string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName; + string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName; + TemplateVertexData data = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lmap" ); + + string varName = "ase_lmap"; + if( data != null ) + varName = data.VarName; + + dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef DYNAMICLIGHTMAP_ON //dynlm" ); + dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //dynlm" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef LIGHTMAP_ON //stalm" ); + dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw;" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //stalm" ); + + TemplateVertexData shdata = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT3, false, "ase_sh" ); + string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Vertex ); + string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex ); + //Debug.Log( shdata ); + string shVarName = "ase_sh"; + if( shdata != null ) + shVarName = shdata.VarName; + string outSH = vOutName + "." + shVarName + ".xyz"; + dataCollector.AddToVertexLocalVariables( UniqueId, "#ifndef LIGHTMAP_ON //nstalm" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //sh" ); + dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = 0;" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef VERTEXLIGHT_ON //vl" ); + dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " += Shade4PointLights (" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0," ); + dataCollector.AddToVertexLocalVariables( UniqueId, "unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb," ); + dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightAtten0, " + worldPos + ", " + worldNormal + ");" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //vl" ); + dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = ShadeSHPerVertex (" + worldNormal + ", " + outSH + ");" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //sh" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //nstalm" ); + + //dataCollector.AddToPragmas( UniqueId, "multi_compile_fwdbase" ); + + string fragWorldNormal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ); + else + fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + else + { + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ); + } + + dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data" + OutputId + ";" ); + dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data" + OutputId + " );" ); + + dataCollector.AddLocalVariable( UniqueId, "#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) //dylm" + OutputId ); + dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".lightmapUV = " + fInName + "." + varName + ";" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //dylm" + OutputId ); + + dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //fsh" + OutputId ); + dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".ambient = " + fInName + "." + shVarName + ";" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //fsh" + OutputId ); + + dataCollector.AddToLocalVariables( UniqueId, "UnityGI gi" + OutputId + " = UnityGI_Base(data" + OutputId + ", 1, " + fragWorldNormal + ");" ); + + finalValue = "gi" + OutputId + ".indirect.diffuse"; + m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ); + return finalValue; + } + else + { + if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight ) + { + string texcoord1 = string.Empty; + + if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) ) + texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName; + else + texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ); + + string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName; + string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName; + + + if( !dataCollector.TemplateDataCollectorInstance.HasRawInterpolatorOfName( "lightmapUVOrVertexSH" ) ) + { + string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex ); + dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "lightmapUVOrVertexSH" ); + + dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_LIGHTMAP_UV( " + texcoord1 + ", unity_LightmapST, " + vOutName + ".lightmapUVOrVertexSH.xy );" ); + dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_SH( " + worldNormal + ", " + vOutName + ".lightmapUVOrVertexSH.xyz );" ); + + dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" ); + dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" ); + } + + string fragWorldNormal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ); + else + fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + else + { + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ); + } + + //SAMPLE_GI + + //This function may not do full pixel and does not behave correctly with given normal thus is commented out + //dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SAMPLE_GI( " + fInName + ".lightmapUVOrVertexSH.xy, " + fInName + ".lightmapUVOrVertexSH.xyz, " + fragWorldNormal + " );" ); + dataCollector.AddFunction( LWIndirectDiffuseBody[ 0 ], LWIndirectDiffuseBody, false ); + finalValue = "bakedGI" + OutputId; + string result = string.Format( LWIndirectDiffuseHeader, fInName + ".lightmapUVOrVertexSH.xy", fragWorldNormal ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, finalValue, result ); + + m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ); + return finalValue; + } + else if( dataCollector.CurrentSRPType == TemplateSRPType.HD ) + { + string texcoord1 = string.Empty; + string texcoord2 = string.Empty; + + if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) ) + texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName; + else + texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false ); + + if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) ) + texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName; + else + texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false ); + + dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lightmapUVs" ); + + string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName; + string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName; + + dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw;" ); + dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;" ); + + string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Fragment ); + + dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" ); + dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" ); + dataCollector.AddToPragmas( UniqueId, "multi_compile _ DYNAMICLIGHTMAP_ON" ); + + string fragWorldNormal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ); + else + fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + else + { + fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ); + } + + //SAMPLE_GI + dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SampleBakedGI( " + worldPos + ", " + fragWorldNormal + ", " + fInName + ".ase_lightmapUVs.xy, " + fInName + ".ase_lightmapUVs.zw );" ); + finalValue = "bakedGI" + OutputId; + m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ); + return finalValue; + } + } + } + if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting ) + return "float3(0,0,0)"; + + string normal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + dataCollector.ForceNormal = true; + + normal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + if( m_normalSpace == ViewSpace.Tangent ) + normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )"; + } + else + { + if( dataCollector.IsFragmentCategory ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + if( dataCollector.DirtyNormal ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + dataCollector.ForceNormal = true; + } + } + + normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ); + } + + + if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "ShadeSH9( float4( " + normal + ", 1 ) )" ); + } + else + { + dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi;" ); + dataCollector.AddLocalVariable( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT3, "diffNorm" + OutputId, normal ); + dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGI_Base( data, 1, diffNorm" + OutputId + " );" ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "gi" + OutputId + ".indirect.diffuse + diffNorm" + OutputId + " * 0.0001" ); + } + + finalValue = "indirectDiffuse" + OutputId; + m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory ); + return finalValue; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() > 13002 ) + m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) ); + + UpdatePort(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta new file mode 100644 index 00000000..2e9b5ba5 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 11bf17b0757d57c47add2eb50c62c75e +timeCreated: 1495726164 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs new file mode 100644 index 00000000..197e193e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs @@ -0,0 +1,268 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Indirect Specular Light", "Light", "Indirect Specular Light", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )] + public sealed class IndirectSpecularLight : ParentNode + { + [SerializeField] + private ViewSpace m_normalSpace = ViewSpace.Tangent; + + private const string DefaultErrorMessage = "This node only returns correct information using a custom light model, otherwise returns 0"; + private bool m_upgradeMessage = false; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, "Normal" ); + AddInputPort( WirePortDataType.FLOAT, false, "Smoothness" ); + AddInputPort( WirePortDataType.FLOAT, false, "Occlusion" ); + m_inputPorts[ 0 ].Vector3InternalData = Vector3.forward; + m_inputPorts[ 1 ].FloatInternalData = 0.5f; + m_inputPorts[ 2 ].FloatInternalData = 1; + m_inputPorts[ 1 ].AutoDrawInternalData = true; + m_inputPorts[ 2 ].AutoDrawInternalData = true; + m_autoWrapProperties = true; + AddOutputPort( WirePortDataType.FLOAT3, "RGB" ); + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = DefaultErrorMessage; + m_previewShaderGUID = "d6e441d0a8608954c97fa347d3735e92"; + m_drawPreviewAsSphere = true; + } + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + if( m_inputPorts[ 0 ].IsConnected ) + dataCollector.DirtyNormal = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + m_previewMaterialPassId = 1; + else + m_previewMaterialPassId = 2; + } + else + { + m_previewMaterialPassId = 0; + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + + EditorGUI.BeginChangeCheck(); + m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace ); + if( EditorGUI.EndChangeCheck() ) + { + UpdatePort(); + } + if( !m_inputPorts[ 1 ].IsConnected ) + m_inputPorts[ 1 ].FloatInternalData = EditorGUILayout.FloatField( m_inputPorts[ 1 ].Name, m_inputPorts[ 1 ].FloatInternalData ); + if( !m_inputPorts[ 2 ].IsConnected ) + m_inputPorts[ 2 ].FloatInternalData = EditorGUILayout.FloatField( m_inputPorts[ 2 ].Name, m_inputPorts[ 2 ].FloatInternalData ); + } + + private void UpdatePort() + { + if( m_normalSpace == ViewSpace.World ) + m_inputPorts[ 0 ].ChangeProperties( "World Normal", m_inputPorts[ 0 ].DataType, false ); + else + m_inputPorts[ 0 ].ChangeProperties( "Normal", m_inputPorts[ 0 ].DataType, false ); + + m_sizeIsDirty = true; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( m_upgradeMessage || ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) ) + m_showErrorMessage = true; + else + m_showErrorMessage = false; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate ) + { + if( !dataCollector.IsSRP ) + { + dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib ); + string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos(); + string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment ); + + string worldNormal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ); + else + worldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + else + { + worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ); + } + + string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + + dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data;" ); + dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data );" ); + dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ";" ); + dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + worldViewDir + ";" ); + dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR;" ); + dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR;" ); + dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[0] = unity_SpecCube0_BoxMin;" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" ); + dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[0] = unity_SpecCube0_BoxMax;" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[0] = unity_SpecCube0_ProbePosition;" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[1] = unity_SpecCube1_BoxMax;" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[1] = unity_SpecCube1_BoxMin;" ); + dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[1] = unity_SpecCube1_ProbePosition;" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" ); + + dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + tempsmoothness + ", " + worldViewDir + ", " + worldNormal + ", float3(0,0,0));" ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + tempocclusion + ", " + worldNormal + ", g" + OutputId + " )" ); + return "indirectSpecular" + OutputId; + } + else + { + if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight ) + { + string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment ); + string worldNormal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + if( m_normalSpace == ViewSpace.Tangent ) + worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId ); + else + worldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + else + { + worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment ); + } + + string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + + dataCollector.AddLocalVariable( UniqueId, "half3 reflectVector" + OutputId + " = reflect( -" + worldViewDir + ", " + worldNormal + " );" ); + dataCollector.AddLocalVariable( UniqueId, "float3 indirectSpecular" + OutputId + " = GlossyEnvironmentReflection( reflectVector" + OutputId + ", 1.0 - " + tempsmoothness + ", " + tempocclusion + " );" ); + return "indirectSpecular" + OutputId; + } + else if( dataCollector.CurrentSRPType == TemplateSRPType.HD ) + { + UIUtils.ShowMessage( UniqueId, "Indirect Specular Light node currently not supported on HDRP" ); + return m_outputPorts[0].ErrorValue; + } + } + } + + if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting ) + return m_outputPorts[0].ErrorValue; + + string normal = string.Empty; + if( m_inputPorts[ 0 ].IsConnected ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + dataCollector.ForceNormal = true; + + normal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + if( m_normalSpace == ViewSpace.Tangent ) + normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )"; + + dataCollector.AddLocalVariable( UniqueId, "float3 indirectNormal" + OutputId + " = " + normal + ";" ); + normal = "indirectNormal" + OutputId; + } + else + { + if( dataCollector.IsFragmentCategory ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + if( dataCollector.DirtyNormal ) + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + dataCollector.ForceNormal = true; + } + } + + normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ); + } + + string smoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + string occlusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + string viewDir = "data.worldViewDir"; + + if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + string worldPos = GeneratorUtils.GenerateWorldPosition( ref dataCollector, UniqueId ); + viewDir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId ); + + dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data;" ); + dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data );" ); + dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ";" ); + dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + viewDir + ";" ); + dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR;" ); + dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR;" ); + dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" ); + dataCollector.AddLocalVariable( UniqueId, "data.boxMin[0] = unity_SpecCube0_BoxMin;" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" ); + dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" ); + dataCollector.AddLocalVariable( UniqueId, "data.boxMax[0] = unity_SpecCube0_BoxMax;" ); + dataCollector.AddLocalVariable( UniqueId, "data.probePosition[0] = unity_SpecCube0_ProbePosition;" ); + dataCollector.AddLocalVariable( UniqueId, "data.boxMax[1] = unity_SpecCube1_BoxMax;" ); + dataCollector.AddLocalVariable( UniqueId, "data.boxMin[1] = unity_SpecCube1_BoxMin;" ); + dataCollector.AddLocalVariable( UniqueId, "data.probePosition[1] = unity_SpecCube1_ProbePosition;" ); + dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" ); + } + + dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + smoothness + ", " + viewDir + ", " + normal + ", float3(0,0,0));" ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + occlusion + ", " + normal + ", g" + OutputId + " )" ); + + return "indirectSpecular" + OutputId; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() > 13002 ) + m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) ); + + if( UIUtils.CurrentShaderVersion() < 13804 ) + { + m_errorMessageTooltip = "Smoothness port was previously being used as Roughness, please check if you are correctly using it and save to confirm."; + m_upgradeMessage = true; + UIUtils.ShowMessage( UniqueId, "Indirect Specular Light node: Smoothness port was previously being used as Roughness, please check if you are correctly using it and save to confirm." ); + } + + UpdatePort(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace ); + + m_errorMessageTooltip = DefaultErrorMessage; + m_upgradeMessage = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta new file mode 100644 index 00000000..0c0bb141 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0820850e74009954188ff84e2f5cc4f2 +timeCreated: 1495817589 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs new file mode 100644 index 00000000..57ad0f44 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs @@ -0,0 +1,128 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +using UnityEditor; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Light Attenuation", "Light", "Contains light attenuation for all types of light", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )] + public sealed class LightAttenuation : ParentNode + { + static readonly string SurfaceError = "This node only returns correct information using a custom light model, otherwise returns 1"; + static readonly string TemplateError = "This node will only produce proper attenuation if the template contains a shadow caster pass"; + + private const string ASEAttenVarName = "ase_lightAtten"; + + private readonly string[] LightweightPragmaMultiCompiles = + { + "multi_compile _ _MAIN_LIGHT_SHADOWS", + "multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE", + "multi_compile _ _SHADOWS_SOFT" + }; + + //private readonly string[] LightweightVertexInstructions = + //{ + // /*local vertex position*/"VertexPositionInputs ase_vertexInput = GetVertexPositionInputs ({0});", + // "#ifdef _MAIN_LIGHT_SHADOWS//ase_lightAtten_vert", + // /*available interpolator*/"{0} = GetShadowCoord( ase_vertexInput );", + // "#endif//ase_lightAtten_vert" + //}; + private const string LightweightLightAttenDecl = "float ase_lightAtten = 0;"; + private readonly string[] LightweightFragmentInstructions = + { + /*shadow coords*/"Light ase_lightAtten_mainLight = GetMainLight( {0} );", + "ase_lightAtten = ase_lightAtten_mainLight.distanceAttenuation * ase_lightAtten_mainLight.shadowAttenuation;" + }; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.FLOAT, "Out" ); + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = SurfaceError; + m_previewShaderGUID = "4b12227498a5c8d46b6c44ea018e5b56"; + m_drawPreviewAsSphere = true; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate ) + { + if( !dataCollector.IsSRP ) + { + return dataCollector.TemplateDataCollectorInstance.GetLightAtten( UniqueId ); + } + else + { + if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight ) + { + if( dataCollector.HasLocalVariable( LightweightLightAttenDecl )) + return ASEAttenVarName; + + // Pragmas + for( int i = 0; i < LightweightPragmaMultiCompiles.Length; i++ ) + dataCollector.AddToPragmas( UniqueId, LightweightPragmaMultiCompiles[ i ] ); + + string shadowCoords = dataCollector.TemplateDataCollectorInstance.GetShadowCoords( UniqueId/*, false, dataCollector.PortCategory*/ ); + //return shadowCoords; + // Vertex Instructions + //TemplateVertexData shadowCoordsData = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false ); + //string vertexInterpName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName; + //string vertexShadowCoords = vertexInterpName + "." + shadowCoordsData.VarNameWithSwizzle; + //string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition( WirePortDataType.FLOAT3, PrecisionType.Float ,false,MasterNodePortCategory.Vertex ); + + //dataCollector.AddToVertexLocalVariables( UniqueId, string.Format( LightweightVertexInstructions[ 0 ], vertexPos )); + //dataCollector.AddToVertexLocalVariables( UniqueId, LightweightVertexInstructions[ 1 ]); + //dataCollector.AddToVertexLocalVariables( UniqueId, string.Format( LightweightVertexInstructions[ 2 ], vertexShadowCoords ) ); + //dataCollector.AddToVertexLocalVariables( UniqueId, LightweightVertexInstructions[ 3 ]); + + // Fragment Instructions + //string fragmentInterpName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName; + //string fragmentShadowCoords = fragmentInterpName + "." + shadowCoordsData.VarNameWithSwizzle; + + dataCollector.AddLocalVariable( UniqueId, LightweightLightAttenDecl ); + dataCollector.AddLocalVariable( UniqueId, string.Format( LightweightFragmentInstructions[ 0 ], shadowCoords ) ); + dataCollector.AddLocalVariable( UniqueId, LightweightFragmentInstructions[ 1 ] ); + return ASEAttenVarName; + } + else + { + UIUtils.ShowMessage( UniqueId, "Light Attenuation node currently not supported on HDRP" ); + return "1"; + } + } + } + + if ( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting ) + { + UIUtils.ShowMessage( UniqueId, "Light Attenuation node currently not supported on non-custom lighting surface shaders" ); + return "1"; + } + + dataCollector.UsingLightAttenuation = true; + return ASEAttenVarName; + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader && ContainerGraph.CurrentSRPType != TemplateSRPType.Lightweight ) + { + m_showErrorMessage = true; + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = TemplateError; + } else + { + m_errorMessageTypeIsError = NodeMessageType.Error; + m_errorMessageTooltip = SurfaceError; + if ( ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) ) + m_showErrorMessage = true; + else + m_showErrorMessage = false; + } + + + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta new file mode 100644 index 00000000..05a8aa70 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4e205b44d56609f459ffc558febe2792 +timeCreated: 1495449979 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs new file mode 100644 index 00000000..92021081 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs @@ -0,0 +1,88 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Light Color", "Light", "Light Color, RGB value already contains light intensity while A only contains light intensity" )] + public sealed class LightColorNode : ShaderVariablesNode + { + private const string m_lightColorValue = "_LightColor0"; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "RGBA", WirePortDataType.COLOR ); + AddOutputPort( WirePortDataType.FLOAT3, "Color" ); + AddOutputPort( WirePortDataType.FLOAT, "Intensity" ); + m_previewShaderGUID = "43f5d3c033eb5044e9aeb40241358349"; + } + + public override void RenderNodePreview() + { + //Runs at least one time + if( !m_initialized ) + { + // nodes with no preview don't update at all + PreviewIsDirty = false; + return; + } + + if( !PreviewIsDirty ) + return; + + int count = m_outputPorts.Count; + for( int i = 0; i < count; i++ ) + { + RenderTexture temp = RenderTexture.active; + RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture; + Graphics.Blit( null, m_outputPorts[ i ].OutputPreviewTexture, PreviewMaterial, i ); + RenderTexture.active = temp; + } + + PreviewIsDirty = m_continuousPreviewRefresh; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate && !dataCollector.IsSRP ) + dataCollector.AddToIncludes( -1, Constants.UnityLightingLib ); + + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + string finalVar = m_lightColorValue; + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + { + dataCollector.TemplateDataCollectorInstance.AddHDLightInfo(); + finalVar = string.Format( TemplateHelperFunctions.HDLightInfoFormat, "0", "color" ); ; + } + else + { + finalVar = "_MainLightColor"; + } + } + else + { + dataCollector.AddLocalVariable( UniqueId, "#if defined(LIGHTMAP_ON) && ( UNITY_VERSION < 560 || ( defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) ) )//aselc" ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, "ase_lightColor", "0" ); + dataCollector.AddLocalVariable( UniqueId, "#else //aselc" ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, "ase_lightColor", finalVar ); + dataCollector.AddLocalVariable( UniqueId, "#endif //aselc" ); + finalVar = "ase_lightColor"; + } + //else if( ContainerGraph.CurrentStandardSurface.CurrentLightingModel == StandardShaderLightModel.CustomLighting ) + // finalVar = "gi.light.color"; + + switch( outputId ) + { + default: + case 0: return finalVar; + case 1: return finalVar + ".rgb"; + case 2: return finalVar + ".a"; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta new file mode 100644 index 00000000..9acf2a10 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 275270020c577924caf04492f73b2ea6 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs new file mode 100644 index 00000000..80aae5df --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs @@ -0,0 +1,92 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEditor; +using UnityEngine; +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "World Space Light Pos", "Light", "Light Position" )] + public sealed class WorldSpaceLightPos : ShaderVariablesNode + { + private const string HelperText = + "This node will behave differently according to light type." + + "\n\n- For directional lights the Dir/Pos output will specify a world space direction and Type will be set to 0." + + "\n\n- For other light types the Dir/Pos output will specify a world space position and Type will be set to 1."; + private const string m_lightPosValue = "_WorldSpaceLightPos0"; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, Constants.EmptyPortValue, WirePortDataType.FLOAT4 ); + AddOutputPort( WirePortDataType.FLOAT3, "Dir/Pos" ); + AddOutputPort( WirePortDataType.FLOAT, "Type" ); + m_previewShaderGUID = "2292a614672283c41a367b22cdde4620"; + m_drawPreviewAsSphere = true; + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUILayout.HelpBox( HelperText, MessageType.Info ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar ); + string finalVar = m_lightPosValue; + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.IsSRP ) + finalVar = "_MainLightPosition"; + if( outputId == 1 ) + { + return finalVar + ".xyz"; + } + else if( outputId == 2 ) + { + return finalVar + ".w"; + } + else + { + return finalVar; + } + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + + public override void RenderNodePreview() + { + //Runs at least one time + if( !m_initialized ) + { + // nodes with no preview don't update at all + PreviewIsDirty = false; + return; + } + + if( !PreviewIsDirty ) + return; + + SetPreviewInputs(); + + RenderTexture temp = RenderTexture.active; + + RenderTexture.active = m_outputPorts[ 0 ].OutputPreviewTexture; + Graphics.Blit( null, m_outputPorts[ 0 ].OutputPreviewTexture, PreviewMaterial, 0 ); + Graphics.Blit( m_outputPorts[ 0 ].OutputPreviewTexture, m_outputPorts[ 1 ].OutputPreviewTexture ); + + RenderTexture.active = m_outputPorts[ 2 ].OutputPreviewTexture; + Graphics.Blit( null, m_outputPorts[ 2 ].OutputPreviewTexture, PreviewMaterial, 1 ); + RenderTexture.active = temp; + + PreviewIsDirty = m_continuousPreviewRefresh; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta new file mode 100644 index 00000000..79f4fc5b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: db94d973647dae9488d3ef5ee2fd95a4 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs new file mode 100644 index 00000000..499999f1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs @@ -0,0 +1,27 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + public class ShaderVariablesNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.OBJECT, "Out" ); + } + public override string GetIncludes() + { + return Constants.UnityShaderVariables; + } + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( !( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.IsSRP ) ) + dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ); + return string.Empty; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs.meta new file mode 100644 index 00000000..dce292dc --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/ShaderVariablesNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1eb723e6ceff9a345a9dbfe04aa3dc11 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time.meta new file mode 100644 index 00000000..bfd7fd96 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7c77e88b33fec7c429412624a7b2c620 +folderAsset: yes +timeCreated: 1481126947 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs new file mode 100644 index 00000000..096676f2 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs @@ -0,0 +1,55 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Cos Time", "Time", "Cosine of time" )] + public sealed class CosTime : ConstVecShaderVariable + { +#if UNITY_2018_3_OR_NEWER + private readonly string[] SRPTime = + { + "cos( _TimeParameters.x * 0.125 )", + "cos( _TimeParameters.x * 0.25 )", + "cos( _TimeParameters.x * 0.5 )", + "_TimeParameters.z", + }; +#endif + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "t/8" ); + ChangeOutputName( 2, "t/4" ); + ChangeOutputName( 3, "t/2" ); + ChangeOutputName( 4, "t" ); + m_value = "_CosTime"; + m_previewShaderGUID = "3093999b42c3c0940a71799511d7781c"; + m_continuousPreviewRefresh = true; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { +#if UNITY_2018_3_OR_NEWER + if( outputId > 0 && dataCollector.IsTemplate ) + { + if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) || + ( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ) + return SRPTime[ outputId - 1 ]; + } +#endif + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs.meta new file mode 100644 index 00000000..80373c18 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/CosTime.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 447e504f2ca5aaf4bbf0fdbce33596bc +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs new file mode 100644 index 00000000..a1f3380f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs @@ -0,0 +1,33 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Delta Time", "Time", "Delta time" )] + public sealed class DeltaTime : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "dt" ); + ChangeOutputName( 2, "1/dt" ); + ChangeOutputName( 3, "smoothDt" ); + ChangeOutputName( 4, "1/smoothDt" ); + m_value = "unity_DeltaTime"; + m_previewShaderGUID = "9d69a693042c443498f96d6da60535eb"; + m_continuousPreviewRefresh = true; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs.meta new file mode 100644 index 00000000..400f94fe --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/DeltaTime.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3ddde7ed1ab4f8044a9a6aa3891f5ca4 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs new file mode 100644 index 00000000..8445f90b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs @@ -0,0 +1,48 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Time", "Time", "Time in seconds with a scale multiplier" )] + public sealed class SimpleTimeNode : ShaderVariablesNode + { + private const string TimeStandard = "_Time.y"; +#if UNITY_2018_3_OR_NEWER + private const string TimeSRP = "_TimeParameters.x"; +#endif + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT ); + AddInputPort( WirePortDataType.FLOAT, false, "Scale" ); + m_inputPorts[ 0 ].FloatInternalData = 1; + m_useInternalPortData = true; + m_previewShaderGUID = "45b7107d5d11f124fad92bcb1fa53661"; + m_continuousPreviewRefresh = true; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + string multiplier = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string timeGlobalVar = TimeStandard; +#if UNITY_2018_3_OR_NEWER + if( dataCollector.IsTemplate ) + { + if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) || + ( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ) + timeGlobalVar = TimeSRP; + } +#endif + if( multiplier == "1.0" ) + return timeGlobalVar; + + string scaledVarName = "mulTime" + OutputId; + string scaledVarValue = timeGlobalVar + " * " + multiplier; + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, scaledVarName, scaledVarValue ); + return scaledVarName; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs.meta new file mode 100644 index 00000000..313b9315 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SimpleTimeNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f36e4491ee33fe74fa51cfb5ad450c6e +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs new file mode 100644 index 00000000..aac2b1eb --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs @@ -0,0 +1,58 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEditor; +using UnityEngine; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Sin Time", "Time", "Unity sin time" )] + public sealed class SinTimeNode : ConstVecShaderVariable + { + //double m_time; +#if UNITY_2018_3_OR_NEWER + private readonly string[] SRPTime = + { + "sin( _TimeParameters.x * 0.125 )", + "sin( _TimeParameters.x * 0.25 )", + "sin( _TimeParameters.x * 0.5 )", + "_TimeParameters.y", + }; +#endif + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "t/8" ); + ChangeOutputName( 2, "t/4" ); + ChangeOutputName( 3, "t/2" ); + ChangeOutputName( 4, "t" ); + m_value = "_SinTime"; + m_previewShaderGUID = "e4ba809e0badeb94994170b2cbbbba10"; + m_continuousPreviewRefresh = true; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { +#if UNITY_2018_3_OR_NEWER + if( outputId > 0 && dataCollector.IsTemplate ) + { + if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) || + ( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ) + return SRPTime[ outputId - 1 ]; + } +#endif + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs.meta new file mode 100644 index 00000000..876a7748 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/SinTimeNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 796acd44fcf330e4e921855630007b9b +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs new file mode 100644 index 00000000..258d5177 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs @@ -0,0 +1,55 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Time Parameters", "Time", "Time since level load" )] + public sealed class TimeNode : ConstVecShaderVariable + { +#if UNITY_2018_3_OR_NEWER + private readonly string[] SRPTime = + { + "( _TimeParameters.x * 0.05 )", + "( _TimeParameters.x )", + "( _TimeParameters.x * 2 )", + "( _TimeParameters.x * 3 )", + }; +#endif + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "t/20" ); + ChangeOutputName( 2, "t" ); + ChangeOutputName( 3, "t*2" ); + ChangeOutputName( 4, "t*3" ); + m_value = "_Time"; + m_previewShaderGUID = "73abc10c8d1399444827a7eeb9c24c2a"; + m_continuousPreviewRefresh = true; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { +#if UNITY_2018_3_OR_NEWER + if( outputId > 0 && dataCollector.IsTemplate ) + { + if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) || + ( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 )) + return SRPTime[ outputId - 1 ]; + } +#endif + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs.meta new file mode 100644 index 00000000..521dcf41 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Time/TimeNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d8c6b7bfb7784e14d8708ab6fb981268 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform.meta new file mode 100644 index 00000000..008be40e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2ce97203c4871664493f8760d88d0d4d +folderAsset: yes +timeCreated: 1481126946 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs new file mode 100644 index 00000000..1238566a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs @@ -0,0 +1,24 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Camera To World Matrix", "Matrix Transform", "Current camera to world matrix" )] + public sealed class CameraToWorldMatrix : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_CameraToWorld"; + m_drawPreview = false; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ); + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs.meta new file mode 100644 index 00000000..2e13b7e9 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/CameraToWorldMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6accfe0f350cf064dae07041fe90446b +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs new file mode 100644 index 00000000..0b53040c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs @@ -0,0 +1,46 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Inverse Projection Matrix", "Matrix Transform", "Current inverse projection matrix", NodeAvailabilityFlags = (int)( NodeAvailability.TemplateShader ) )] + public sealed class InverseProjectionMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_I_P"; + m_drawPreview = false; + m_matrixId = 1; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + else + { + return GeneratorUtils.GenerateIdentity4x4( ref dataCollector, UniqueId ); + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( ContainerGraph.IsSRP ) + { + m_showErrorMessage = false; + } + else + { + m_showErrorMessage = true; + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = "This node only works for Scriptable Render Pipeline (LWRP, HDRP, URP)"; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs.meta new file mode 100644 index 00000000..302ccf23 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseProjectionMatrixNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0fdbc380972c44b489c5f948a40b8e69 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs new file mode 100644 index 00000000..e4071ba0 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Inverse Transpose Model View Matrix", "Matrix Transform", "All Transformation types" )] + public sealed class InverseTranspMVMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_IT_MV"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs.meta new file mode 100644 index 00000000..1b3b8fd3 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseTranspMVMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3a71f1e560487aa4c8484c4153941884 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs new file mode 100644 index 00000000..c21aa195 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs @@ -0,0 +1,19 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Inverse View Matrix", "Matrix Transform", "Current inverse view matrix" )] + public sealed class InverseViewMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_I_V"; + m_drawPreview = false; + m_matrixId = 0; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs.meta new file mode 100644 index 00000000..61b23243 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dd0c1c252c062184e9ad592b91e7fcd2 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs new file mode 100644 index 00000000..d812cc23 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs @@ -0,0 +1,46 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Inverse View Projection Matrix", "Matrix Transform", "Current view inverse projection matrix", NodeAvailabilityFlags = (int)( NodeAvailability.TemplateShader ) )] + public sealed class InverseViewProjectionMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_I_VP"; + m_drawPreview = false; + m_matrixId = 1; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + else + { + return GeneratorUtils.GenerateIdentity4x4( ref dataCollector, UniqueId ); + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( ContainerGraph.IsSRP ) + { + m_showErrorMessage = false; + } + else + { + m_showErrorMessage = true; + m_errorMessageTypeIsError = NodeMessageType.Warning; + m_errorMessageTooltip = "This node only works for Scriptable Render Pipeline (LWRP, HDRP, URP)"; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs.meta new file mode 100644 index 00000000..6b221613 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/InverseViewProjectionMatrixNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f6f151774e252dd4fb2b9ee440ec8eed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs new file mode 100644 index 00000000..ed903397 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Model Matrix", "Matrix Transform", "Current model matrix" )] + public sealed class MMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_M"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs.meta new file mode 100644 index 00000000..51c6d1f8 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 503a386043991354eaca2410683d836a +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs new file mode 100644 index 00000000..a99d8518 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Model View Matrix", "Matrix Transform", "Current model * view matrix" )] + public sealed class MVMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_MV"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs.meta new file mode 100644 index 00000000..6c0355ea --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 30c7936db4e6fe5488076d799841f857 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs new file mode 100644 index 00000000..324a1532 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Model View Projection Matrix", "Matrix Transform", "Current model * view * projection matrix" )] + public sealed class MVPMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_MVP"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs.meta new file mode 100644 index 00000000..8275deff --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/MVPMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 74e00fb3d8e161f498c078795184bae4 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs new file mode 100644 index 00000000..2f5873be --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs @@ -0,0 +1,19 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Object To World Matrix", "Matrix Transform", "Current model matrix" )] + public sealed class ObjectToWorldMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_ObjectToWorld"; + m_HDValue = "GetObjectToWorldMatrix()"; + m_LWValue = "GetObjectToWorldMatrix()"; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs.meta new file mode 100644 index 00000000..7d008d9d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ObjectToWorldMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a0c0180a327eba54c832fbb695dd282f +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs new file mode 100644 index 00000000..a80058d2 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs @@ -0,0 +1,19 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Projection Matrix", "Matrix Transform", "Current projection matrix" )] + public sealed class ProjectionMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_P"; + m_drawPreview = false; + m_matrixId = 1; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs.meta new file mode 100644 index 00000000..5f2d19b1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ProjectionMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 008fd07cf3f9a7140a9e23be43733f7c +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs new file mode 100644 index 00000000..4f568726 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Texture 0 Matrix", "Matrix Transform", "Texture 0 Matrix", null, UnityEngine.KeyCode.None, true, true )] + public sealed class Texture0MatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_TEXTURE0"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs.meta new file mode 100644 index 00000000..fbdf6114 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture0MatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f57a1d05f7a9c5847912566ff1605c6d +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs new file mode 100644 index 00000000..a9debbe5 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Texture 1 Matrix", "Matrix Transform", "Texture 1 Matrix", null, UnityEngine.KeyCode.None, true, true )] + public sealed class Texture1MatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_TEXTURE1"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs.meta new file mode 100644 index 00000000..429b1082 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture1MatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9ef360a7c6005ad479d7a3e6db1d32f4 +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs new file mode 100644 index 00000000..c0938e7a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Texture 2 Matrix", "Matrix Transform", "Texture 2 Matrix", null, UnityEngine.KeyCode.None, true, true )] + public sealed class Texture2MatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_TEXTURE2"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs.meta new file mode 100644 index 00000000..dc1e0080 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture2MatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6cf4950dda0f6e6438ace404fbef19a7 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs new file mode 100644 index 00000000..8b5f86ae --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Texture 3 Matrix", "Matrix Transform", "Texture 3 Matrix", null, UnityEngine.KeyCode.None, true, true )] + public sealed class Texture3MatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_TEXTURE3"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs.meta new file mode 100644 index 00000000..00df6e3e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/Texture3MatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 02a9fb7a3a104974e941f4109567b97f +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs new file mode 100644 index 00000000..bc7ee22a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs @@ -0,0 +1,560 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + public enum InverseTangentType + { + Fast, + Precise + } + + [Serializable] + [NodeAttributes( "Transform Direction", "Vector Operators", "Transforms a direction vector from one space to another" )] + public sealed class TransformDirectionNode : ParentNode + { + + [SerializeField] + private TransformSpaceFrom m_from = TransformSpaceFrom.Object; + + [SerializeField] + private TransformSpaceTo m_to = TransformSpaceTo.World; + + [SerializeField] + private bool m_normalize = false; + + [SerializeField] + private InverseTangentType m_inverseTangentType = InverseTangentType.Fast; + + private string InverseTBNStr = "Inverse TBN"; + + private const string NormalizeOptionStr = "Normalize"; + private const string NormalizeFunc = "normalize( {0} )"; + + private const string AseObjectToWorldDirVarName = "objToWorldDir"; + private const string AseObjectToWorldDirFormat = "mul( unity_ObjectToWorld, float4( {0}, 0 ) ).xyz"; + private const string AseSRPObjectToWorldDirFormat = "mul( GetObjectToWorldMatrix(), float4( {0}, 0 ) ).xyz"; + + private const string AseObjectToViewDirVarName = "objToViewDir"; + private const string AseObjectToViewDirFormat = "mul( UNITY_MATRIX_IT_MV, float4( {0}, 0 ) ).xyz"; + private const string AseHDObjectToViewDirFormat = "TransformWorldToViewDir( TransformObjectToWorldDir( {0} ))"; + + private const string AseWorldToObjectDirVarName = "worldToObjDir"; + private const string AseWorldToObjectDirFormat = "mul( unity_WorldToObject, float4( {0}, 0 ) ).xyz"; + private const string AseSRPWorldToObjectDirFormat = "mul( GetWorldToObjectMatrix(), float4( {0}, 0 ) ).xyz"; + + + private const string AseWorldToViewDirVarName = "worldToViewDir"; + private const string AseWorldToViewDirFormat = "mul( UNITY_MATRIX_V, float4( {0}, 0 ) ).xyz"; + + private const string AseViewToObjectDirVarName = "viewToObjDir"; + private const string AseViewToObjectDirFormat = "mul( UNITY_MATRIX_T_MV, float4( {0}, 0 ) ).xyz"; + + private const string AseViewToWorldDirVarName = "viewToWorldDir"; + private const string AseViewToWorldDirFormat = "mul( UNITY_MATRIX_I_V, float4( {0}, 0 ) ).xyz"; + + /////////////////////////////////////////////////////////// + private const string AseObjectToClipDirVarName = "objectToClipDir"; + private const string AseObjectToClipDirFormat = "mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, float4({0}, 0.0)))"; + private const string AseSRPObjectToClipDirFormat = "TransformWorldToHClipDir(TransformObjectToWorldDir({0}))"; + + private const string AseWorldToClipDirVarName = "worldToClipDir"; + private const string AseWorldToClipDirFormat = "mul(UNITY_MATRIX_VP, float4({0}, 0.0))"; + private const string AseSRPWorldToClipDirFormat = "TransformWorldToHClipDir({0})"; + + private const string AseViewToClipDirVarName = "viewToClipDir"; + private const string AseViewToClipDirFormat = "mul(UNITY_MATRIX_P, float4({0}, 0.0))"; + private const string AseSRPViewToClipDirFormat = "mul(GetViewToHClipMatrix(), float4({0}, 1.0))"; + // + private const string AseClipToObjectDirVarName = "clipToObjectDir"; + + private const string AseClipToObjectDirFormat = "mul( UNITY_MATRIX_IT_MV, mul( unity_CameraInvProjection,float4({0},0)) ).xyz"; + private const string AseClipToWorldDirFormat = "mul( UNITY_MATRIX_I_V, mul( unity_CameraInvProjection,float4({0},0)) ).xyz"; + private const string AseClipToViewDirFormat = " mul( unity_CameraInvProjection,float4({0},0)).xyz"; + private const string AseHDClipToObjectDirFormat = "mul( UNITY_MATRIX_I_M, mul( UNITY_MATRIX_I_VP,float4({0},0)) ).xyz"; + + private const string AseClipToWorldDirVarName = "clipToWorldDir"; + private const string AseHDClipToWorldDirFormat = "mul( UNITY_MATRIX_I_VP, float4({0},0) ).xyz"; + + private const string AseClipToViewDirVarName = "clipToViewDir"; + private const string AseHDClipToViewDirFormat = " mul( UNITY_MATRIX_I_P,float4({0},0)).xyz"; + private const string AseClipToNDC = "{0}.xyz/{0}.w"; + + ///////////////////////////////////////////////////// + private const string AseObjectToTangentDirVarName = "objectToTangentDir"; + private const string AseWorldToTangentDirVarName = "worldToTangentDir"; + private const string AseViewToTangentDirVarName = "viewToTangentDir"; + private const string AseClipToTangentDirVarName = "clipToTangentDir"; + private const string ASEWorldToTangentFormat = "mul( ase_worldToTangent, {0})"; + + + private const string AseTangentToObjectDirVarName = "tangentTobjectDir"; + private const string AseTangentToWorldDirVarName = "tangentToWorldDir"; + private const string AseTangentToViewDirVarName = "tangentToViewDir"; + private const string AseTangentToClipDirVarName = "tangentToClipDir"; + private const string ASEMulOpFormat = "mul( {0}, {1} )"; + + + + /////////////////////////////////////////////////////////// + private const string FromStr = "From"; + private const string ToStr = "To"; + private const string SubtitleFormat = "{0} to {1}"; + + private readonly string[] m_spaceOptionsFrom = + { + "Object", + "World", + "View", + "Tangent" + }; + + private readonly string[] m_spaceOptionsTo = + { + "Object", + "World", + "View", + "Tangent", + "Clip" + }; + + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, Constants.EmptyPortValue ); + AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" ); + m_useInternalPortData = true; + m_autoWrapProperties = true; + m_previewShaderGUID = "74e4d859fbdb2c0468de3612145f4929"; + m_textLabelWidth = 100; + UpdateSubtitle(); + } + + private void UpdateSubtitle() + { + SetAdditonalTitleText( string.Format( SubtitleFormat, m_from, m_to ) ); + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_from = (TransformSpaceFrom)EditorGUILayoutPopup( FromStr, (int)m_from, m_spaceOptionsFrom ); + m_to = (TransformSpaceTo)EditorGUILayoutPopup( ToStr, (int)m_to, m_spaceOptionsTo ); + if( m_from == TransformSpaceFrom.Tangent ) + { + m_inverseTangentType = (InverseTangentType)EditorGUILayoutEnumPopup( InverseTBNStr, m_inverseTangentType ); + } + + m_normalize = EditorGUILayoutToggle( NormalizeOptionStr, m_normalize ); + if( EditorGUI.EndChangeCheck() ) + { + UpdateSubtitle(); + } + } + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + if( (int)m_from != (int)m_to && ( m_from == TransformSpaceFrom.Tangent || m_to == TransformSpaceTo.Tangent ) ) + dataCollector.DirtyNormal = true; + } + + void CalculateTransform( TransformSpaceFrom from, TransformSpaceTo to, ref MasterNodeDataCollector dataCollector, ref string varName, ref string result ) + { + switch( from ) + { + case TransformSpaceFrom.Object: + { + switch( to ) + { + default: case TransformSpaceTo.Object: break; + case TransformSpaceTo.World: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + result = string.Format( AseSRPObjectToWorldDirFormat, result ); + else + result = string.Format( AseObjectToWorldDirFormat, result ); + varName = AseObjectToWorldDirVarName + OutputId; + } + break; + case TransformSpaceTo.View: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + result = string.Format( AseHDObjectToViewDirFormat, result ); + else + result = string.Format( AseObjectToViewDirFormat, result ); + varName = AseObjectToViewDirVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPObjectToClipDirFormat, result ); + } + else + { + result = string.Format( AseObjectToClipDirFormat, result ); + } + varName = AseObjectToClipDirVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.World: + { + switch( to ) + { + case TransformSpaceTo.Object: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + result = string.Format( AseSRPWorldToObjectDirFormat, result ); + else + result = string.Format( AseWorldToObjectDirFormat, result ); + varName = AseWorldToObjectDirVarName + OutputId; + } + break; + default: + case TransformSpaceTo.World: break; + case TransformSpaceTo.View: + { + result = string.Format( AseWorldToViewDirFormat, result ); + varName = AseWorldToViewDirVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPWorldToClipDirFormat, result ); + } + else + { + result = string.Format( AseWorldToClipDirFormat, result ); + } + varName = AseWorldToClipDirVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.View: + { + switch( to ) + { + case TransformSpaceTo.Object: + { + result = string.Format( AseViewToObjectDirFormat, result ); + varName = AseViewToObjectDirVarName + OutputId; + } + break; + case TransformSpaceTo.World: + { + result = string.Format( AseViewToWorldDirFormat, result ); + varName = AseViewToWorldDirVarName + OutputId; + } + break; + default: case TransformSpaceTo.View: break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPViewToClipDirFormat, result ); + } + else + { + result = string.Format( AseViewToClipDirFormat, result ); + } + varName = AseViewToClipDirVarName + OutputId; + } + break; + } + } + break; + //case TransformSpace.Clip: + //{ + // switch( to ) + // { + // case TransformSpace.Object: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToObjectDirFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToObjectDirFormat, result ); + // } + // varName = AseClipToObjectDirVarName + OutputId; + // } + // break; + // case TransformSpace.World: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToWorldDirFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToWorldDirFormat, result ); + // } + // varName = AseClipToWorldDirVarName + OutputId; + // } + // break; + // case TransformSpace.View: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToViewDirFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToViewDirFormat, result ); + // } + // varName = AseClipToViewDirVarName + OutputId; + // } + // break; + // case TransformSpace.Clip: break; + // default: + // break; + // } + //} + //break; + default: break; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + + GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ); + + string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string varName = string.Empty; + + if( (int)m_from == (int)m_to ) + { + RegisterLocalVariable( 0, result, ref dataCollector ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + + switch( m_from ) + { + case TransformSpaceFrom.Object: + { + switch( m_to ) + { + default: case TransformSpaceTo.Object: break; + case TransformSpaceTo.World: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.View: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + CalculateTransform( m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseObjectToTangentDirVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.World: + { + switch( m_to ) + { + case TransformSpaceTo.Object: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + default: + case TransformSpaceTo.World: break; + case TransformSpaceTo.View: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseWorldToTangentDirVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.View: + { + switch( m_to ) + { + case TransformSpaceTo.Object: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.World: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + default: case TransformSpaceTo.View: break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + CalculateTransform( m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseViewToTangentDirVarName + OutputId; + } + break; + } + } + break; + //case TransformSpace.Clip: + //{ + // switch( m_to ) + // { + // case TransformSpace.Object: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.World: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.View: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.Clip: break; + // case TransformSpace.Tangent: + // { + // GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + // CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ); + // result = string.Format( ASEWorldToTangentFormat, result ); + // varName = AseClipToTangentDirVarName + OutputId; + // } + // break; + // default: + // break; + // } + //}break; + case TransformSpaceFrom.Tangent: + { + string matrixVal = string.Empty; + if( m_inverseTangentType == InverseTangentType.Fast ) + matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixFast( ref dataCollector, UniqueId, CurrentPrecisionType ); + else + matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixPrecise( ref dataCollector, UniqueId, CurrentPrecisionType ); + + switch( m_to ) + { + case TransformSpaceTo.Object: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToObjectDirVarName + OutputId; + } + break; + case TransformSpaceTo.World: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + varName = AseTangentToWorldDirVarName + OutputId; + } + break; + case TransformSpaceTo.View: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToViewDirVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToClipDirVarName + OutputId; + } + break; + case TransformSpaceTo.Tangent: + default: + break; + } + } + break; + default: break; + } + + if( m_normalize ) + result = string.Format( NormalizeFunc, result ); + + RegisterLocalVariable( 0, result, ref dataCollector, varName ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + string from = GetCurrentParam( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 17500 && from.Equals( "Clip" ) ) + { + UIUtils.ShowMessage( UniqueId, "Clip Space no longer supported on From field over Transform Direction node" ); + } + else + { + m_from = (TransformSpaceFrom)Enum.Parse( typeof( TransformSpaceFrom ), from ); + } + m_to = (TransformSpaceTo)Enum.Parse( typeof( TransformSpaceTo ), GetCurrentParam( ref nodeParams ) ); + m_normalize = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 15800 ) + { + m_inverseTangentType = (InverseTangentType)Enum.Parse( typeof( InverseTangentType ), GetCurrentParam( ref nodeParams ) ); + } + UpdateSubtitle(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_from ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_to ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_normalize ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_inverseTangentType ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs.meta new file mode 100644 index 00000000..123dc9ff --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformDirectionNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5088261e4c0031f4aba961a253707b80 +timeCreated: 1525857790 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs new file mode 100644 index 00000000..850f1a51 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs @@ -0,0 +1,620 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Transform Position", "Object Transform", "Transforms a position value from one space to another" )] + public sealed class TransformPositionNode : ParentNode + { + [SerializeField] + private TransformSpaceFrom m_from = TransformSpaceFrom.Object; + + [SerializeField] + private TransformSpaceTo m_to = TransformSpaceTo.World; + + [SerializeField] + private bool m_perspectiveDivide = false; + + [SerializeField] + private InverseTangentType m_inverseTangentType = InverseTangentType.Fast; + + [SerializeField] + private bool m_absoluteWorldPos = true; + + private const string AbsoluteWorldPosStr = "Absolute"; + + private string InverseTBNStr = "Inverse TBN"; + + private const string AseObjectToWorldPosVarName = "objToWorld"; + private const string AseObjectToWorldPosFormat = "mul( unity_ObjectToWorld, float4( {0}, 1 ) ).xyz"; + private const string AseHDObjectToWorldPosFormat = "mul( GetObjectToWorldMatrix(), float4( {0}, 1 ) ).xyz"; + private const string ASEHDAbsoluteWordPos = "GetAbsolutePositionWS({0})"; + private const string ASEHDRelaviveCameraPos = "GetCameraRelativePositionWS({0})"; + private const string AseObjectToViewPosVarName = "objToView"; + private const string AseObjectToViewPosFormat = "mul( UNITY_MATRIX_MV, float4( {0}, 1 ) ).xyz"; + private const string AseHDObjectToViewPosFormat = "TransformWorldToView( TransformObjectToWorld({0}) )"; + + private const string AseWorldToObjectPosVarName = "worldToObj"; + private const string AseWorldToObjectPosFormat = "mul( unity_WorldToObject, float4( {0}, 1 ) ).xyz"; + private const string AseSRPWorldToObjectPosFormat = "mul( GetWorldToObjectMatrix(), float4( {0}, 1 ) ).xyz"; + + + private const string AseWorldToViewPosVarName = "worldToView"; + private const string AseWorldToViewPosFormat = "mul( UNITY_MATRIX_V, float4( {0}, 1 ) ).xyz"; + + private const string AseViewToObjectPosVarName = "viewToObj"; + private const string AseViewToObjectPosFormat = "mul( unity_WorldToObject, mul( UNITY_MATRIX_I_V , float4( {0}, 1 ) ) ).xyz"; + private const string AseHDViewToObjectPosFormat = "mul( GetWorldToObjectMatrix(), mul( UNITY_MATRIX_I_V , float4( {0}, 1 ) ) ).xyz"; + + private const string AseViewToWorldPosVarName = "viewToWorld"; + private const string AseViewToWorldPosFormat = "mul( UNITY_MATRIX_I_V, float4( {0}, 1 ) ).xyz"; + + /////////////////////////////////////////////////////////// + private const string AseObjectToClipPosVarName = "objectToClip"; + private const string AseObjectToClipPosFormat = "UnityObjectToClipPos({0})"; + private const string AseSRPObjectToClipPosFormat = "TransformWorldToHClip(TransformObjectToWorld({0}))"; + + private const string AseWorldToClipPosVarName = "worldToClip"; + private const string AseWorldToClipPosFormat = "mul(UNITY_MATRIX_VP, float4({0}, 1.0))"; + private const string AseSRPWorldToClipPosFormat = "TransformWorldToHClip({0})"; + + private const string AseViewToClipPosVarName = "viewToClip"; + private const string AseViewToClipPosFormat = "mul(UNITY_MATRIX_P, float4({0}, 1.0))"; + private const string AseSRPViewToClipPosFormat = "TransformWViewToHClip({0})"; + // + + private const string AseClipToObjectPosVarName = "clipToObject"; + private const string AseClipToObjectPosFormat = "mul( UNITY_MATRIX_IT_MV, mul( unity_CameraInvProjection,float4({0},1)) ).xyz"; + private const string AseHDClipToObjectPosFormat = "mul( UNITY_MATRIX_I_M, mul( UNITY_MATRIX_I_VP,float4({0},1)) ).xyz"; + + private const string AseClipToWorldPosVarName = "clipToWorld"; + private const string AseClipToWorldPosFormat = "mul( UNITY_MATRIX_I_V, mul( unity_CameraInvProjection,float4({0},1)) ).xyz"; + private const string AseHDClipToWorldPosFormat = "mul( UNITY_MATRIX_I_VP, float4({0},1) ).xyz"; + + private const string AseClipToViewPosVarName = "clipToView"; + private const string AseClipToViewPosFormat = " mul( unity_CameraInvProjection,float4({0},1)).xyz"; + private const string AseHDClipToViewPosFormat = " mul( UNITY_MATRIX_I_P,float4({0},1)).xyz"; + private const string AseClipToNDC = "{0}.xyz/{0}.w"; + ///////////////////////////////////////////////////// + private const string AseObjectToTangentPosVarName = "objectToTangentPos"; + private const string AseWorldToTangentPosVarName = "worldToTangentPos"; + private const string AseViewToTangentPosVarName = "viewToTangentPos"; + private const string AseClipToTangentPosVarName = "clipToTangentPos"; + private const string ASEWorldToTangentFormat = "mul( ase_worldToTangent, {0})"; + + + private const string AseTangentToObjectPosVarName = "tangentTobjectPos"; + private const string AseTangentToWorldPosVarName = "tangentToWorldPos"; + private const string AseTangentToViewPosVarName = "tangentToViewPos"; + private const string AseTangentToClipPosVarName = "tangentToClipPos"; + private const string ASEMulOpFormat = "mul( {0}, {1} )"; + + + /////////////////////////////////////////////////////////// + private const string FromStr = "From"; + private const string ToStr = "To"; + private const string PerpectiveDivideStr = "Perpective Divide"; + private const string SubtitleFormat = "{0} to {1}"; + + private readonly string[] m_spaceOptionsFrom = + { + "Object", + "World", + "View", + "Tangent" + }; + + private readonly string[] m_spaceOptionsTo = + { + "Object", + "World", + "View", + "Tangent", + "Clip" + }; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, Constants.EmptyPortValue ); + AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" ); + m_useInternalPortData = true; + m_autoWrapProperties = true; + m_previewShaderGUID = "74e4d859fbdb2c0468de3612145f4929"; + m_textLabelWidth = 120; + UpdateSubtitle(); + } + + private void UpdateSubtitle() + { + SetAdditonalTitleText( string.Format( SubtitleFormat, m_from, m_to ) ); + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_from = (TransformSpaceFrom)EditorGUILayoutPopup( FromStr, (int)m_from, m_spaceOptionsFrom ); + m_to = (TransformSpaceTo)EditorGUILayoutPopup( ToStr, (int)m_to, m_spaceOptionsTo ); + if( m_from == TransformSpaceFrom.Tangent ) + { + m_inverseTangentType = (InverseTangentType)EditorGUILayoutEnumPopup( InverseTBNStr, m_inverseTangentType ); + } + if( EditorGUI.EndChangeCheck() ) + { + UpdateSubtitle(); + } + + if( m_to == TransformSpaceTo.Clip ) + { + m_perspectiveDivide = EditorGUILayoutToggle( PerpectiveDivideStr, m_perspectiveDivide ); + } + + //if( m_containerGraph.IsHDRP && ( m_from == TransformSpace.Object && m_to == TransformSpace.World ) || + // ( m_from == TransformSpace.World && m_to == TransformSpace.Object ) ) + //{ + // m_absoluteWorldPos = EditorGUILayoutToggle( AbsoluteWorldPosStr, m_absoluteWorldPos ); + //} + } + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + if( (int)m_from != (int)m_to && ( m_from == TransformSpaceFrom.Tangent || m_to == TransformSpaceTo.Tangent ) ) + dataCollector.DirtyNormal = true; + } + + void CalculateTransform( TransformSpaceFrom from, TransformSpaceTo to, ref MasterNodeDataCollector dataCollector, ref string varName, ref string result ) + { + switch( from ) + { + case TransformSpaceFrom.Object: + { + switch( to ) + { + default: + case TransformSpaceTo.Object: break; + case TransformSpaceTo.World: + { + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + { + result = string.Format( AseHDObjectToWorldPosFormat, result ); + if( m_absoluteWorldPos ) + { + result = string.Format( ASEHDAbsoluteWordPos, result ); + } + } + else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight ) + { + result = string.Format( AseHDObjectToWorldPosFormat, result ); + } + } + else + result = string.Format( AseObjectToWorldPosFormat, result ); + + + varName = AseObjectToWorldPosVarName + OutputId; + } + break; + case TransformSpaceTo.View: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + result = string.Format( AseHDObjectToViewPosFormat, result ); + else + result = string.Format( AseObjectToViewPosFormat, result ); + varName = AseObjectToViewPosVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPObjectToClipPosFormat, result ); + } + else + { + result = string.Format( AseObjectToClipPosFormat, result ); + } + varName = AseObjectToClipPosVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.World: + { + switch( to ) + { + case TransformSpaceTo.Object: + { + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + { + if( m_absoluteWorldPos ) + { + result = string.Format( ASEHDRelaviveCameraPos, result ); + } + result = string.Format( AseSRPWorldToObjectPosFormat, result ); + } + else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight ) + { + result = string.Format( AseSRPWorldToObjectPosFormat, result ); + } + + } + else + result = string.Format( AseWorldToObjectPosFormat, result ); + varName = AseWorldToObjectPosVarName + OutputId; + } + break; + default: + case TransformSpaceTo.World: break; + case TransformSpaceTo.View: + { + result = string.Format( AseWorldToViewPosFormat, result ); + varName = AseWorldToViewPosVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPWorldToClipPosFormat, result ); + } + else + { + result = string.Format( AseWorldToClipPosFormat, result ); + } + varName = AseWorldToClipPosVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.View: + { + switch( to ) + { + case TransformSpaceTo.Object: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + result = string.Format( AseHDViewToObjectPosFormat, result ); + else + result = string.Format( AseViewToObjectPosFormat, result ); + varName = AseViewToObjectPosVarName + OutputId; + } + break; + case TransformSpaceTo.World: + { + result = string.Format( AseViewToWorldPosFormat, result ); + varName = AseViewToWorldPosVarName + OutputId; + } + break; + default: + case TransformSpaceTo.View: break; + case TransformSpaceTo.Clip: + { + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.BuiltIn ) + { + result = string.Format( AseSRPViewToClipPosFormat, result ); + } + else + { + result = string.Format( AseViewToClipPosFormat, result ); + } + varName = AseViewToClipPosVarName + OutputId; + } + break; + } + } + break; + //case TransformSpace.Clip: + //{ + // switch( to ) + // { + // case TransformSpace.Object: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToObjectPosFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToObjectPosFormat, result ); + // } + // varName = AseClipToObjectPosVarName + OutputId; + // } + // break; + // case TransformSpace.World: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToWorldPosFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToWorldPosFormat, result ); + // } + // varName = AseClipToWorldPosVarName + OutputId; + // } + // break; + // case TransformSpace.View: + // { + // if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD ) + // { + // result = string.Format( AseHDClipToViewPosFormat, result ); + // } + // else + // { + // result = string.Format( AseClipToViewPosFormat, result ); + // } + // varName = AseClipToViewPosVarName + OutputId; + // } + // break; + // case TransformSpace.Clip: break; + // default: + // break; + // } + //} + //break; + default: break; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + + GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ); + + string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string varName = string.Empty; + + if( (int)m_from == (int)m_to ) + { + RegisterLocalVariable( 0, result, ref dataCollector ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + + switch( m_from ) + { + case TransformSpaceFrom.Object: + { + switch( m_to ) + { + default: + case TransformSpaceTo.Object: break; + case TransformSpaceTo.World: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.View: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + CalculateTransform( m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseObjectToTangentPosVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.World: + { + switch( m_to ) + { + case TransformSpaceTo.Object: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + default: + case TransformSpaceTo.World: break; + case TransformSpaceTo.View: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseWorldToTangentPosVarName + OutputId; + } + break; + } + } + break; + case TransformSpaceFrom.View: + { + switch( m_to ) + { + case TransformSpaceTo.Object: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.World: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); ; + } + break; + default: + case TransformSpaceTo.View: break; + case TransformSpaceTo.Clip: + { + CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + } + break; + case TransformSpaceTo.Tangent: + { + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + CalculateTransform( m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result ); + result = string.Format( ASEWorldToTangentFormat, result ); + varName = AseViewToTangentPosVarName + OutputId; + } + break; + } + } + break; + //case TransformSpace.Clip: + //{ + // switch( m_to ) + // { + // case TransformSpace.Object: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.World: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.View: + // { + // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); + // } + // break; + // case TransformSpace.Clip: break; + // case TransformSpace.Tangent: + // { + // GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + // CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ); + // result = string.Format( ASEWorldToTangentFormat, result ); + // varName = AseClipToTangentPosVarName + OutputId; + // } + // break; + // default: + // break; + // } + //} + //break; + case TransformSpaceFrom.Tangent: + { + string matrixVal = string.Empty; + if( m_inverseTangentType == InverseTangentType.Fast ) + matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixFast( ref dataCollector, UniqueId, CurrentPrecisionType ); + else + matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixPrecise( ref dataCollector, UniqueId, CurrentPrecisionType ); + + switch( m_to ) + { + case TransformSpaceTo.Object: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToObjectPosVarName + OutputId; + } + break; + case TransformSpaceTo.World: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + varName = AseTangentToWorldPosVarName + OutputId; + } + break; + case TransformSpaceTo.View: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToViewPosVarName + OutputId; + } + break; + case TransformSpaceTo.Clip: + { + result = string.Format( ASEMulOpFormat, matrixVal, result ); + CalculateTransform( TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result ); + varName = AseTangentToClipPosVarName + OutputId; + } + break; + case TransformSpaceTo.Tangent: + default: + break; + } + } + break; + default: break; + } + + if( m_to == TransformSpaceTo.Clip ) + { + if( m_perspectiveDivide ) + { + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, varName, result ); + result = string.Format( AseClipToNDC, varName ); + varName += "NDC"; + } + else + { + result += ".xyz"; + } + } + + RegisterLocalVariable( 0, result, ref dataCollector, varName ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + string from = GetCurrentParam( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 17500 && from.Equals( "Clip" ) ) + { + UIUtils.ShowMessage( UniqueId, "Clip Space no longer supported on From field over Transform Position node" ); + } + else + { + m_from = (TransformSpaceFrom)Enum.Parse( typeof( TransformSpaceFrom ), from ); + } + m_to = (TransformSpaceTo)Enum.Parse( typeof( TransformSpaceTo ), GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 15701 ) + { + m_perspectiveDivide = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + if( UIUtils.CurrentShaderVersion() > 15800 ) + { + m_inverseTangentType = (InverseTangentType)Enum.Parse( typeof( InverseTangentType ), GetCurrentParam( ref nodeParams ) ); + } + if( UIUtils.CurrentShaderVersion() > 16103 ) + { + m_absoluteWorldPos = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + UpdateSubtitle(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_from ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_to ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_perspectiveDivide ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_inverseTangentType ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_absoluteWorldPos ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs.meta new file mode 100644 index 00000000..84e1fcd2 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformPositionNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 274dde08d42e4b041b9be7a22a8c09d6 +timeCreated: 1525857790 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs new file mode 100644 index 00000000..1802fe55 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs @@ -0,0 +1,166 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + public enum BuiltInShaderTransformTypes + { + UNITY_MATRIX_MVP = 0, + UNITY_MATRIX_MV, + UNITY_MATRIX_V, + UNITY_MATRIX_P, + UNITY_MATRIX_VP, + UNITY_MATRIX_T_MV, + UNITY_MATRIX_IT_MV, + //UNITY_MATRIX_TEXTURE0, + //UNITY_MATRIX_TEXTURE1, + //UNITY_MATRIX_TEXTURE2, + //UNITY_MATRIX_TEXTURE3, + _Object2World, + _World2Object//, + //unity_Scale + } + + [Serializable] + [NodeAttributes( "Common Transform Matrices", "Matrix Transform", "All Transformation types" )] + public sealed class TransformVariables : ShaderVariablesNode + { + [SerializeField] + private BuiltInShaderTransformTypes m_selectedType = BuiltInShaderTransformTypes.UNITY_MATRIX_MVP; + + private const string MatrixLabelStr = "Matrix"; + private readonly string[] ValuesStr = + { + "Model View Projection", + "Model View", + "View", + "Projection", + "View Projection", + "Transpose Model View", + "Inverse Transpose Model View", + "Object to World", + "Word to Object" + }; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, ValuesStr[ ( int ) m_selectedType ], WirePortDataType.FLOAT4x4 ); + m_textLabelWidth = 60; + m_hasLeftDropdown = true; + m_autoWrapProperties = true; + m_drawPreview = false; + } + + public override void AfterCommonInit() + { + base.AfterCommonInit(); + if( PaddingTitleLeft == 0 ) + { + PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + if( PaddingTitleRight == 0 ) + PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + EditorGUI.BeginChangeCheck(); + m_selectedType = (BuiltInShaderTransformTypes)m_upperLeftWidget.DrawWidget( this, (int)m_selectedType, ValuesStr ); + if( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, ValuesStr[ (int)m_selectedType ] ); + m_sizeIsDirty = true; + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_selectedType = ( BuiltInShaderTransformTypes ) EditorGUILayoutPopup( MatrixLabelStr, ( int ) m_selectedType, ValuesStr ); + if ( EditorGUI.EndChangeCheck() ) + { + ChangeOutputName( 0, ValuesStr[ ( int ) m_selectedType ] ); + m_sizeIsDirty = true; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + switch( m_selectedType ) + { + case BuiltInShaderTransformTypes.UNITY_MATRIX_MVP: + return "mul(GetWorldToHClipMatrix(),GetObjectToWorldMatrix())"; + case BuiltInShaderTransformTypes.UNITY_MATRIX_MV: + return "mul( GetWorldToViewMatrix(),GetObjectToWorldMatrix())"; + case BuiltInShaderTransformTypes.UNITY_MATRIX_V: + return "GetWorldToViewMatrix()"; + case BuiltInShaderTransformTypes.UNITY_MATRIX_P: + return "GetViewToHClipMatrix()"; + case BuiltInShaderTransformTypes.UNITY_MATRIX_VP: + return "GetWorldToHClipMatrix()"; + case BuiltInShaderTransformTypes._Object2World: + return "GetObjectToWorldMatrix()"; + case BuiltInShaderTransformTypes._World2Object: + return "GetWorldToObjectMatrix()"; + case BuiltInShaderTransformTypes.UNITY_MATRIX_T_MV: + case BuiltInShaderTransformTypes.UNITY_MATRIX_IT_MV: + default: + { + UIUtils.ShowMessage( UniqueId, "Matrix not declared natively on SRP. Must create it manually inside ASE" ); + return "float4x4(" + + "1,0,0,0," + + "0,1,0,0," + + "0,0,1,0," + + "0,0,0,1)"; + } + } + } + else + { + return m_selectedType.ToString(); + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + string selectedTypeStr = GetCurrentParam( ref nodeParams ); + try + { + BuiltInShaderTransformTypes selectedType = (BuiltInShaderTransformTypes)Enum.Parse( typeof( BuiltInShaderTransformTypes ), selectedTypeStr ); + m_selectedType = selectedType; + } + catch( Exception e ) + { + switch( selectedTypeStr ) + { + default: Debug.LogException( e );break; + case "UNITY_MATRIX_TEXTURE0":UIUtils.ShowMessage( UniqueId, "Texture 0 matrix is no longer supported",MessageSeverity.Warning);break; + case "UNITY_MATRIX_TEXTURE1":UIUtils.ShowMessage( UniqueId, "Texture 1 matrix is no longer supported",MessageSeverity.Warning);break; + case "UNITY_MATRIX_TEXTURE2":UIUtils.ShowMessage( UniqueId, "Texture 2 matrix is no longer supported",MessageSeverity.Warning);break; + case "UNITY_MATRIX_TEXTURE3":UIUtils.ShowMessage( UniqueId, "Texture 3 matrix is no longer supported",MessageSeverity.Warning); break; + case "unity_Scale": UIUtils.ShowMessage( UniqueId, "Scale matrix is no longer supported", MessageSeverity.Warning ); break; + } + } + + ChangeOutputName( 0, ValuesStr[ ( int ) m_selectedType ] ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs.meta new file mode 100644 index 00000000..d0e613af --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransformVariables.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 04aad5172ee1d4d4795e20bfae0ff64d +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs new file mode 100644 index 00000000..c7c46fe8 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Transpose Model View Matrix", "Matrix Transform", "Transpose of model * view matrix" )] + public sealed class TransposeMVMatrix : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_T_MV"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs.meta new file mode 100644 index 00000000..871d6018 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/TransposeMVMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5762b195353d629448631bfb15fb8372 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs new file mode 100644 index 00000000..09325ec7 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs @@ -0,0 +1,23 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Projector Clip Matrix", "Matrix Transform", "Current Projector Clip matrix. To be used when working with Unity projector." )] + public sealed class UnityProjectorClipMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_ProjectorClip"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + dataCollector.AddToUniforms( UniqueId, "float4x4 unity_ProjectorClip;" ); + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs.meta new file mode 100644 index 00000000..6bc17bde --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorClipMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6095e3e4dc186f146bc109813901ccc8 +timeCreated: 1512062884 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs new file mode 100644 index 00000000..4cfb63c8 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs @@ -0,0 +1,23 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Projector Matrix", "Matrix Transform", "Current Projector Clip matrix. To be used when working with Unity projector." )] + public sealed class UnityProjectorMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_Projector"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + dataCollector.AddToUniforms( UniqueId, "float4x4 unity_Projector;" ); + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs.meta new file mode 100644 index 00000000..0a62ab9f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityProjectorMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c3efd02b48473d94b92302654b671ddc +timeCreated: 1512062884 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs new file mode 100644 index 00000000..2d2f00c9 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Scale Matrix", "Matrix Transform", "Scale Matrix",null, UnityEngine.KeyCode.None, true, true, "Object Scale" )] + public sealed class UnityScaleMatrix : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_Scale"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs.meta new file mode 100644 index 00000000..26f2df76 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/UnityScaleMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 28a04286716e19f4aa58954888374428 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs new file mode 100644 index 00000000..2291bc32 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs @@ -0,0 +1,19 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "View Matrix", "Matrix Transform", "Current view matrix" )] + public sealed class ViewMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_V"; + m_drawPreview = false; + m_matrixId = 0; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs.meta new file mode 100644 index 00000000..bcfb2edc --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5aa75cc5e6044a44a9a4439eac1d948b +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs new file mode 100644 index 00000000..23e53e40 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs @@ -0,0 +1,18 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "View Projection Matrix", "Matrix Transform", "Current view * projection matrix." )] + public sealed class ViewProjectionMatrixNode : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "UNITY_MATRIX_VP"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs.meta new file mode 100644 index 00000000..1a1cd1c4 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/ViewProjectionMatrixNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fe26c99932382e047aebc05b7e67a3d0 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs new file mode 100644 index 00000000..65d9e082 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs @@ -0,0 +1,23 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "World To Camera Matrix", "Matrix Transform", "Inverse of current camera to world matrix" )] + public sealed class WorldToCameraMatrix : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_WorldToCamera"; + m_drawPreview = false; + } + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector ); + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs.meta new file mode 100644 index 00000000..a8d0b7a1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToCameraMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 584bea5554dc1b64c8965d8fcfc54e23 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs new file mode 100644 index 00000000..dd82ebb1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs @@ -0,0 +1,20 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "World To Object Matrix", "Matrix Transform", "Inverse of current world matrix" )] + public sealed class WorldToObjectMatrix : ConstantShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 ); + m_value = "unity_WorldToObject"; + m_HDValue = "GetWorldToObjectMatrix()"; + m_LWValue = "GetWorldToObjectMatrix()"; + m_drawPreview = false; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs.meta new file mode 100644 index 00000000..dd284eb7 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToObjectMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d9e2a5077cc29de439d5c845eac35a04 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs new file mode 100644 index 00000000..194802ef --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs @@ -0,0 +1,47 @@ +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "World To Tangent Matrix", "Matrix Transform", "World to tangent transform matrix" )] + public sealed class WorldToTangentMatrix : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.FLOAT3x3, "Out" ); + //UIUtils.AddNormalDependentCount(); + m_drawPreview = false; + } + + //public override void Destroy() + //{ + // ContainerGraph.RemoveNormalDependentCount(); + // base.Destroy(); + //} + + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + base.PropagateNodeData( nodeData, ref dataCollector ); + dataCollector.DirtyNormal = true; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) + { + if( dataCollector.IsTemplate ) + return dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix( CurrentPrecisionType ); + + if( dataCollector.IsFragmentCategory ) + { + dataCollector.ForceNormal = true; + + dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType ); + dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ); + } + + GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); + + return GeneratorUtils.WorldToTangentStr; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs.meta new file mode 100644 index 00000000..ed19db78 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Transform/WorldToTangentMatrix.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b598d9ebc2d7be44a97270732f55f9bc +timeCreated: 1484747592 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various.meta new file mode 100644 index 00000000..89ede46c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5bbb49ec7f4a3524d9950847c88d4afc +folderAsset: yes +timeCreated: 1481126946 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs new file mode 100644 index 00000000..231a0111 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs @@ -0,0 +1,37 @@ +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Color Space Double", "Miscellaneous", "Color Space Double" )] + public class ColorSpaceDouble : ParentNode + { + private const string ColorSpaceDoubleStr = "unity_ColorSpaceDouble"; + + private readonly string[] ColorSpaceDoubleDef = + { + "#ifdef UNITY_COLORSPACE_GAMMA//ASE Color Space Def", + "#define unity_ColorSpaceDouble half4(2.0, 2.0, 2.0, 2.0)//ASE Color Space Def", + "#else // Linear values//ASE Color Space Def", + "#define unity_ColorSpaceDouble half4(4.59479380, 4.59479380, 4.59479380, 2.0)//ASE Color Space Def", + "#endif//ASE Color Space Def" + }; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputColorPorts( "RGBA" ); + m_previewShaderGUID = "ac680a8772bb97c46851a7f075fd04e3"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + for( int i = 0; i < ColorSpaceDoubleDef.Length; i++ ) + { + dataCollector.AddToDirectives( ColorSpaceDoubleDef[ i ], -1 ); + } + } + return GetOutputVectorItem( 0, outputId, ColorSpaceDoubleStr ); ; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs.meta new file mode 100644 index 00000000..32721b88 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/ColorSpaceDouble.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7d1204234983b3c4499da752961185be +timeCreated: 1481888315 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs new file mode 100644 index 00000000..0570939c --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs @@ -0,0 +1,53 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Face", "Vertex Data", "Indicates whether the rendered surface is facing the camera (1), or facing away from the camera(-1)" )] + public class FaceVariableNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.FLOAT, "Out" ); + m_previewShaderGUID = "4b0b5b9f16353b840a5f5ad2baab3c3c"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " node does not work on Tessellation port" ); + return m_outputPorts[0].ErrorValue; + } + + if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex ) + { + if ( dataCollector.TesselationActive ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " node does not work properly on Vertex/Tessellation ports" ); + return m_outputPorts[ 0 ].ErrorValue; + } + else + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " node does not work propery on Vertex ports" ); + return m_outputPorts[ 0 ].ErrorValue; + } + } + + if ( dataCollector.IsTemplate ) + { + return dataCollector.TemplateDataCollectorInstance.GetVFace( UniqueId ); + } + else + { + dataCollector.AddToInput( UniqueId, SurfaceInputs.VFACE ); + string variable = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex ) ? Constants.VertexShaderOutputStr : Constants.InputVarStr; + return variable + "." + Constants.VFaceVariable; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs.meta new file mode 100644 index 00000000..b583327e --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/FaceVariableNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4b4a6f07436b05a4cbc2559e4e704000 +timeCreated: 1492513159 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs new file mode 100644 index 00000000..c845e063 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs @@ -0,0 +1,43 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Instance ID", "Vertex Data", "Indicates the per-instance identifier" )] + public class InstanceIdNode : ParentNode + { + private readonly string[] InstancingVariableAttrib = + { "uint currInstanceId = 0;", + "#ifdef UNITY_INSTANCING_ENABLED", + "currInstanceId = unity_InstanceID;", + "#endif"}; + private const string InstancingInnerVariable = "currInstanceId"; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.INT, "Out" ); + m_previewShaderGUID = "03febce56a8cf354b90e7d5180c1dbd7"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsTemplate ) + { + dataCollector.TemplateDataCollectorInstance.SetupInstancing(); + } + + if( !dataCollector.HasLocalVariable( InstancingVariableAttrib[ 0 ] ) ) + { + dataCollector.AddLocalVariable( UniqueId, InstancingVariableAttrib[ 0 ] ,true ); + dataCollector.AddLocalVariable( UniqueId, InstancingVariableAttrib[ 1 ] ,true ); + dataCollector.AddLocalVariable( UniqueId, InstancingVariableAttrib[ 2 ] ,true ); + dataCollector.AddLocalVariable( UniqueId, InstancingVariableAttrib[ 3 ] ,true ); + } + return InstancingInnerVariable; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs.meta new file mode 100644 index 00000000..efae4fb9 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/InstanceIdNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c449923583a9fbe4283acebc97756ea1 +timeCreated: 1547811127 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs new file mode 100644 index 00000000..f2a1959f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs @@ -0,0 +1,44 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "LOD Fade", "Miscellaneous", "LODFadeNode" )] + public sealed class LODFadeNode : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "Fade[0...1]" ); + ChangeOutputName( 2, "Fade[16Lvl]" ); + ChangeOutputName( 3, "Unused" ); + ChangeOutputName( 4, "Unused" ); + m_value = "unity_LODFade"; + m_previewShaderGUID = "fcd4d93f57ffc51458d4ade10df2fdb4"; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + + if( !m_outputPorts[ 3 ].IsConnected ) + { + m_outputPorts[ 3 ].Visible = false; + m_sizeIsDirty = true; + } + + if( !m_outputPorts[ 4 ].IsConnected ) + { + m_outputPorts[ 4 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs.meta new file mode 100644 index 00000000..a83635a4 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/LODFadeNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f96cf34c2936c96458403e9cf75e8e10 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs new file mode 100644 index 00000000..b60f8472 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs @@ -0,0 +1,38 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +#if UNITY_EDITOR_WIN +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Primitive ID", "Vertex Data", "Per-primitive identifier automatically generated by the runtime" )] + public class PrimitiveIDVariableNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.INT, "Out" ); + m_previewShaderGUID = "92c1b588d7658594cb219696f593f64b"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( !dataCollector.IsTemplate ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " is not supported on surface shaders." ); + return m_outputPorts[0].ErrorValue; + } + + if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " is not supported on Vertex ports" ); + return m_outputPorts[0].ErrorValue; + } + + return dataCollector.TemplateDataCollectorInstance.GetPrimitiveId(); + } + } +} +#endif + diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs.meta new file mode 100644 index 00000000..6d7d119b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/PrimitiveIdVariableNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dd0af9fbbba750341a7b09316178f285 +timeCreated: 1492513159 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs new file mode 100644 index 00000000..6bfd7f36 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs @@ -0,0 +1,70 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Switch by Face", "Miscellaneous", "Switch which automaticaly uses a Face variable to select which input to use" )] + public class SwitchByFaceNode : DynamicTypeNode + { + private const string SwitchOp = "((({0}>0)?({1}):({2})))"; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_inputPorts[ 0 ].Name = "Front"; + m_inputPorts[ 1 ].Name = "Back"; + m_textLabelWidth = 50; + m_previewShaderGUID = "f4edf6febb54dc743b25bd5b56facea8"; + } + + + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " does not work on Tessellation port" ); + return GenerateErrorValue(); + } + + if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex ) + { + if ( dataCollector.TesselationActive ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " does not work properly on Vertex/Tessellation ports" ); + return GenerateErrorValue(); + } + else + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " does not work properly on Vertex ports" ); + return GenerateErrorValue(); + } + } + + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + string front = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string back = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + + dataCollector.AddToInput( UniqueId, SurfaceInputs.VFACE ); + string variable = string.Empty; + if ( dataCollector.IsTemplate ) + { + variable = dataCollector.TemplateDataCollectorInstance.GetVFace( UniqueId ); + } + else + { + variable = ( ( dataCollector.PortCategory == MasterNodePortCategory.Vertex ) ? Constants.VertexShaderOutputStr : Constants.InputVarStr ) + "." + Constants.VFaceVariable; + } + + string value = string.Format( SwitchOp, variable, front, back ); + RegisterLocalVariable( 0, value, ref dataCollector, "switchResult" + OutputId ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs.meta new file mode 100644 index 00000000..b12692c4 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/SwitchByFaceNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b0464d8b27caa7d4d8fa5d1828934da8 +timeCreated: 1492515561 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs new file mode 100644 index 00000000..d2b75192 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs @@ -0,0 +1,54 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Vertex ID", "Vertex Data", "Indicates current vertex number" )] + public class VertexIdVariableNode : ParentNode + { + private const string VertexIdVarName = "ase_vertexId"; + private const string VertexIdRegistry = "uint "+ VertexIdVarName + " : SV_VertexID;"; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.INT, "Out" ); + m_previewShaderGUID = "5934bf2c10b127a459177a3b622cea65"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + UIUtils.ShowMessage( UniqueId, m_nodeAttribs.Name + " does not work on Tessellation port" ); + return m_outputPorts[0].ErrorValue; + } + + if ( dataCollector.IsTemplate ) + { + return dataCollector.TemplateDataCollectorInstance.GetVertexId(); + } + else + { + if( dataCollector.IsFragmentCategory ) + { + GenerateValueInVertex( ref dataCollector, WirePortDataType.UINT, Constants.VertexShaderInputStr + "."+ VertexIdVarName, VertexIdVarName, true ); + return Constants.InputVarStr + "."+ VertexIdVarName; + } + else + { + return Constants.VertexShaderInputStr + "."+ VertexIdVarName; + } + } + } + public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector ) + { + if( !dataCollector.IsTemplate ) + dataCollector.AddCustomAppData( VertexIdRegistry ); + + base.PropagateNodeData( nodeData, ref dataCollector ); + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs.meta new file mode 100644 index 00000000..cad8fe04 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/VertexIdVariableNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ce37a30cae7677942ad44f0945ab7b77 +timeCreated: 1492513159 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs new file mode 100644 index 00000000..49966a09 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "World Transform Params", "Object Transform", "World Transform Params contains information about the transform, W is usually 1.0, or -1.0 for odd-negative scale transforms" )] + public sealed class WorldTransformParams : ConstVecShaderVariable + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + ChangeOutputName( 1, "X" ); + ChangeOutputName( 2, "Y" ); + ChangeOutputName( 3, "Z" ); + ChangeOutputName( 4, "W" ); + m_value = "unity_WorldTransformParams"; + m_previewShaderGUID = "5a2642605f085da458d6e03ade47b87a"; + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + if( !m_outputPorts[ 0 ].IsConnected ) + { + m_outputPorts[ 0 ].Visible = false; + m_sizeIsDirty = true; + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs.meta new file mode 100644 index 00000000..b28aa84a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Various/WorldTransformParams.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: aec376443deca354789bc36ba18af898 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs new file mode 100644 index 00000000..6704cbee --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs @@ -0,0 +1,1197 @@ +// Amplify Shader Editor - Visual Shader vEditing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Static Switch", "Logical Operators", "Creates a shader keyword toggle", Available = true )] + public sealed class StaticSwitch : PropertyNode + { + private float InstanceIconWidth = 19; + private float InstanceIconHeight = 19; + private readonly Color ReferenceHeaderColor = new Color( 0f, 0.5f, 0.585f, 1.0f ); + + [SerializeField] + private int m_defaultValue = 0; + + [SerializeField] + private int m_materialValue = 0; + + [SerializeField] + private int m_multiCompile = 0; + + [SerializeField] + private int m_currentKeywordId = 0; + + [SerializeField] + private string m_currentKeyword = string.Empty; + + [SerializeField] + private bool m_createToggle = true; + + private const string IsLocalStr = "Is Local"; +#if UNITY_2019_1_OR_NEWER + [SerializeField] + private bool m_isLocal = true; +#else + [SerializeField] + private bool m_isLocal = false; +#endif + private GUIContent m_checkContent; + private GUIContent m_popContent; + + private int m_conditionId = -1; + + private const int MinComboSize = 50; + private const int MaxComboSize = 105; + + private Rect m_varRect; + private Rect m_imgRect; + private bool m_editing; + + public enum KeywordModeType + { + Toggle = 0, + ToggleOff, + KeywordEnum, + } + + public enum StaticSwitchVariableMode + { + Create = 0, + Fetch, + Reference + } + + [SerializeField] + private KeywordModeType m_keywordModeType = KeywordModeType.Toggle; + + [SerializeField] + private StaticSwitch m_reference = null; + + private const string StaticSwitchStr = "Static Switch"; + private const string MaterialToggleStr = "Material Toggle"; + + private const string ToggleMaterialValueStr = "Material Value"; + private const string ToggleDefaultValueStr = "Default Value"; + + private const string AmountStr = "Amount"; + private const string KeywordStr = "Keyword"; + private const string CustomStr = "Custom"; + private const string ToggleTypeStr = "Toggle Type"; + private const string TypeStr = "Type"; + private const string ModeStr = "Mode"; + private const string KeywordTypeStr = "Keyword Type"; + + private const string KeywordNameStr = "Keyword Name"; + public readonly static string[] KeywordTypeList = { "Shader Feature", "Multi Compile"/*, "Define Symbol"*/ }; + public readonly static int[] KeywordTypeInt = { 0, 1/*, 2*/ }; + + [SerializeField] + private string[] m_defaultKeywordNames = { "Key0", "Key1", "Key2", "Key3", "Key4", "Key5", "Key6", "Key7", "Key8" }; + + [SerializeField] + private string[] m_keywordEnumList = { "Key0", "Key1" }; + + [SerializeField] + private StaticSwitchVariableMode m_staticSwitchVarMode = StaticSwitchVariableMode.Create; + + [SerializeField] + private int m_referenceArrayId = -1; + + [SerializeField] + private int m_referenceNodeId = -1; + + private int m_keywordEnumAmount = 2; + + private bool m_isStaticSwitchDirty = false; + + private Rect m_iconPos; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + AddInputPort( WirePortDataType.FLOAT, false, "False", -1, MasterNodePortCategory.Fragment, 1 ); + AddInputPort( WirePortDataType.FLOAT, false, "True", -1, MasterNodePortCategory.Fragment, 0 ); + for( int i = 2; i < 9; i++ ) + { + AddInputPort( WirePortDataType.FLOAT, false, m_defaultKeywordNames[ i ] ); + m_inputPorts[ i ].Visible = false; + } + m_headerColor = new Color( 0.0f, 0.55f, 0.45f, 1f ); + m_customPrefix = KeywordStr + " "; + m_autoWrapProperties = false; + m_freeType = false; + m_useVarSubtitle = true; + m_allowPropertyDuplicates = true; + m_showTitleWhenNotEditing = false; + m_currentParameterType = PropertyType.Property; + + m_checkContent = new GUIContent(); + m_checkContent.image = UIUtils.CheckmarkIcon; + + m_popContent = new GUIContent(); + m_popContent.image = UIUtils.PopupIcon; + + m_previewShaderGUID = "0b708c11c68e6a9478ac97fe3643eab1"; + m_showAutoRegisterUI = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_conditionId == -1 ) + m_conditionId = Shader.PropertyToID( "_Condition" ); + + StaticSwitch node = ( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null ) ? m_reference : this; + + if( m_createToggle ) + PreviewMaterial.SetInt( m_conditionId, node.MaterialValue ); + else + PreviewMaterial.SetInt( m_conditionId, node.DefaultValue ); + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + + if( m_createToggle ) + UIUtils.RegisterPropertyNode( this ); + else + UIUtils.UnregisterPropertyNode( this ); + + if( CurrentVarMode != StaticSwitchVariableMode.Reference ) + { + ContainerGraph.StaticSwitchNodes.AddNode( this ); + } + + if( UniqueId > -1 ) + ContainerGraph.StaticSwitchNodes.OnReorderEventComplete += OnReorderEventComplete; + } + + public override void Destroy() + { + base.Destroy(); + UIUtils.UnregisterPropertyNode( this ); + if( CurrentVarMode != StaticSwitchVariableMode.Reference ) + { + ContainerGraph.StaticSwitchNodes.RemoveNode( this ); + } + + if( UniqueId > -1 ) + ContainerGraph.StaticSwitchNodes.OnReorderEventComplete -= OnReorderEventComplete; + } + + void OnReorderEventComplete() + { + if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + if( m_reference != null ) + { + m_referenceArrayId = ContainerGraph.StaticSwitchNodes.GetNodeRegisterIdx( m_reference.UniqueId ); + } + } + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnections(); + } + + public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnections(); + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + UpdateConnections(); + } + + private void UpdateConnections() + { + WirePortDataType mainType = WirePortDataType.FLOAT; + + int highest = UIUtils.GetPriority( mainType ); + for( int i = 0; i < m_inputPorts.Count; i++ ) + { + if( m_inputPorts[ i ].IsConnected ) + { + WirePortDataType portType = m_inputPorts[ i ].GetOutputConnection().DataType; + if( UIUtils.GetPriority( portType ) > highest ) + { + mainType = portType; + highest = UIUtils.GetPriority( portType ); + } + } + } + + for( int i = 0; i < m_inputPorts.Count; i++ ) + { + m_inputPorts[ i ].ChangeType( mainType, false ); + } + + m_outputPorts[ 0 ].ChangeType( mainType, false ); + } + + public override string GetPropertyValue() + { + if( m_createToggle ) + if( m_keywordModeType == KeywordModeType.KeywordEnum && m_keywordEnumAmount > 0 ) + return PropertyAttributes + "[" + m_keywordModeType.ToString() + "(" + GetKeywordEnumPropertyList() + ")] " + m_propertyName + "(\"" + m_propertyInspectorName + "\", Float) = " + m_defaultValue; + else + return PropertyAttributes + "[" + m_keywordModeType.ToString() + "(" + GetPropertyValStr() + ")] " + m_propertyName + "(\"" + m_propertyInspectorName + "\", Float) = " + m_defaultValue; + else + return string.Empty; + } + + public string KeywordEnum( int index ) + { + if( m_createToggle ) + { + return string.IsNullOrEmpty( PropertyName ) ? KeywordEnumList( index ) : ( PropertyName + "_" + KeywordEnumList( index ) ); + } + else + { + return string.IsNullOrEmpty( PropertyName ) ? KeywordEnumList( index ) : ( PropertyName + KeywordEnumList( index ) ); + } + } + + public string KeywordEnumList( int index ) + { + if( CurrentVarMode == StaticSwitchVariableMode.Fetch ) + return m_keywordEnumList[ index ]; + else + { + return m_createToggle ? m_keywordEnumList[ index ].ToUpper() : m_keywordEnumList[ index ]; + } + + } + public override string PropertyName + { + get + { + if( CurrentVarMode == StaticSwitchVariableMode.Fetch ) + return m_currentKeyword; + else + { + return m_createToggle ? base.PropertyName.ToUpper() : base.PropertyName; + } + } + } + + public override string GetPropertyValStr() + { + if( m_keywordModeType == KeywordModeType.KeywordEnum ) + return PropertyName; + else if( CurrentVarMode == StaticSwitchVariableMode.Fetch ) + return m_currentKeyword; + else + return PropertyName + OnOffStr; + } + + private string GetKeywordEnumPropertyList() + { + string result = string.Empty; + for( int i = 0; i < m_keywordEnumList.Length; i++ ) + { + if( i == 0 ) + result = m_keywordEnumList[ i ]; + else + result += "," + m_keywordEnumList[ i ]; + } + return result; + } + + private string GetKeywordEnumPragmaList() + { + string result = string.Empty; + for( int i = 0; i < m_keywordEnumList.Length; i++ ) + { + if( i == 0 ) + result = KeywordEnum( i ); + else + result += " " + KeywordEnum( i ); + } + return result; + } + + public override string GetUniformValue() + { + return string.Empty; + } + + public override bool GetUniformData( out string dataType, out string dataName, ref bool fullValue ) + { + dataType = string.Empty; + dataName = string.Empty; + return false; + } + + public override void DrawProperties() + { + //base.DrawProperties(); + NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, PropertyGroup ); + NodeUtils.DrawPropertyGroup( ref m_visibleCustomAttrFoldout, CustomAttrStr, DrawCustomAttributes, DrawCustomAttrAddRemoveButtons ); + CheckPropertyFromInspector(); + } + + void DrawEnumList() + { + EditorGUI.BeginChangeCheck(); + KeywordEnumAmount = EditorGUILayoutIntSlider( AmountStr, KeywordEnumAmount, 2, 9 ); + if( EditorGUI.EndChangeCheck() ) + { + CurrentSelectedInput = Mathf.Clamp( CurrentSelectedInput, 0, KeywordEnumAmount - 1 ); + UpdateLabels(); + } + EditorGUI.indentLevel++; + for( int i = 0; i < m_keywordEnumList.Length; i++ ) + { + EditorGUI.BeginChangeCheck(); + m_keywordEnumList[ i ] = EditorGUILayoutTextField( "Item " + i, m_keywordEnumList[ i ] ); + if( EditorGUI.EndChangeCheck() ) + { + m_keywordEnumList[ i ] = UIUtils.RemoveInvalidEnumCharacters( m_keywordEnumList[ i ] ); + m_keywordEnumList[ i ] = m_keywordEnumList[ i ].Replace( " ", "" ); // sad face :( does not support spaces + m_inputPorts[ i ].Name = m_keywordEnumList[ i ]; + m_defaultKeywordNames[ i ] = m_inputPorts[ i ].Name; + } + } + EditorGUI.indentLevel--; + } + + public void UpdateLabels() + { + int maxinputs = m_keywordModeType == KeywordModeType.KeywordEnum ? KeywordEnumAmount : 2; + KeywordEnumAmount = Mathf.Clamp( KeywordEnumAmount, 0, maxinputs ); + m_keywordEnumList = new string[ maxinputs ]; + + for( int i = 0; i < maxinputs; i++ ) + { + m_keywordEnumList[ i ] = m_defaultKeywordNames[ i ]; + m_inputPorts[ i ].Name = m_keywordEnumList[ i ]; + } + + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + m_inputPorts[ 0 ].Name = "False"; + m_inputPorts[ 1 ].Name = "True"; + } + + for( int i = 0; i < m_inputPorts.Count; i++ ) + { + m_inputPorts[ i ].Visible = ( i < maxinputs ); + } + m_sizeIsDirty = true; + m_isStaticSwitchDirty = true; + } + + void PropertyGroup() + { + EditorGUI.BeginChangeCheck(); + CurrentVarMode = (StaticSwitchVariableMode)EditorGUILayoutEnumPopup( ModeStr, CurrentVarMode ); + if( EditorGUI.EndChangeCheck() ) + { + if( CurrentVarMode == StaticSwitchVariableMode.Fetch ) + { + m_keywordModeType = KeywordModeType.Toggle; + UpdateLabels(); + } + + if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + UIUtils.UnregisterPropertyNode( this ); + } + else + { + if( m_createToggle ) + UIUtils.RegisterPropertyNode( this ); + else + UIUtils.UnregisterPropertyNode( this ); + } + } + + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + EditorGUI.BeginChangeCheck(); + m_multiCompile = EditorGUILayoutIntPopup( KeywordTypeStr, m_multiCompile, KeywordTypeList, KeywordTypeInt ); + if( EditorGUI.EndChangeCheck() ) + { + BeginPropertyFromInspectorCheck(); + } + } + else if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + string[] arr = ContainerGraph.StaticSwitchNodes.NodesArr; + bool guiEnabledBuffer = GUI.enabled; + if( arr != null && arr.Length > 0 ) + { + GUI.enabled = true; + } + else + { + m_referenceArrayId = -1; + GUI.enabled = false; + } + + EditorGUI.BeginChangeCheck(); + m_referenceArrayId = EditorGUILayoutPopup( Constants.AvailableReferenceStr, m_referenceArrayId, arr ); + if( EditorGUI.EndChangeCheck() ) + { + m_reference = ContainerGraph.StaticSwitchNodes.GetNode( m_referenceArrayId ); + if( m_reference != null ) + { + m_referenceNodeId = m_reference.UniqueId; + CheckReferenceValues( true ); + } + else + { + m_referenceArrayId = -1; + m_referenceNodeId = -1; + } + } + GUI.enabled = guiEnabledBuffer; + + return; + } + + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + EditorGUI.BeginChangeCheck(); + m_keywordModeType = (KeywordModeType)EditorGUILayoutEnumPopup( TypeStr, m_keywordModeType ); + if( EditorGUI.EndChangeCheck() ) + { + UpdateLabels(); + } + } + + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( true ); + bool guiEnabledBuffer = GUI.enabled; + GUI.enabled = false; + EditorGUILayout.TextField( KeywordNameStr, GetPropertyValStr() ); + GUI.enabled = guiEnabledBuffer; + } + + } + else + { + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + ShowPropertyInspectorNameGUI(); + ShowPropertyNameGUI( true ); + DrawEnumList(); + } + + } + + if( CurrentVarMode == StaticSwitchVariableMode.Fetch ) + { + //ShowPropertyInspectorNameGUI(); + EditorGUI.BeginChangeCheck(); + m_currentKeywordId = EditorGUILayoutPopup( KeywordStr, m_currentKeywordId, UIUtils.AvailableKeywords ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_currentKeywordId != 0 ) + { + m_currentKeyword = UIUtils.AvailableKeywords[ m_currentKeywordId ]; + } + } + + if( m_currentKeywordId == 0 ) + { + EditorGUI.BeginChangeCheck(); + m_currentKeyword = EditorGUILayoutTextField( CustomStr, m_currentKeyword ); + if( EditorGUI.EndChangeCheck() ) + { + m_currentKeyword = UIUtils.RemoveInvalidCharacters( m_currentKeyword ); + } + } + } + +#if UNITY_2019_1_OR_NEWER + m_isLocal = EditorGUILayoutToggle( IsLocalStr, m_isLocal ); +#endif + + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + ShowAutoRegister(); + } + + EditorGUI.BeginChangeCheck(); + m_createToggle = EditorGUILayoutToggle( MaterialToggleStr, m_createToggle ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_createToggle ) + UIUtils.RegisterPropertyNode( this ); + else + UIUtils.UnregisterPropertyNode( this ); + } + + + if( m_createToggle ) + { + EditorGUILayout.BeginHorizontal(); + GUILayout.Space( 20 ); + m_propertyTab = GUILayout.Toolbar( m_propertyTab, LabelToolbarTitle ); + EditorGUILayout.EndHorizontal(); + switch( m_propertyTab ) + { + default: + case 0: + { + EditorGUI.BeginChangeCheck(); + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + m_materialValue = EditorGUILayoutToggle( ToggleMaterialValueStr, m_materialValue == 1 ) ? 1 : 0; + else + m_materialValue = EditorGUILayoutPopup( ToggleMaterialValueStr, m_materialValue, m_keywordEnumList ); + if( EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + } + break; + case 1: + { + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + m_defaultValue = EditorGUILayoutToggle( ToggleDefaultValueStr, m_defaultValue == 1 ) ? 1 : 0; + else + m_defaultValue = EditorGUILayoutPopup( ToggleDefaultValueStr, m_defaultValue, m_keywordEnumList ); + } + break; + } + } + + //EditorGUILayout.HelpBox( "Keyword Type:\n" + + // "The difference is that unused variants of \"Shader Feature\" shaders will not be included into game build while \"Multi Compile\" variants are included regardless of their usage.\n\n" + + // "So \"Shader Feature\" makes most sense for keywords that will be set on the materials, while \"Multi Compile\" for keywords that will be set from code globally.\n\n" + + // "You can set keywords using the material property using the \"Property Name\" or you can set the keyword directly using the \"Keyword Name\".", MessageType.None ); + } + + public override void CheckPropertyFromInspector( bool forceUpdate = false ) + { + if( m_propertyFromInspector ) + { + if( forceUpdate || ( EditorApplication.timeSinceStartup - m_propertyFromInspectorTimestamp ) > MaxTimestamp ) + { + m_propertyFromInspector = false; + RegisterPropertyName( true, m_propertyInspectorName, m_autoGlobalName, m_underscoredGlobal ); + m_propertyNameIsDirty = true; + + if( CurrentVarMode != StaticSwitchVariableMode.Reference ) + { + ContainerGraph.StaticSwitchNodes.UpdateDataOnNode( UniqueId, DataToArray ); + } + } + } + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + float finalSize = 0; + if( m_keywordModeType == KeywordModeType.KeywordEnum ) + { + GUIContent dropdown = new GUIContent( m_inputPorts[ CurrentSelectedInput ].Name ); + int cacheSize = UIUtils.GraphDropDown.fontSize; + UIUtils.GraphDropDown.fontSize = 10; + Vector2 calcSize = UIUtils.GraphDropDown.CalcSize( dropdown ); + UIUtils.GraphDropDown.fontSize = cacheSize; + finalSize = Mathf.Clamp( calcSize.x, MinComboSize, MaxComboSize ); + if( m_insideSize.x != finalSize ) + { + m_insideSize.Set( finalSize, 25 ); + m_sizeIsDirty = true; + } + } + + base.OnNodeLayout( drawInfo ); + + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + m_varRect = m_remainingBox; + m_varRect.size = Vector2.one * 22 * drawInfo.InvertedZoom; + m_varRect.center = m_remainingBox.center; + if( m_showPreview ) + m_varRect.y = m_remainingBox.y; + } + else + { + m_varRect = m_remainingBox; + m_varRect.width = finalSize * drawInfo.InvertedZoom; + m_varRect.height = 16 * drawInfo.InvertedZoom; + m_varRect.x = m_remainingBox.xMax - m_varRect.width; + m_varRect.y += 1 * drawInfo.InvertedZoom; + + m_imgRect = m_varRect; + m_imgRect.x = m_varRect.xMax - 16 * drawInfo.InvertedZoom; + m_imgRect.width = 16 * drawInfo.InvertedZoom; + m_imgRect.height = m_imgRect.width; + } + + CheckReferenceValues( false ); + + if( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference ) + { + m_iconPos = m_globalPosition; + m_iconPos.width = InstanceIconWidth * drawInfo.InvertedZoom; + m_iconPos.height = InstanceIconHeight * drawInfo.InvertedZoom; + + m_iconPos.y += 10 * drawInfo.InvertedZoom; + m_iconPos.x += /*m_globalPosition.width - m_iconPos.width - */5 * drawInfo.InvertedZoom; + } + + } + + void CheckReferenceValues( bool forceUpdate ) + { + if( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference ) + { + if( m_reference == null && m_referenceNodeId > 0 ) + { + m_reference = ContainerGraph.GetNode( m_referenceNodeId ) as StaticSwitch; + m_referenceArrayId = ContainerGraph.StaticSwitchNodes.GetNodeRegisterIdx( m_referenceNodeId ); + } + + if( m_reference != null ) + { + if( forceUpdate || m_reference.IsStaticSwitchDirty ) + { + int count = m_inputPorts.Count; + for( int i = 0; i < count; i++ ) + { + m_inputPorts[ i ].Name = m_reference.InputPorts[ i ].Name; + m_inputPorts[ i ].Visible = m_reference.InputPorts[ i ].Visible; + } + m_sizeIsDirty = true; + } + } + } + else + { + m_isStaticSwitchDirty = false; + } + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( drawInfo.CurrentEventType != EventType.MouseDown || !m_createToggle ) + return; + + if( m_varRect.Contains( drawInfo.MousePosition ) ) + { + m_editing = true; + } + else if( m_editing ) + { + m_editing = false; + } + } + + private int CurrentSelectedInput + { + get + { + return m_materialMode ? m_materialValue : m_defaultValue; + } + set + { + if( m_materialMode ) + m_materialValue = value; + else + m_defaultValue = value; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + if( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference ) + return; + + if( m_editing ) + { + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + if( GUI.Button( m_varRect, GUIContent.none, UIUtils.GraphButton ) ) + { + CurrentSelectedInput = CurrentSelectedInput == 1 ? 0 : 1; + PreviewIsDirty = true; + m_editing = false; + if( m_materialMode ) + m_requireMaterialUpdate = true; + } + + if( CurrentSelectedInput == 1 ) + { + GUI.Label( m_varRect, m_checkContent, UIUtils.GraphButtonIcon ); + } + } + else + { + EditorGUI.BeginChangeCheck(); + CurrentSelectedInput = EditorGUIPopup( m_varRect, CurrentSelectedInput, m_keywordEnumList, UIUtils.GraphDropDown ); + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_editing = false; + if( m_materialMode ) + m_requireMaterialUpdate = true; + } + } + } + } + + public override void OnNodeRepaint( DrawInfo drawInfo ) + { + base.OnNodeRepaint( drawInfo ); + + if( !m_isVisible ) + return; + + if( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference ) + { + GUI.Label( m_iconPos, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerTextureIcon ) ); + return; + } + + if( m_createToggle && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 ) + { + if( !m_editing ) + { + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + GUI.Label( m_varRect, GUIContent.none, UIUtils.GraphButton ); + + if( CurrentSelectedInput == 1 ) + GUI.Label( m_varRect, m_checkContent, UIUtils.GraphButtonIcon ); + } + else + { + GUI.Label( m_varRect, m_keywordEnumList[ CurrentSelectedInput ], UIUtils.GraphDropDown ); + GUI.Label( m_imgRect, m_popContent, UIUtils.GraphButtonIcon ); + } + } + } + } + + private string OnOffStr + { + get + { + StaticSwitch node = null; + switch( CurrentVarMode ) + { + default: + case StaticSwitchVariableMode.Create: + case StaticSwitchVariableMode.Fetch: + node = this; + break; + case StaticSwitchVariableMode.Reference: + { + node = ( m_reference != null ) ? m_reference : this; + } + break; + } + + if( !node.CreateToggle ) + return string.Empty; + + switch( node.KeywordModeTypeValue ) + { + default: + case KeywordModeType.Toggle: + return "_ON"; + case KeywordModeType.ToggleOff: + return "_OFF"; + } + } + } + string GetStaticSwitchType() + { + string staticSwitchType = ( m_multiCompile == 1 ) ? "multi_compile" : "shader_feature"; +#if UNITY_2019_1_OR_NEWER + if( m_isLocal ) + staticSwitchType += "_local"; +#endif + return staticSwitchType; + } + + void RegisterPragmas( ref MasterNodeDataCollector dataCollector ) + { + if( CurrentVarMode == StaticSwitchVariableMode.Create ) + { + string staticSwitchType = GetStaticSwitchType(); + if( m_keywordModeType == KeywordModeType.KeywordEnum ) + { + if( m_multiCompile == 1 ) + dataCollector.AddToPragmas( UniqueId, staticSwitchType + " " + GetKeywordEnumPragmaList() ); + else if( m_multiCompile == 0 ) + dataCollector.AddToPragmas( UniqueId, staticSwitchType + " " + GetKeywordEnumPragmaList() ); + } + else + { + if( m_multiCompile == 1 ) + dataCollector.AddToPragmas( UniqueId, staticSwitchType + " __ " + PropertyName + OnOffStr ); + else if( m_multiCompile == 0 ) + dataCollector.AddToPragmas( UniqueId, staticSwitchType + " " + PropertyName + OnOffStr ); + } + } + } + + protected override void RegisterProperty( ref MasterNodeDataCollector dataCollector ) + { + if( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null ) + { + m_reference.RegisterProperty( ref dataCollector ); + m_reference.RegisterPragmas( ref dataCollector ); + } + else + { + if( m_createToggle ) + base.RegisterProperty( ref dataCollector ); + + RegisterPragmas( ref dataCollector ); + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + StaticSwitch node = ( m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null ) ? m_reference : this; + + this.OrderIndex = node.RawOrderIndex; + this.OrderIndexOffset = node.OrderIndexOffset; + //if( m_keywordModeType == KeywordModeType.KeywordEnum ) + + //node.RegisterPragmas( ref dataCollector ); + + string outType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if( node.KeywordModeTypeValue == KeywordModeType.KeywordEnum ) + { + string defaultKey = "\t" + outType + " staticSwitch" + OutputId + " = " + m_inputPorts[ node.DefaultValue ].GeneratePortInstructions( ref dataCollector ) + ";"; + + string[] allOutputs = new string[ node.KeywordEnumAmount ]; + for( int i = 0; i < node.KeywordEnumAmount; i++ ) + allOutputs[ i ] = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector ); + + for( int i = 0; i < node.KeywordEnumAmount; i++ ) + { + string keyword = node.KeywordEnum( i ); + if( i == 0 ) + dataCollector.AddLocalVariable( UniqueId, "#if defined(" + keyword + ")", true ); + else + dataCollector.AddLocalVariable( UniqueId, "#elif defined(" + keyword + ")", true ); + + if( node.DefaultValue == i ) + dataCollector.AddLocalVariable( UniqueId, defaultKey, true ); + else + dataCollector.AddLocalVariable( UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + allOutputs[ i ] + ";", true ); + } + dataCollector.AddLocalVariable( UniqueId, "#else", true ); + dataCollector.AddLocalVariable( UniqueId, defaultKey, true ); + dataCollector.AddLocalVariable( UniqueId, "#endif", true ); + } + else + { + string falseCode = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string trueCode = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + + if( node.CurrentVarMode == StaticSwitchVariableMode.Fetch ) + dataCollector.AddLocalVariable( UniqueId, "#ifdef " + node.CurrentKeyword, true ); + else + dataCollector.AddLocalVariable( UniqueId, "#ifdef " + node.PropertyName + OnOffStr, true ); + dataCollector.AddLocalVariable( UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + trueCode + ";", true ); + dataCollector.AddLocalVariable( UniqueId, "#else", true ); + dataCollector.AddLocalVariable( UniqueId, "\t" + outType + " staticSwitch" + OutputId + " = " + falseCode + ";", true ); + dataCollector.AddLocalVariable( UniqueId, "#endif", true ); + } + + m_outputPorts[ 0 ].SetLocalValue( "staticSwitch" + OutputId, dataCollector.PortCategory ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + public override void DrawTitle( Rect titlePos ) + { + bool referenceMode = m_staticSwitchVarMode == StaticSwitchVariableMode.Reference && m_reference != null; + string subTitle = string.Empty; + string subTitleFormat = string.Empty; + if( referenceMode ) + { + subTitle = m_reference.GetPropertyValStr(); + subTitleFormat = Constants.SubTitleRefNameFormatStr; + } + else + { + subTitle = GetPropertyValStr(); + subTitleFormat = Constants.SubTitleVarNameFormatStr; + } + + SetAdditonalTitleTextOnCallback( subTitle, ( instance, newSubTitle ) => instance.AdditonalTitleContent.text = string.Format( subTitleFormat, newSubTitle ) ); + + if( !m_isEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 ) + { + GUI.Label( titlePos, StaticSwitchStr, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) ); + } + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + if( m_keywordModeType == KeywordModeType.KeywordEnum ) + { + for( int i = 0; i < m_keywordEnumAmount; i++ ) + { + string key = KeywordEnum( i ); + mat.DisableKeyword( key ); + } + mat.EnableKeyword( KeywordEnum( m_materialValue )); + mat.SetFloat( m_propertyName, m_materialValue ); + } + else + { + int final = m_materialValue; + if( m_keywordModeType == KeywordModeType.ToggleOff ) + final = final == 1 ? 0 : 1; + mat.SetFloat( m_propertyName, m_materialValue ); + if( final == 1 ) + mat.EnableKeyword( GetPropertyValStr() ); + else + mat.DisableKeyword( GetPropertyValStr() ); + } + } + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetInt( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetInt( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_multiCompile = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14403 ) + { + m_defaultValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + { + m_materialValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + } + } + else + { + m_defaultValue = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ) ? 1 : 0; + if( UIUtils.CurrentShaderVersion() > 14101 ) + { + m_materialValue = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ) ? 1 : 0; + } + } + + if( UIUtils.CurrentShaderVersion() > 13104 ) + { + m_createToggle = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + m_currentKeyword = GetCurrentParam( ref nodeParams ); + m_currentKeywordId = UIUtils.GetKeywordId( m_currentKeyword ); + } + if( UIUtils.CurrentShaderVersion() > 14001 ) + { + m_keywordModeType = (KeywordModeType)Enum.Parse( typeof( KeywordModeType ), GetCurrentParam( ref nodeParams ) ); + } + + if( UIUtils.CurrentShaderVersion() > 14403 ) + { + KeywordEnumAmount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + for( int i = 0; i < KeywordEnumAmount; i++ ) + { + m_defaultKeywordNames[ i ] = GetCurrentParam( ref nodeParams ); + } + + UpdateLabels(); + } + + if( UIUtils.CurrentShaderVersion() > 16304 ) + { + string currentVarMode = GetCurrentParam( ref nodeParams ); + CurrentVarMode = (StaticSwitchVariableMode)Enum.Parse( typeof( StaticSwitchVariableMode ), currentVarMode ); + if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + m_referenceNodeId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + } + } + else + { + CurrentVarMode = (StaticSwitchVariableMode)m_variableMode; + } + + if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + UIUtils.UnregisterPropertyNode( this ); + } + else + { + if( m_createToggle ) + UIUtils.RegisterPropertyNode( this ); + else + UIUtils.UnregisterPropertyNode( this ); + } + + if( UIUtils.CurrentShaderVersion() > 16700 ) + { + m_isLocal = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + + SetMaterialToggleRetrocompatibility(); + + if( !m_isNodeBeingCopied && CurrentVarMode != StaticSwitchVariableMode.Reference ) + { + ContainerGraph.StaticSwitchNodes.UpdateDataOnNode( UniqueId, DataToArray ); + } + } + + void SetMaterialToggleRetrocompatibility() + { + if( UIUtils.CurrentShaderVersion() < 17108 ) + { + if( !m_createToggle && m_staticSwitchVarMode == StaticSwitchVariableMode.Create ) + { + if( m_keywordModeType != KeywordModeType.KeywordEnum ) + { + m_propertyName = m_propertyName.ToUpper() + "_ON"; + } + else + { + m_propertyName = m_propertyName.ToUpper(); + for( int i = 0; i < m_keywordEnumList.Length; i++ ) + { + m_keywordEnumList[ i ] = "_" + m_keywordEnumList[ i ].ToUpper(); + } + } + m_autoGlobalName = false; + } + } + } + + public override void ReadFromDeprecated( ref string[] nodeParams, Type oldType = null ) + { + base.ReadFromDeprecated( ref nodeParams, oldType ); + { + m_currentKeyword = GetCurrentParam( ref nodeParams ); + m_currentKeywordId = UIUtils.GetKeywordId( m_currentKeyword ); + m_createToggle = false; + m_keywordModeType = KeywordModeType.Toggle; + m_variableMode = VariableMode.Fetch; + CurrentVarMode = StaticSwitchVariableMode.Fetch; + } + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_multiCompile ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_materialValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_createToggle ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_currentKeyword ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_keywordModeType ); + IOUtils.AddFieldValueToString( ref nodeInfo, KeywordEnumAmount ); + for( int i = 0; i < KeywordEnumAmount; i++ ) + { + IOUtils.AddFieldValueToString( ref nodeInfo, m_keywordEnumList[ i ] ); + } + + IOUtils.AddFieldValueToString( ref nodeInfo, CurrentVarMode ); + if( CurrentVarMode == StaticSwitchVariableMode.Reference ) + { + int referenceId = ( m_reference != null ) ? m_reference.UniqueId : -1; + IOUtils.AddFieldValueToString( ref nodeInfo, referenceId ); + } + IOUtils.AddFieldValueToString( ref nodeInfo, m_isLocal ); + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + CheckReferenceValues( true ); + } + + StaticSwitchVariableMode CurrentVarMode + { + get { return m_staticSwitchVarMode; } + set + { + if( m_staticSwitchVarMode != value ) + { + if( value == StaticSwitchVariableMode.Reference ) + { + ContainerGraph.StaticSwitchNodes.RemoveNode( this ); + m_referenceArrayId = -1; + m_referenceNodeId = -1; + m_reference = null; + m_headerColorModifier = ReferenceHeaderColor; + } + else + { + m_headerColorModifier = Color.white; + ContainerGraph.StaticSwitchNodes.AddNode( this ); + UpdateLabels(); + } + } + m_staticSwitchVarMode = value; + } + } + public bool IsStaticSwitchDirty { get { return m_isStaticSwitchDirty; } } + public KeywordModeType KeywordModeTypeValue { get { return m_keywordModeType; } } + public int DefaultValue { get { return m_defaultValue; } } + public int MaterialValue { get { return m_materialValue; } } + public string CurrentKeyword { get { return m_currentKeyword; } } + public bool CreateToggle { get { return m_createToggle; } } + + public int KeywordEnumAmount + { + get + { + return m_keywordEnumAmount; + } + set + { + m_keywordEnumAmount = value; + m_defaultValue = Mathf.Clamp( m_defaultValue, 0, m_keywordEnumAmount - 1 ); + m_materialValue = Mathf.Clamp( m_defaultValue, 0, m_keywordEnumAmount - 1 ); + } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs.meta new file mode 100644 index 00000000..e1b216a4 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/StaticSwitch.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b1d1a233ea65ccd478fb6caf4327da48 +timeCreated: 1497289190 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs new file mode 100644 index 00000000..4901dbbf --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +// +// Custom Node TAU +// Donated by The Four Headed Cat - @fourheadedcat + +using UnityEngine; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Tau", "Constants And Properties", "Tau constant (2*PI): 6.28318530718", null, KeyCode.None, true, false, null,null, "The Four Headed Cat - @fourheadedcat" )] + public sealed class TauNode : ParentNode + { + private readonly string Tau = ( 2.0 * Mathf.PI ).ToString(); + public TauNode() : base() { } + public TauNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_previewShaderGUID = "701bc295c0d75d8429eabcf45e8e008d"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + return dataCollector.IsSRP? "TWO_PI": Tau; + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs.meta new file mode 100644 index 00000000..96b9694f --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TauNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1a6ded4f5e42f6d4684a6131a3cf4d33 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs new file mode 100644 index 00000000..46584ded --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs @@ -0,0 +1,994 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Texture Array", "Textures", "Texture Array fetches a texture from a texture2DArray asset file given a index value", KeyCode.None, true, 0, int.MaxValue, typeof( Texture2DArray ) )] + public class TextureArrayNode : PropertyNode + { + [SerializeField] + private Texture2DArray m_defaultTextureArray; + + [SerializeField] + private Texture2DArray m_materialTextureArray; + + [SerializeField] + private TexReferenceType m_referenceType = TexReferenceType.Object; + + [SerializeField] + private int m_uvSet = 0; + + [SerializeField] + private MipType m_mipMode = MipType.Auto; + + private readonly string[] m_mipOptions = { "Auto", "Mip Level", "Derivative" }; + + private TextureArrayNode m_referenceSampler = null; + + [SerializeField] + private int m_referenceArrayId = -1; + + [SerializeField] + private int m_referenceNodeId = -1; + + [SerializeField] + private bool m_autoUnpackNormals = false; + + private InputPort m_texPort; + private InputPort m_uvPort; + private InputPort m_indexPort; + private InputPort m_lodPort; + private InputPort m_normalPort; + private InputPort m_ddxPort; + private InputPort m_ddyPort; + + private OutputPort m_colorPort; + + private const string AutoUnpackNormalsStr = "Normal"; + private const string NormalScaleStr = "Scale"; + + private string m_labelText = "None (Texture2DArray)"; + + private readonly Color ReferenceHeaderColor = new Color( 2.66f, 1.02f, 0.6f, 1.0f ); + + private int m_cachedUvsId = -1; + private int m_cachedSamplerId = -1; + private int m_texConnectedId = -1; + private int m_cachedUnpackId = -1; + private int m_cachedLodId = -1; + + private Rect m_iconPos; + private bool m_isEditingPicker; + + private bool m_linearTexture; + protected bool m_drawPicker; + + private ReferenceState m_state = ReferenceState.Self; + private ParentNode m_previewTextProp = null; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputColorPorts( "RGBA" ); + m_colorPort = m_outputPorts[ 0 ]; + AddInputPort( WirePortDataType.SAMPLER2D, false, "Tex", -1, MasterNodePortCategory.Fragment, 6 ); + AddInputPort( WirePortDataType.FLOAT2, false, "UV", -1, MasterNodePortCategory.Fragment, 0 ); + AddInputPort( WirePortDataType.FLOAT, false, "Index", -1, MasterNodePortCategory.Fragment, 1 ); + AddInputPort( WirePortDataType.FLOAT, false, "Level", -1, MasterNodePortCategory.Fragment, 2 ); + AddInputPort( WirePortDataType.FLOAT, false, NormalScaleStr, -1, MasterNodePortCategory.Fragment, 3 ); + AddInputPort( WirePortDataType.FLOAT2, false, "DDX", -1, MasterNodePortCategory.Fragment, 4 ); + AddInputPort( WirePortDataType.FLOAT2, false, "DDY", -1, MasterNodePortCategory.Fragment, 5 ); + m_inputPorts[ 2 ].AutoDrawInternalData = true; + + m_texPort = m_inputPorts[ 0 ]; + m_uvPort = m_inputPorts[ 1 ]; + m_indexPort = m_inputPorts[ 2 ]; + m_lodPort = m_inputPorts[ 3 ]; + + m_lodPort.Visible = false; + m_normalPort = m_inputPorts[ 4 ]; + m_normalPort.Visible = m_autoUnpackNormals; + m_normalPort.FloatInternalData = 1.0f; + m_ddxPort = m_inputPorts[ 5 ]; + m_ddxPort.Visible = false; + m_ddyPort = m_inputPorts[ 6 ]; + m_ddyPort.Visible = false; + m_insideSize.Set( 128, 128 + 5 ); + m_drawPrecisionUI = false; + m_currentParameterType = PropertyType.Property; + + m_availableAttribs.Add( new PropertyAttributes( "No Scale Offset", "[NoScaleOffset]" ) ); + + m_freeType = false; + m_showPreview = true; + m_drawPreviewExpander = false; + m_drawPreview = false; + m_drawPicker = true; + m_customPrefix = "Texture Array "; + m_selectedLocation = PreviewLocation.TopCenter; + m_previewShaderGUID = "2e6d093df2d289f47b827b36efb31a81"; + m_showAutoRegisterUI = false; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_cachedUvsId == -1 ) + m_cachedUvsId = Shader.PropertyToID( "_CustomUVs" ); + + if( m_cachedSamplerId == -1 ) + m_cachedSamplerId = Shader.PropertyToID( "_Sampler" ); + + if( m_texConnectedId == -1 ) + m_texConnectedId = Shader.PropertyToID( "_TexConnected" ); + + if( m_cachedUnpackId == -1 ) + m_cachedUnpackId = Shader.PropertyToID( "_Unpack" ); + + if( m_cachedLodId == -1 ) + m_cachedLodId = Shader.PropertyToID( "_LodType" ); + + PreviewMaterial.SetFloat( m_cachedLodId, ( m_mipMode == MipType.MipLevel ? 1 : 0 ) ); + PreviewMaterial.SetFloat( m_cachedUnpackId, m_autoUnpackNormals ? 1 : 0 ); + if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null ) + { + if( (ParentNode)m_referenceSampler != m_referenceSampler.PreviewTextProp ) + { + PreviewMaterial.SetInt( m_texConnectedId, 1 ); + PreviewMaterial.SetTexture( "_G", m_referenceSampler.PreviewTextProp.PreviewTexture ); + } + else + { + PreviewMaterial.SetInt( m_texConnectedId, 0 ); + PreviewMaterial.SetTexture( m_cachedSamplerId, m_referenceSampler.TextureArray ); + } + } + else if( m_texPort.IsConnected ) + { + PreviewMaterial.SetInt( m_texConnectedId, 1 ); + } + else + { + PreviewMaterial.SetInt( m_texConnectedId, 0 ); + PreviewMaterial.SetTexture( m_cachedSamplerId, TextureArray ); + } + PreviewMaterial.SetFloat( m_cachedUvsId, ( m_uvPort.IsConnected ? 1 : 0 ) ); + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + if( m_referenceType == TexReferenceType.Object ) + { + UIUtils.RegisterTextureArrayNode( this ); + UIUtils.RegisterPropertyNode( this ); + } + + if( UniqueId > -1 ) + ContainerGraph.TextureArrayNodes.OnReorderEventComplete += OnReorderEventComplete; + + } + + private void OnReorderEventComplete() + { + if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null ) + { + m_referenceArrayId = ContainerGraph.TextureArrayNodes.GetNodeRegisterIdx( m_referenceSampler.UniqueId ); + } + } + + new void ShowDefaults() + { + m_uvSet = EditorGUILayoutIntPopup( Constants.AvailableUVSetsLabel, m_uvSet, Constants.AvailableUVSetsStr, Constants.AvailableUVSets ); + + MipType newMipMode = (MipType)EditorGUILayoutPopup( "Mip Mode", (int)m_mipMode, m_mipOptions ); + if( newMipMode != m_mipMode ) + { + m_mipMode = newMipMode; + } + + switch( m_mipMode ) + { + case MipType.Auto: + m_lodPort.Visible = false; + m_ddxPort.Visible = false; + m_ddyPort.Visible = false; + break; + case MipType.MipLevel: + m_lodPort.Visible = true; + m_ddxPort.Visible = false; + m_ddyPort.Visible = false; + break; + case MipType.MipBias: + case MipType.Derivative: + m_ddxPort.Visible = true; + m_ddyPort.Visible = true; + m_lodPort.Visible = false; + break; + } + + if( m_ddxPort.Visible ) + { + EditorGUILayout.HelpBox( "Warning: Derivative Mip Mode only works on some platforms (D3D11 XBOXONE GLES3 GLCORE)", MessageType.Warning ); + } + + if( !m_lodPort.IsConnected && m_lodPort.Visible ) + { + m_lodPort.FloatInternalData = EditorGUILayoutFloatField( "Mip Level", m_lodPort.FloatInternalData ); + } + + if( !m_indexPort.IsConnected ) + { + m_indexPort.FloatInternalData = EditorGUILayoutFloatField( "Index", m_indexPort.FloatInternalData ); + } + + + } + + public override void DrawMainPropertyBlock() + { + EditorGUI.BeginChangeCheck(); + m_referenceType = (TexReferenceType)EditorGUILayoutPopup( Constants.ReferenceTypeStr, (int)m_referenceType, Constants.ReferenceArrayLabels ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_referenceType == TexReferenceType.Object ) + { + UIUtils.RegisterTextureArrayNode( this ); + UIUtils.RegisterPropertyNode( this ); + + SetTitleText( m_propertyInspectorName ); + SetAdditonalTitleText( string.Format( Constants.PropertyValueLabel, GetPropertyValStr() ) ); + m_referenceArrayId = -1; + m_referenceNodeId = -1; + m_referenceSampler = null; + } + else + { + UIUtils.UnregisterTextureArrayNode( this ); + UIUtils.UnregisterPropertyNode( this ); + } + UpdateHeaderColor(); + } + + if( m_referenceType == TexReferenceType.Object ) + { + EditorGUI.BeginChangeCheck(); + base.DrawMainPropertyBlock(); + if( EditorGUI.EndChangeCheck() ) + { + OnPropertyNameChanged(); + } + } + else + { + string[] arr = UIUtils.TextureArrayNodeArr(); + bool guiEnabledBuffer = GUI.enabled; + if( arr != null && arr.Length > 0 ) + { + GUI.enabled = true; + } + else + { + m_referenceArrayId = -1; + GUI.enabled = false; + } + + m_referenceArrayId = EditorGUILayoutPopup( Constants.AvailableReferenceStr, m_referenceArrayId, arr ); + GUI.enabled = guiEnabledBuffer; + + ShowDefaults(); + + DrawSamplerOptions(); + } + } + + public override void OnPropertyNameChanged() + { + base.OnPropertyNameChanged(); + UIUtils.UpdateTextureArrayDataNode( UniqueId, PropertyInspectorName ); + } + + public override void DrawSubProperties() + { + ShowDefaults(); + + DrawSamplerOptions(); + + EditorGUI.BeginChangeCheck(); + m_defaultTextureArray = EditorGUILayoutObjectField( Constants.DefaultValueLabel, m_defaultTextureArray, typeof( Texture2DArray ), false ) as Texture2DArray; + if( EditorGUI.EndChangeCheck() ) + { + CheckTextureImporter( true ); + SetAdditonalTitleText( string.Format( Constants.PropertyValueLabel, GetPropertyValStr() ) ); + } + } + + public override void DrawMaterialProperties() + { + ShowDefaults(); + + DrawSamplerOptions(); + + EditorGUI.BeginChangeCheck(); + m_materialTextureArray = EditorGUILayoutObjectField( Constants.MaterialValueLabel, m_materialTextureArray, typeof( Texture2DArray ), false ) as Texture2DArray; + if( EditorGUI.EndChangeCheck() ) + { + CheckTextureImporter( true ); + SetAdditonalTitleText( string.Format( Constants.PropertyValueLabel, GetPropertyValStr() ) ); + m_requireMaterialUpdate = true; + } + } + + public void DrawSamplerOptions() + { + EditorGUI.BeginChangeCheck(); + bool autoUnpackNormals = EditorGUILayoutToggle( "Normal Map", m_autoUnpackNormals ); + if( EditorGUI.EndChangeCheck() ) + { + if( m_autoUnpackNormals != autoUnpackNormals ) + { + AutoUnpackNormals = autoUnpackNormals; + + ConfigureInputPorts(); + ConfigureOutputPorts(); + } + } + + if( m_autoUnpackNormals && !m_normalPort.IsConnected ) + { + m_normalPort.FloatInternalData = EditorGUILayoutFloatField( NormalScaleStr, m_normalPort.FloatInternalData ); + } + } + + public void ConfigureInputPorts() + { + m_normalPort.Visible = AutoUnpackNormals; + + m_sizeIsDirty = true; + } + + public void ConfigureOutputPorts() + { + m_outputPorts[ m_colorPort.PortId + 4 ].Visible = !AutoUnpackNormals; + + if( !AutoUnpackNormals ) + { + m_colorPort.ChangeProperties( "RGBA", WirePortDataType.FLOAT4, false ); + m_outputPorts[ m_colorPort.PortId + 1 ].ChangeProperties( "R", WirePortDataType.FLOAT, false ); + m_outputPorts[ m_colorPort.PortId + 2 ].ChangeProperties( "G", WirePortDataType.FLOAT, false ); + m_outputPorts[ m_colorPort.PortId + 3 ].ChangeProperties( "B", WirePortDataType.FLOAT, false ); + m_outputPorts[ m_colorPort.PortId + 4 ].ChangeProperties( "A", WirePortDataType.FLOAT, false ); + + } + else + { + m_colorPort.ChangeProperties( "XYZ", WirePortDataType.FLOAT3, false ); + m_outputPorts[ m_colorPort.PortId + 1 ].ChangeProperties( "X", WirePortDataType.FLOAT, false ); + m_outputPorts[ m_colorPort.PortId + 2 ].ChangeProperties( "Y", WirePortDataType.FLOAT, false ); + m_outputPorts[ m_colorPort.PortId + 3 ].ChangeProperties( "Z", WirePortDataType.FLOAT, false ); + } + + m_sizeIsDirty = true; + } + + public virtual void CheckTextureImporter( bool additionalCheck ) + { + m_requireMaterialUpdate = true; + Texture2DArray texture = m_materialMode ? m_materialTextureArray : m_defaultTextureArray; + + UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath( AssetDatabase.GetAssetPath( texture ), typeof( UnityEngine.Object ) ); + + if( obj != null ) + { + SerializedObject serializedObject = new UnityEditor.SerializedObject( obj ); + + if( serializedObject != null ) + { + SerializedProperty colorSpace = serializedObject.FindProperty( "m_ColorSpace" ); + m_linearTexture = ( colorSpace.intValue == 0 ); + } + } + } + + void UpdateHeaderColor() + { + m_headerColorModifier = ( m_referenceType == TexReferenceType.Object ) ? Color.white : ReferenceHeaderColor; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( !( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp || drawInfo.CurrentEventType == EventType.ExecuteCommand || drawInfo.CurrentEventType == EventType.DragPerform ) ) + return; + + bool insideBox = m_previewRect.Contains( drawInfo.MousePosition ); + + if( insideBox ) + { + m_isEditingPicker = true; + } + else if( m_isEditingPicker && !insideBox && drawInfo.CurrentEventType != EventType.ExecuteCommand ) + { + GUI.FocusControl( null ); + m_isEditingPicker = false; + } + + if( m_state != ReferenceState.Self && drawInfo.CurrentEventType == EventType.MouseDown && m_previewRect.Contains( drawInfo.MousePosition ) ) + { + UIUtils.FocusOnNode( m_previewTextProp, 1, true ); + Event.current.Use(); + } + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + if( m_drawPreview ) + { + m_iconPos = m_globalPosition; + m_iconPos.width = 19 * drawInfo.InvertedZoom; + m_iconPos.height = 19 * drawInfo.InvertedZoom; + + m_iconPos.y += 10 * drawInfo.InvertedZoom; + m_iconPos.x += m_globalPosition.width - m_iconPos.width - 5 * drawInfo.InvertedZoom; + } + + bool instanced = CheckReference(); + if( instanced ) + { + m_state = ReferenceState.Instance; + m_previewTextProp = m_referenceSampler; + } + else if( m_texPort.IsConnected ) + { + m_state = ReferenceState.Connected; + m_previewTextProp = m_texPort.GetOutputNode( 0 ) as ParentNode; + } + else + { + m_state = ReferenceState.Self; + m_previewTextProp = this; + } + + if( m_previewTextProp == null ) + m_previewTextProp = this; + + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( m_isEditingPicker && m_drawPicker ) + { + Rect hitRect = m_previewRect; + hitRect.height = 14 * drawInfo.InvertedZoom; + hitRect.y = m_previewRect.yMax - hitRect.height; + hitRect.width = 4 * 14 * drawInfo.InvertedZoom; + + bool restoreMouse = false; + if( Event.current.type == EventType.MouseDown && hitRect.Contains( drawInfo.MousePosition ) ) + { + restoreMouse = true; + Event.current.type = EventType.Ignore; + } + + EditorGUI.BeginChangeCheck(); + m_colorBuffer = GUI.color; + GUI.color = Color.clear; + if( m_materialMode ) + m_materialTextureArray = EditorGUIObjectField( m_previewRect, m_materialTextureArray, typeof( Texture2DArray ), false ) as Texture2DArray; + else + m_defaultTextureArray = EditorGUIObjectField( m_previewRect, m_defaultTextureArray, typeof( Texture2DArray ), false ) as Texture2DArray; + GUI.color = m_colorBuffer; + + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + CheckTextureImporter( true ); + SetTitleText( PropertyInspectorName ); + SetAdditonalTitleText( string.Format( Constants.PropertyValueLabel, GetPropertyValStr() ) ); + ConfigureInputPorts(); + ConfigureOutputPorts(); + BeginDelayedDirtyProperty(); + m_requireMaterialUpdate = true; + } + + if( restoreMouse ) + { + Event.current.type = EventType.MouseDown; + } + + if( ( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp ) ) + DrawPreviewMaskButtonsLayout( drawInfo, m_previewRect ); + } + + if( drawInfo.CurrentEventType != EventType.Repaint ) + return; + + switch( m_state ) + { + default: + case ReferenceState.Self: + if( drawInfo.CurrentEventType == EventType.Repaint ) + { + m_drawPreview = false; + m_drawPicker = true; + + DrawTexturePicker( drawInfo ); + } + break; + case ReferenceState.Connected: + if( drawInfo.CurrentEventType == EventType.Repaint ) + { + m_drawPreview = true; + m_drawPicker = false; + + if( m_previewTextProp != null ) + { + SetTitleTextOnCallback( m_previewTextProp.TitleContent.text, ( instance, newTitle ) => instance.TitleContent.text = newTitle + " (Input)" ); + SetAdditonalTitleText( m_previewTextProp.AdditonalTitleContent.text ); + } + + // Draw chain lock + GUI.Label( m_iconPos, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerTextureIcon ) ); + + // Draw frame around preview + GUI.Label( m_previewRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) ); + } + break; + case ReferenceState.Instance: + { + m_drawPreview = true; + m_drawPicker = false; + + if( m_referenceSampler != null ) + { + SetTitleTextOnCallback( m_referenceSampler.PreviewTextProp.TitleContent.text, ( instance, newTitle ) => instance.TitleContent.text = newTitle + Constants.InstancePostfixStr ); + SetAdditonalTitleText( m_referenceSampler.PreviewTextProp.AdditonalTitleContent.text ); + } + + // Draw chain lock + GUI.Label( m_iconPos, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerTextureIcon ) ); + + // Draw frame around preview + GUI.Label( m_previewRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) ); + } + break; + } + } + + protected void DrawTexturePicker( DrawInfo drawInfo ) + { + Rect newRect = m_previewRect; + Texture2DArray currentValue = m_materialMode ? m_materialTextureArray : m_defaultTextureArray; + + if( currentValue == null ) + GUI.Label( newRect, string.Empty, UIUtils.ObjectFieldThumb ); + else + DrawPreview( drawInfo, m_previewRect ); + + if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 ) + { + Rect butRect = m_previewRect; + butRect.y -= 1; + butRect.x += 1; + + Rect smallButton = newRect; + smallButton.height = 14 * drawInfo.InvertedZoom; + smallButton.y = newRect.yMax - smallButton.height - 2; + smallButton.width = 40 * drawInfo.InvertedZoom; + smallButton.x = newRect.xMax - smallButton.width - 2; + if( currentValue == null ) + { + GUI.Label( newRect, m_labelText, UIUtils.ObjectFieldThumbOverlay ); + } + else + { + DrawPreviewMaskButtonsRepaint( drawInfo, butRect ); + } + GUI.Label( smallButton, "Select", UIUtils.GetCustomStyle( CustomStyle.SamplerButton ) ); + } + + GUI.Label( newRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + + + OnPropertyNameChanged(); + + if( CheckReference() ) + { + OrderIndex = m_referenceSampler.RawOrderIndex; + OrderIndexOffset = m_referenceSampler.OrderIndexOffset; + } + + bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ); + + bool instanced = false; + + if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null ) + instanced = true; + + if( instanced ) + { + if( !m_referenceSampler.TexPort.IsConnected ) + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + } + else if( !m_texPort.IsConnected ) + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + string level = string.Empty; + if( m_lodPort.Visible ) + { + level = m_lodPort.GeneratePortInstructions( ref dataCollector ); + } + + if( isVertex && !m_lodPort.Visible ) + level = "0"; + + string propertyName = string.Empty; + if( instanced ) + { + if( m_referenceSampler.TexPort.IsConnected ) + propertyName = m_referenceSampler.TexPort.GeneratePortInstructions( ref dataCollector ); + else + propertyName = m_referenceSampler.PropertyName; + } + else if( m_texPort.IsConnected ) + propertyName = m_texPort.GeneratePortInstructions( ref dataCollector ); + else + propertyName = PropertyName; + + string uvs = string.Empty; + if( m_uvPort.IsConnected ) + { + uvs = m_uvPort.GeneratePortInstructions( ref dataCollector ); + } + else + { + if( dataCollector.IsTemplate ) + { + uvs = dataCollector.TemplateDataCollectorInstance.GetTextureCoord( m_uvSet, propertyName/*( instanced ? m_referenceSampler.PropertyName : PropertyName )*/, UniqueId, CurrentPrecisionType ); + } + else + { + if( isVertex ) + uvs = TexCoordVertexDataNode.GenerateVertexUVs( ref dataCollector, UniqueId, m_uvSet, propertyName ); + else + uvs = TexCoordVertexDataNode.GenerateFragUVs( ref dataCollector, UniqueId, m_uvSet, propertyName ); + } + } + string index = m_indexPort.GeneratePortInstructions( ref dataCollector ); + + string m_normalMapUnpackMode = ""; + if( m_autoUnpackNormals ) + { + bool isScaledNormal = false; + if( m_normalPort.IsConnected ) + { + isScaledNormal = true; + } + else + { + if( m_normalPort.FloatInternalData != 1 ) + { + isScaledNormal = true; + } + } + + string scaleValue = isScaledNormal ? m_normalPort.GeneratePortInstructions( ref dataCollector ) : "1.0"; + m_normalMapUnpackMode = TemplateHelperFunctions.CreateUnpackNormalStr( dataCollector, isScaledNormal, scaleValue ); + if( isScaledNormal && ( !dataCollector.IsTemplate || !dataCollector.IsSRP ) ) + { + dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs ); + } + + } + + string result = string.Empty; + + if( dataCollector.IsTemplate && dataCollector.IsSRP ) + { + //CAREFUL mipbias here means derivative (this needs index changes) + //TODO: unity now supports bias as well + if( m_mipMode == MipType.MipBias ) + { + dataCollector.UsingArrayDerivatives = true; + result = propertyName + ".SampleGrad(sampler" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions( ref dataCollector ) + ", " + m_ddyPort.GeneratePortInstructions( ref dataCollector ) + ");"; + } + else if( m_lodPort.Visible || isVertex ) + { + result = "SAMPLE_TEXTURE2D_ARRAY_LOD(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + ", " + level + " )"; + } + else + { + result = "SAMPLE_TEXTURE2D_ARRAY(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + " )"; + } + } + else + { + //CAREFUL mipbias here means derivative (this needs index changes) + if( m_mipMode == MipType.MipBias ) + { + dataCollector.UsingArrayDerivatives = true; + result = "ASE_SAMPLE_TEX2DARRAY_GRAD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions( ref dataCollector ) + ", " + m_ddyPort.GeneratePortInstructions( ref dataCollector ) + " )"; + } + else if( m_lodPort.Visible || isVertex ) + { + result = "UNITY_SAMPLE_TEX2DARRAY_LOD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + level + " )"; + } + else + { + result = "UNITY_SAMPLE_TEX2DARRAY" + ( m_lodPort.Visible || isVertex ? "_LOD" : "" ) + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + ( m_lodPort.Visible || isVertex ? ", " + level : "" ) + " )"; + } + } + + if( m_autoUnpackNormals ) + result = string.Format( m_normalMapUnpackMode, result ); + + RegisterLocalVariable( 0, result, ref dataCollector, "texArray" + OutputId ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + + public override string PropertyName + { + get + { + if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null ) + return m_referenceSampler.PropertyName; + else + return base.PropertyName; + } + } + + public override string PropertyInspectorName + { + get + { + if( m_referenceType == TexReferenceType.Instance && m_referenceSampler != null ) + return m_referenceSampler.PropertyInspectorName; + else + return base.PropertyInspectorName; + } + } + + public override string GetPropertyValue() + { + return PropertyAttributes + PropertyName + "(\"" + PropertyInspectorName + "\", 2DArray ) = \"\" {}"; + } + + public override bool GetUniformData( out string dataType, out string dataName, ref bool fullValue ) + { + MasterNode currMasterNode = ( m_containerGraph.CurrentMasterNode != null ) ? m_containerGraph.CurrentMasterNode : m_containerGraph.ParentWindow.OutsideGraph.CurrentMasterNode; + if( currMasterNode != null && currMasterNode.CurrentDataCollector.IsTemplate && currMasterNode.CurrentDataCollector.IsSRP ) + { + dataType = "TEXTURE2D_ARRAY( " + PropertyName + ""; + dataName = ");\nuniform SAMPLER( sampler" + PropertyName + " )"; + return true; + } + dataType = "UNITY_DECLARE_TEX2DARRAY("; + dataName = PropertyName + " )"; + return true; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + string textureName = GetCurrentParam( ref nodeParams ); + m_defaultTextureArray = AssetDatabase.LoadAssetAtPath<Texture2DArray>( textureName ); + m_uvSet = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + m_referenceType = (TexReferenceType)Enum.Parse( typeof( TexReferenceType ), GetCurrentParam( ref nodeParams ) ); + m_referenceNodeId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 3202 ) + m_mipMode = (MipType)Enum.Parse( typeof( MipType ), GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 5105 ) + m_autoUnpackNormals = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + + if( m_referenceType == TexReferenceType.Instance ) + { + UIUtils.UnregisterTextureArrayNode( this ); + UIUtils.UnregisterPropertyNode( this ); + } + + ConfigureInputPorts(); + ConfigureOutputPorts(); + + m_lodPort.Visible = ( m_mipMode == MipType.MipLevel ); + m_ddxPort.Visible = ( m_mipMode == MipType.MipBias ); //not really bias, it's derivative + m_ddyPort.Visible = ( m_mipMode == MipType.MipBias ); //not really bias, it's derivative + + UpdateHeaderColor(); + + if( m_defaultTextureArray ) + { + m_materialTextureArray = m_defaultTextureArray; + } + + if( !m_isNodeBeingCopied && m_referenceType == TexReferenceType.Object ) + { + ContainerGraph.TextureArrayNodes.UpdateDataOnNode( UniqueId, DataToArray ); + } + } + + public override void RefreshExternalReferences() + { + base.RefreshExternalReferences(); + + m_referenceSampler = UIUtils.GetNode( m_referenceNodeId ) as TextureArrayNode; + m_referenceArrayId = UIUtils.GetTextureArrayNodeRegisterId( m_referenceNodeId ); + OnPropertyNameChanged(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, ( m_defaultTextureArray != null ) ? AssetDatabase.GetAssetPath( m_defaultTextureArray ) : Constants.NoStringValue ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_uvSet.ToString() ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_referenceType ); + IOUtils.AddFieldValueToString( ref nodeInfo, ( ( m_referenceSampler != null ) ? m_referenceSampler.UniqueId : -1 ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_mipMode ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_autoUnpackNormals ); + } + + public override void ReadAdditionalClipboardData( ref string[] nodeParams ) + { + base.ReadAdditionalClipboardData( ref nodeParams ); + string textureName = GetCurrentParam( ref nodeParams ); + m_materialTextureArray = AssetDatabase.LoadAssetAtPath<Texture2DArray>( textureName ); + } + + public override void WriteAdditionalClipboardData( ref string nodeInfo ) + { + base.WriteAdditionalClipboardData( ref nodeInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, ( m_materialTextureArray != null ) ? AssetDatabase.GetAssetPath( m_materialTextureArray ) : Constants.NoStringValue ); + } + + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction && m_referenceType == TexReferenceType.Object ) + { + OnPropertyNameChanged(); + if( mat.HasProperty( PropertyName ) ) + { + mat.SetTexture( PropertyName, m_materialTextureArray ); + } + } + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) ) + { + if( mat.HasProperty( PropertyName ) ) + { + m_materialTextureArray = (Texture2DArray)mat.GetTexture( PropertyName ); + if( m_materialTextureArray == null ) + m_materialTextureArray = m_defaultTextureArray; + } + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( PropertyName ) ) + { + m_materialTextureArray = (Texture2DArray)material.GetTexture( PropertyName ); + if( m_materialTextureArray == null ) + m_materialTextureArray = m_defaultTextureArray; + + PreviewIsDirty = true; + } + } + + public override bool UpdateShaderDefaults( ref Shader shader, ref TextureDefaultsDataColector defaultCol ) + { + if( m_defaultTextureArray != null ) + { + defaultCol.AddValue( PropertyName, m_defaultTextureArray ); + } + + return true; + } + + public override string GetPropertyValStr() + { + return m_materialMode ? ( m_materialTextureArray != null ? m_materialTextureArray.name : IOUtils.NO_TEXTURES ) : ( m_defaultTextureArray != null ? m_defaultTextureArray.name : IOUtils.NO_TEXTURES ); + } + + public bool CheckReference() + { + if( m_referenceType == TexReferenceType.Instance && m_referenceArrayId > -1 ) + { + m_referenceSampler = UIUtils.GetTextureArrayNode( m_referenceArrayId ); + + if( m_referenceSampler == null ) + { + m_texPort.Locked = false; + m_referenceArrayId = -1; + } + else + m_texPort.Locked = true; + } + else + { + m_texPort.Locked = false; + } + + return m_referenceSampler != null; + } + + public override void SetupFromCastObject( UnityEngine.Object obj ) + { + base.SetupFromCastObject( obj ); + SetupFromObject( obj ); + } + + public override void OnObjectDropped( UnityEngine.Object obj ) + { + SetupFromObject( obj ); + } + + private void SetupFromObject( UnityEngine.Object obj ) + { + if( m_materialMode ) + m_materialTextureArray = obj as Texture2DArray; + else + m_defaultTextureArray = obj as Texture2DArray; + } + + public Texture2DArray TextureArray { get { return ( m_materialMode ? m_materialTextureArray : m_defaultTextureArray ); } } + + public bool IsLinearTexture { get { return m_linearTexture; } } + + public bool AutoUnpackNormals + { + get { return m_autoUnpackNormals; } + set { m_autoUnpackNormals = value; } + } + + public override string DataToArray { get { return PropertyInspectorName; } } + + public override void Destroy() + { + base.Destroy(); + m_defaultTextureArray = null; + m_materialTextureArray = null; + + m_texPort = null; + m_uvPort = null; + m_indexPort = null; + m_lodPort = null; + m_normalPort = null; + m_ddxPort = null; + m_ddyPort = null; + + if( m_referenceType == TexReferenceType.Object ) + { + UIUtils.UnregisterTextureArrayNode( this ); + UIUtils.UnregisterPropertyNode( this ); + } + + if( UniqueId > -1 ) + ContainerGraph.TextureArrayNodes.OnReorderEventComplete -= OnReorderEventComplete; + } + + public ParentNode PreviewTextProp { get { return m_previewTextProp; } } + public InputPort TexPort { get { return m_texPort; } } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs.meta new file mode 100644 index 00000000..54332f0b --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/TextureArrayNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3c5be6f9c03445d4fb70955f594877dc +timeCreated: 1485801067 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs new file mode 100644 index 00000000..306816ba --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs @@ -0,0 +1,301 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Vector2", "Constants And Properties", "Vector2 property", null, KeyCode.Alpha2 )] + public sealed class Vector2Node : PropertyNode + { + [SerializeField] + private Vector2 m_defaultValue = Vector2.zero; + + [SerializeField] + private Vector2 m_materialValue = Vector2.zero; + + private const float LabelWidth = 8; + + private int m_cachedPropertyId = -1; + + private bool m_isEditingFields; + private Vector2 m_previousValue = Vector2.zero; + private string[] m_fieldText = new string[] { "0", "0" }; + + public Vector2Node() : base() { } + public Vector2Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Vector" ); + m_insideSize.Set(50,20); + m_selectedLocation = PreviewLocation.BottomCenter; + AddOutputVectorPorts( WirePortDataType.FLOAT2, "XY" ); + m_availableAttribs.Add( new PropertyAttributes( "Remap Sliders", "[RemapSliders]" ) ); + m_previewShaderGUID = "88b4191eb06084d4da85d1dd2f984085"; + m_srpBatcherCompatible = true; + m_showHybridInstancedUI = true; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + m_defaultValue = EditorGUILayoutVector2Field( Constants.DefaultValueLabel, m_defaultValue ); + } + + public override void DrawMaterialProperties() + { + if ( m_materialMode ) + EditorGUI.BeginChangeCheck(); + + m_materialValue = EditorGUILayoutVector2Field( Constants.MaterialValueLabel, m_materialValue ); + if ( m_materialMode && EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if ( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputVector" ); + + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_materialValue[ 0 ], m_materialValue[ 1 ], 0, 0 ) ); + else + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_defaultValue[ 0 ], m_defaultValue[ 1 ], 0, 0 ) ); + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if ( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if ( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if ( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if ( !m_isVisible ) + return; + + if ( m_isEditingFields && m_currentParameterType != PropertyType.Global) + { + EditorGUI.BeginChangeCheck(); + for ( int i = 0; i < 2; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + float val = m_materialValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_materialValue[ i ] = val; + } + else + { + float val = m_defaultValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_defaultValue[ i ] = val; + } + } + if ( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = m_materialMode; + BeginDelayedDirtyProperty(); + } + } + else if ( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + for ( int i = 0; i < 2; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + if( GUI.enabled ) + { + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + } + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + if ( m_previousValue[ i ] != m_materialValue[ i ] ) + { + m_previousValue[ i ] = m_materialValue[ i ]; + m_fieldText[ i ] = m_materialValue[ i ].ToString(); + } + } + else + { + if ( m_previousValue[ i ] != m_defaultValue[ i ] ) + { + m_previousValue[ i ] = m_defaultValue[ i ]; + m_fieldText[ i ] = m_defaultValue[ i ].ToString(); + } + } + + GUI.Label( fakeField, m_fieldText[ i ], UIUtils.MainSkin.textField ); + } + GUI.enabled = guiEnabled; + } + } + + public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) + { + Vector2 value = m_defaultValue; + dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( value.x + "," + value.y ) ); + m_outputPorts[ 0 ].SetLocalValue( m_propertyName, dataCollector.PortCategory ); + m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".x" , dataCollector.PortCategory); + m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".y", dataCollector.PortCategory ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId,ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if ( m_currentParameterType != PropertyType.Constant ) + return GetOutputVectorItem( 0, outputId, PropertyData( dataCollector.PortCategory ) ); + + if ( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + if ( CheckLocalVariable( ref dataCollector ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + Vector2 value = m_defaultValue; + string result = string.Empty; + switch ( outputId ) + { + case 0: + { + result = m_precisionString+"( " + value.x + "," + value.y + " )"; + } + break; + + case 1: + { + result = value.x.ToString(); + } + break; + case 2: + { + result = value.y.ToString(); + } + break; + } + + if ( result.Equals( string.Empty ) ) + { + UIUtils.ShowMessage( UniqueId, "Vector2Node generating empty code", MessageSeverity.Warning ); + } + return result; + } + + public override string GetPropertyValue() + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Vector) = (" + m_defaultValue.x + "," + m_defaultValue.y + ",0,0)"; + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetVector( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat , bool fetchMaterialValues ) + { + base.SetMaterialMode( mat , fetchMaterialValues ); + if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetVector( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetVector( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToVector2( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + m_materialValue = IOUtils.StringToVector2( GetCurrentParam( ref nodeParams ) ); + } + + public override void SetGlobalValue() { Shader.SetGlobalVector( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalVector( m_propertyName ); } + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector2ToString( m_defaultValue ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector2ToString( m_materialValue ) ); + } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue.x.ToString( Mathf.Abs( m_materialValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.y.ToString( Mathf.Abs( m_materialValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) : + m_defaultValue.x.ToString( Mathf.Abs( m_defaultValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.y.ToString( Mathf.Abs( m_defaultValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ); + } + + public Vector2 Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs.meta new file mode 100644 index 00000000..a241974a --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector2Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6ca8f5d67cf4c5f428a6dd646099897c +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs new file mode 100644 index 00000000..62be0696 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs @@ -0,0 +1,315 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Vector3", "Constants And Properties", "Vector3 property", null, KeyCode.Alpha3 )] + public sealed class Vector3Node : PropertyNode + { + [SerializeField] + private Vector3 m_defaultValue = Vector3.zero; + + [SerializeField] + private Vector3 m_materialValue = Vector3.zero; + + private const float LabelWidth = 8; + + private int m_cachedPropertyId = -1; + + public Vector3Node() : base() { } + public Vector3Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Vector" ); + m_insideSize.Set( 50, 30 ); + m_selectedLocation = PreviewLocation.BottomCenter; + AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" ); + m_previewShaderGUID = "8a44d38f06246bf48944b3f314bc7920"; + m_srpBatcherCompatible = true; + m_showHybridInstancedUI = true; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + m_defaultValue = EditorGUILayoutVector3Field( Constants.DefaultValueLabel, m_defaultValue ); + } + + public override void DrawMaterialProperties() + { + EditorGUI.BeginChangeCheck(); + + m_materialValue = EditorGUILayoutVector3Field( Constants.MaterialValueLabel, m_materialValue ); + + if( EditorGUI.EndChangeCheck() ) + { + //MarkForPreviewUpdate(); + if( m_materialMode ) + m_requireMaterialUpdate = true; + } + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputVector" ); + + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_materialValue[ 0 ], m_materialValue[ 1 ], m_materialValue[ 2 ], 0 ) ); + else + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_defaultValue[ 0 ], m_defaultValue[ 1 ], m_defaultValue[ 2 ], 0 ) ); + } + + private bool m_isEditingFields; + private Vector3 m_previousValue = Vector3.zero; + private string[] m_fieldText = new string[] { "0", "0", "0" }; + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if( !m_isVisible ) + return; + + if( m_isEditingFields && m_currentParameterType != PropertyType.Global) + { + EditorGUI.BeginChangeCheck(); + for( int i = 0; i < 3; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + float val = m_materialValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_materialValue[ i ] = val; + } + else + { + float val = m_defaultValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_defaultValue[ i ] = val; + } + } + if( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = m_materialMode; + BeginDelayedDirtyProperty(); + } + } + else if( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + + for( int i = 0; i < 3; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + if( GUI.enabled ) + { + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + } + + if( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + if( m_previousValue[ i ] != m_materialValue[ i ] ) + { + m_previousValue[ i ] = m_materialValue[ i ]; + m_fieldText[ i ] = m_materialValue[ i ].ToString(); + } + } + else + { + if( m_previousValue[ i ] != m_defaultValue[ i ] ) + { + m_previousValue[ i ] = m_defaultValue[ i ]; + m_fieldText[ i ] = m_defaultValue[ i ].ToString(); + } + } + + GUI.Label( fakeField, m_fieldText[ i ], UIUtils.MainSkin.textField ); + } + GUI.enabled = guiEnabled; + } + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) + { + Vector3 value = m_defaultValue; + dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( value.x + "," + value.y + "," + value.z ) ); + m_outputPorts[ 0 ].SetLocalValue( m_propertyName , dataCollector.PortCategory ); + m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".x" , dataCollector.PortCategory ); + m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".y" , dataCollector.PortCategory ); + m_outputPorts[ 3 ].SetLocalValue( m_propertyName + ".z", dataCollector.PortCategory ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if( m_currentParameterType != PropertyType.Constant ) + return GetOutputVectorItem( 0, outputId, PropertyData( dataCollector.PortCategory ) ); + + if( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + if( CheckLocalVariable( ref dataCollector ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + Vector3 value = m_defaultValue; + string result = string.Empty; + switch( outputId ) + { + case 0: + { + result = m_precisionString + "(" + value.x + "," + value.y + "," + value.z + ")"; + } + break; + + case 1: + { + result = value.x.ToString(); + } + break; + case 2: + { + result = value.y.ToString(); + } + break; + case 3: + { + result = value.z.ToString(); + } + break; + } + + if( result.Equals( string.Empty ) ) + { + UIUtils.ShowMessage( UniqueId, "Vector3Node generating empty code", MessageSeverity.Warning ); + } + return result; + } + + public override string GetPropertyValue() + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Vector) = (" + m_defaultValue.x + "," + m_defaultValue.y + "," + m_defaultValue.z + ",0)"; + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetVector( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat, bool fetchMaterialValues ) + { + base.SetMaterialMode( mat, fetchMaterialValues ); + if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetVector( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetVector( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToVector3( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + m_materialValue = IOUtils.StringToVector3( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector3ToString( m_defaultValue ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector3ToString( m_materialValue ) ); + } + + public override void SetGlobalValue() { Shader.SetGlobalVector( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalVector( m_propertyName ); } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue.x.ToString( Mathf.Abs( m_materialValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.y.ToString( Mathf.Abs( m_materialValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.z.ToString( Mathf.Abs( m_materialValue.z ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) : + m_defaultValue.x.ToString( Mathf.Abs( m_defaultValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.y.ToString( Mathf.Abs( m_defaultValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.z.ToString( Mathf.Abs( m_defaultValue.z ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ); + } + + public Vector3 Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs.meta new file mode 100644 index 00000000..467beba5 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector3Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 943f4b4fc1fa5214b8934bf4fb76474b +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs new file mode 100644 index 00000000..e729b0d0 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs @@ -0,0 +1,320 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Vector4", "Constants And Properties", "Vector4 property", null, KeyCode.Alpha4 )] + public sealed class Vector4Node : PropertyNode + { + [SerializeField] + private Vector4 m_defaultValue = Vector4.zero; + + [SerializeField] + private Vector4 m_materialValue = Vector4.zero; + + private const float LabelWidth = 8; + + private int m_cachedPropertyId = -1; + + private bool m_isEditingFields; + private Vector4 m_previousValue = Vector4.zero; + private string[] m_fieldText = new string[] { "0", "0", "0", "0" }; + + public Vector4Node() : base() { } + public Vector4Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { } + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Vector" ); + m_insideSize.Set( 50, 40 ); + m_selectedLocation = PreviewLocation.BottomCenter; + AddOutputVectorPorts( WirePortDataType.FLOAT4, "XYZW" ); + m_previewShaderGUID = "aac241d0e47a5a84fbd2edcd640788dc"; + m_srpBatcherCompatible = true; + m_showHybridInstancedUI = true; + } + + public override void CopyDefaultsToMaterial() + { + m_materialValue = m_defaultValue; + } + + public override void DrawSubProperties() + { + m_defaultValue = EditorGUILayoutVector4Field( Constants.DefaultValueLabel, m_defaultValue ); + } + + public override void DrawMaterialProperties() + { + if ( m_materialMode ) + EditorGUI.BeginChangeCheck(); + + m_materialValue = EditorGUILayoutVector4Field( Constants.MaterialValueLabel, m_materialValue ); + if ( m_materialMode && EditorGUI.EndChangeCheck() ) + m_requireMaterialUpdate = true; + + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if ( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_InputVector" ); + + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_materialValue[ 0 ], m_materialValue[ 1 ], m_materialValue[ 2 ], m_materialValue[ 3 ] ) ); + else + PreviewMaterial.SetVector( m_cachedPropertyId, new Vector4( m_defaultValue[ 0 ], m_defaultValue[ 1 ], m_defaultValue[ 2 ], m_defaultValue[ 3 ] ) ); + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos = m_remainingBox; + m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if ( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if ( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if ( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if ( !m_isVisible ) + return; + + if ( m_isEditingFields && m_currentParameterType != PropertyType.Global ) + { + EditorGUI.BeginChangeCheck(); + for ( int i = 0; i < 4; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + float val = m_materialValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_materialValue[ i ] = val; + } + else + { + float val = m_defaultValue[ i ]; + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref val, LabelWidth * drawInfo.InvertedZoom ); + m_defaultValue[ i ] = val; + } + } + if ( EditorGUI.EndChangeCheck() ) + { + PreviewIsDirty = true; + m_requireMaterialUpdate = m_materialMode; + BeginDelayedDirtyProperty(); + //m_propertyNameIsDirty = true; + } + } + else if ( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 ) + { + bool guiEnabled = GUI.enabled; + GUI.enabled = m_currentParameterType != PropertyType.Global; + + for( int i = 0; i < 4; i++ ) + { + m_propertyDrawPos.y = m_outputPorts[ i + 1 ].Position.y - 2 * drawInfo.InvertedZoom; + + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + if( GUI.enabled ) + { + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + } + if ( m_materialMode && m_currentParameterType != PropertyType.Constant ) + { + if ( m_previousValue[ i ] != m_materialValue[ i ] ) + { + m_previousValue[ i ] = m_materialValue[ i ]; + m_fieldText[ i ] = m_materialValue[ i ].ToString(); + } + } + else + { + if ( m_previousValue[ i ] != m_defaultValue[ i ] ) + { + m_previousValue[ i ] = m_defaultValue[ i ]; + m_fieldText[ i ] = m_defaultValue[ i ].ToString(); + } + } + + GUI.Label( fakeField, m_fieldText[ i ], UIUtils.MainSkin.textField ); + } + GUI.enabled = guiEnabled; + } + } + + public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) + { + Vector4 value = m_defaultValue; + dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( value.x + "," + value.y + "," + value.z + "," + value.w ) ); + m_outputPorts[ 0 ].SetLocalValue( m_propertyName, dataCollector.PortCategory ); + m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".x" , dataCollector.PortCategory ); + m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".y" , dataCollector.PortCategory ); + m_outputPorts[ 3 ].SetLocalValue( m_propertyName + ".z" , dataCollector.PortCategory ); + m_outputPorts[ 4 ].SetLocalValue( m_propertyName + ".w", dataCollector.PortCategory ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ); + + if ( m_currentParameterType != PropertyType.Constant ) + return GetOutputVectorItem( 0, outputId, PropertyData( dataCollector.PortCategory ) ); + + if ( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + if ( CheckLocalVariable( ref dataCollector ) ) + { + return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory ); + } + + Vector4 value = m_defaultValue; + string result = string.Empty; + switch ( outputId ) + { + case 0: + { + result = m_precisionString+"(" + value.x + "," + value.y + "," + value.z + "," + value.w + ")"; + } + break; + + case 1: + { + result = value.x.ToString(); + } + break; + case 2: + { + result = value.y.ToString(); + } + break; + case 3: + { + result = value.z.ToString(); + } + break; + case 4: + { + result = value.w.ToString(); + } + break; + } + + if ( result.Equals( string.Empty ) ) + { + UIUtils.ShowMessage( UniqueId, "Vector4Node generating empty code", MessageSeverity.Warning ); + } + return result; + } + + public override string GetPropertyValue() + { + return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Vector) = (" + m_defaultValue.x + "," + m_defaultValue.y + "," + m_defaultValue.z + "," + m_defaultValue.w + ")"; + } + + public override void UpdateMaterial( Material mat ) + { + base.UpdateMaterial( mat ); + if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction ) + { + mat.SetVector( m_propertyName, m_materialValue ); + } + } + + public override void SetMaterialMode( Material mat , bool fetchMaterialValues ) + { + base.SetMaterialMode( mat , fetchMaterialValues ); + if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) ) + { + m_materialValue = mat.GetVector( m_propertyName ); + } + } + + public override void ForceUpdateFromMaterial( Material material ) + { + if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) ) + { + m_materialValue = material.GetVector( m_propertyName ); + PreviewIsDirty = true; + } + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_defaultValue = IOUtils.StringToVector4( GetCurrentParam( ref nodeParams ) ); + if( UIUtils.CurrentShaderVersion() > 14101 ) + m_materialValue = IOUtils.StringToVector4( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector4ToString( m_defaultValue ) ); + IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector4ToString( m_materialValue ) ); + } + + public override void SetGlobalValue() { Shader.SetGlobalVector( m_propertyName, m_defaultValue ); } + public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalVector( m_propertyName ); } + + public override string GetPropertyValStr() + { + return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue.x.ToString( Mathf.Abs( m_materialValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.y.ToString( Mathf.Abs( m_materialValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.z.ToString( Mathf.Abs( m_materialValue.z ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_materialValue.w.ToString( Mathf.Abs( m_materialValue.w ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) : + m_defaultValue.x.ToString( Mathf.Abs( m_defaultValue.x ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.y.ToString( Mathf.Abs( m_defaultValue.y ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.z.ToString( Mathf.Abs( m_defaultValue.z ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR + + m_defaultValue.w.ToString( Mathf.Abs( m_defaultValue.w ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel ); + } + + public Vector4 Value + { + get { return m_defaultValue; } + set { m_defaultValue = value; } + } + } +} diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs.meta b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs.meta new file mode 100644 index 00000000..1cccc215 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/Vector4Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3bc3c79c7cc57df49bedb9d9b64b0bea +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |