예제 #1
0
		public bool ConnectTo( WireReference port )
		{
			if( m_locked )
				return false:

			if( m_externalReferences.Contains( port ) )
				return false:

			m_externalReferences.Add( port ):
			return true:
		}
예제 #2
0
 private void CacheCurrentSettings()
 {
     m_cacheNodeConnections.Clear();
     for (int portId = 0; portId < m_inputPorts.Count; portId++)
     {
         if (m_inputPorts[portId].IsConnected)
         {
             WireReference connection = m_inputPorts[portId].GetConnection();
             m_cacheNodeConnections.Add(m_inputPorts[portId].Name, new NodeCache(connection.NodeId, connection.PortId));
         }
     }
 }
        public bool ConnectTo(WireReference port)
        {
            if (m_locked)
            {
                return(false);
            }

            if (m_externalReferences.Contains(port))
            {
                return(false);
            }

            m_externalReferences.Add(port);
            return(true);
        }
예제 #4
0
		private void CacheCurrentSettings()
		{
			m_cacheNodeConnections.Clear():
			for( int portId = 0: portId < m_outputPorts.Count: portId++ )
			{
				if( m_outputPorts[ portId ].IsConnected )
				{
					int connCount = m_outputPorts[ portId ].ConnectionCount:
					for( int connIdx = 0: connIdx < connCount: connIdx++ )
					{
						WireReference connection = m_outputPorts[ portId ].GetConnection( connIdx ):
						m_cacheNodeConnections.Add( m_outputPorts[ portId ].Name, new NodeCache( connection.NodeId, connection.PortId ) ):
					}
				}
			}
		}
예제 #5
0
        public override void Rewire()
        {
            //if ( m_inputPorts[ 0 ].ExternalReferences != null && m_inputPorts[ 0 ].ExternalReferences.Count > 0 )
            //{
            //WireReference backPort = m_inputPorts[ 0 ].ExternalReferences[ 0 ];
            //for ( int i = 0; i < m_outputPorts[ 0 ].ExternalReferences.Count; i++ )
            //{
            //	UIUtils.CurrentWindow.ConnectInputToOutput( m_outputPorts[ 0 ].ExternalReferences[ i ].NodeId, m_outputPorts[ 0 ].ExternalReferences[ i ].PortId, backPort.NodeId, backPort.PortId );
            //}
            //}
            MarkToDelete = true;
            WireReference outputReference = FindNewValidInputNode(this);
            WireReference inputReference  = FindNewValidOutputNode(this);

            if (outputReference != null && inputReference != null)
            {
                UIUtils.CurrentWindow.ConnectInputToOutput(inputReference.NodeId, inputReference.PortId, outputReference.NodeId, outputReference.PortId);
            }
        }
예제 #6
0
        //public void AnaliseNode( ParentNode node, int outputTargetId, eWirePortDataType inputPortType, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
        //{
        //	dataCollector.AddInstructions( node.GetValueFromOutputStr( outputTargetId, inputPortType, ref dataCollector, ignoreLocalVar ) );
        //}

        public void CreateInstructionsForPort(InputPort port, string portName, bool addCustomDelimiters = false, string customDelimiterIn = null, string customDelimiterOut = null, bool ignoreLocalVar = false)
        {
            WireReference connection = port.GetConnection();
            ParentNode    node       = UIUtils.GetNode(connection.NodeId);

            string newInstruction = node.GetValueFromOutputStr(connection.PortId, port.DataType, ref UIUtils.CurrentDataCollector, ignoreLocalVar);

            if (UIUtils.CurrentDataCollector.DirtySpecialLocalVariables)
            {
                UIUtils.CurrentDataCollector.AddInstructions(UIUtils.CurrentDataCollector.SpecialLocalVariables);
                UIUtils.CurrentDataCollector.ClearSpecialLocalVariables();
            }
            if (UIUtils.CurrentDataCollector.ForceNormal)
            {
                UIUtils.CurrentDataCollector.AddToStartInstructions("\t\t\t" + Constants.OutputVarStr + ".Normal = float3(0,0,1);\n");
                UIUtils.CurrentDataCollector.ForceNormal = false;
            }

            UIUtils.CurrentDataCollector.AddInstructions(addCustomDelimiters ? customDelimiterIn : ("\t\t\t" + portName + " = "));
            UIUtils.CurrentDataCollector.AddInstructions(newInstruction);
            UIUtils.CurrentDataCollector.AddInstructions(addCustomDelimiters ? customDelimiterOut : ";\n");
        }
예제 #7
0
        public override Shader Execute(string pathname, bool isFullPath)
        {
            base.Execute(pathname, isFullPath);

            bool isInstancedShader = UIUtils.IsInstancedShader();

            UIUtils.CurrentDataCollector = new MasterNodeDataCollector();

            string tags = "\"RenderType\" = \"{0}\"  \"Queue\" = \"{1}\"";

            tags = string.Format(tags, m_renderType, (m_renderQueue + "+" + m_queueOrder));
            //if ( !m_customBlendMode )
            {
                if (m_alphaMode == AlphaMode.Fade || m_alphaMode == AlphaMode.Transparent)
                {
                    tags += " \"IgnoreProjector\" = \"True\"";
                }
            }

            tags = "Tags{ " + tags + " }";

            string outputStruct = "";

            switch (m_currentLightModel)
            {
            case StandardShaderLightModel.Standard: outputStruct = "SurfaceOutputStandard"; break;

            case StandardShaderLightModel.StandardSpecular: outputStruct = "SurfaceOutputStandardSpecular"; break;

            case StandardShaderLightModel.Lambert:
            case StandardShaderLightModel.BlinnPhong: outputStruct = "SurfaceOutput"; break;
            }

            outputStruct += " " + Constants.OutputVarStr;
            // Register Local variables
            AddLocalVarInstructions();


            if (m_inputPorts[m_inputPorts.Count - 1].IsConnected)
            {
                //Debug Port active
                InputPort debugPort = m_inputPorts[m_inputPorts.Count - 1];
                CreateInstructionsForPort(debugPort, Constants.OutputVarStr + ".Emission", false, null, null, UIUtils.IsNormalDependent());
            }
            else
            {
                // Custom Light Model
                //TODO: Create Custom Light behaviour
                SortedList <int, InputPort> sortedPorts = new SortedList <int, InputPort>();
                for (int i = 0; i < m_inputPorts.Count; i++)
                {
                    sortedPorts.Add(m_inputPorts[i].OrderId, m_inputPorts[i]);
                }
                //Collect data from standard nodes
                for (int i = 0; i < sortedPorts.Count; i++)
                {
                    if (sortedPorts[i].IsConnected)
                    {
                        if (i == 0)                          // Normal Map is Connected
                        {
                            UIUtils.CurrentDataCollector.DirtyNormal = true;
                        }

                        if (m_inputPorts[i].Name.Equals(DiscardStr))
                        {
                            //Discard Op Node
                            string opacityValue = "0.0";
                            switch (m_inputPorts[i].ConnectionType())
                            {
                            case WirePortDataType.INT:
                            case WirePortDataType.FLOAT:
                            {
                                opacityValue = IOUtils.MaskClipValueName;                                        //UIUtils.FloatToString( m_opacityMaskClipValue );
                            }
                            break;

                            case WirePortDataType.FLOAT2:
                            {
                                opacityValue = string.Format("( {0} ).xx", IOUtils.MaskClipValueName);
                            }
                            break;

                            case WirePortDataType.FLOAT3:
                            {
                                opacityValue = string.Format("( {0} ).xxx", IOUtils.MaskClipValueName);
                            }
                            break;

                            case WirePortDataType.FLOAT4:
                            {
                                opacityValue = string.Format("( {0} ).xxxx", IOUtils.MaskClipValueName);
                            }
                            break;
                            }
                            CreateInstructionsForPort(sortedPorts[i], Constants.OutputVarStr + "." + sortedPorts[i].DataName, true, "\t\t\tclip( ", " - " + opacityValue + " );\n");
                        }
                        else if (m_inputPorts[i].Name.Equals(VertexDisplacementStr))
                        {
                            //Vertex displacement and per vertex custom data
                            WireReference connection = m_inputPorts[i].GetConnection();
                            ParentNode    node       = UIUtils.GetNode(connection.NodeId);

                            string vertexInstructions = node.GetValueFromOutputStr(connection.PortId, m_inputPorts[i].DataType, ref UIUtils.CurrentDataCollector, true);

                            if (UIUtils.CurrentDataCollector.DirtySpecialLocalVariables)
                            {
                                UIUtils.CurrentDataCollector.AddVertexInstruction(UIUtils.CurrentDataCollector.SpecialLocalVariables, m_uniqueId, false);
                                UIUtils.CurrentDataCollector.ClearSpecialLocalVariables();
                            }

                            UIUtils.CurrentDataCollector.AddToVertexDisplacement(vertexInstructions);
                        }
                        else
                        {
                            // if working on normals and have normal dependent node then ignore local var generation
                            bool ignoreLocalVar = (i == 0 && UIUtils.IsNormalDependent());
                            CreateInstructionsForPort(sortedPorts[i], Constants.OutputVarStr + "." + sortedPorts[i].DataName, false, null, null, ignoreLocalVar);
                        }
                    }
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (UIUtils.CurrentDataCollector.GetChannelUsage(i) == TextureChannelUsage.Required)
                {
                    string channelName = UIUtils.GetChannelName(i);
                    UIUtils.CurrentDataCollector.AddToProperties(-1, UIUtils.GetTex2DProperty(channelName, TexturePropertyValues.white), -1);
                }
            }

            UIUtils.CurrentDataCollector.AddToProperties(-1, IOUtils.DefaultASEDirtyCheckProperty, -1);
            if (m_alphaMode == AlphaMode.Masked && !m_customBlendMode)
            {
                UIUtils.CurrentDataCollector.AddToProperties(-1, string.Format(IOUtils.MaskClipValueProperty, OpacityMaskClipValueStr, m_opacityMaskClipValue), -1);
                UIUtils.CurrentDataCollector.AddToUniforms(-1, string.Format(IOUtils.MaskClipValueUniform, m_opacityMaskClipValue));
            }

            //UIUtils.CurrentDataCollector.AddToUniforms( -1, IOUtils.DefaultASEDirtyCheckUniform );

            if (!UIUtils.CurrentDataCollector.DirtyInputs)
            {
                UIUtils.CurrentDataCollector.AddToInput(m_uniqueId, "fixed filler", true);
            }

            UIUtils.CurrentDataCollector.CloseInputs();
            UIUtils.CurrentDataCollector.CloseProperties();
            UIUtils.CurrentDataCollector.ClosePerVertexHeader();

            //build Shader Body
            //string ShaderBody = "Shader \"" + ( _isHidden ? "Hidden/" : String.Empty ) + ( _shaderCategory.Length > 0 ? ( _shaderCategory + "/" ) : String.Empty ) + _shaderName + "\"\n{\n";
            string ShaderBody = "Shader \"" + m_shaderName + "\"\n{\n";

            {
                //set properties
                if (UIUtils.CurrentDataCollector.DirtyProperties)
                {
                    //ShaderBody += UIUtils.CurrentDataCollector.Properties + '\n';
                    ShaderBody += UIUtils.CurrentDataCollector.BuildPropertiesString();
                }
                //set subshader
                ShaderBody += "\n\tSubShader\n\t{\n";
                {
                    //Add SubShader tags
                    ShaderBody += "\t\t" + tags + '\n';
                    ShaderBody += "\t\tCull " + m_cullMode + '\n';
                    //ShaderBody += "\t\tZWrite " + _zWriteMode + '\n';
                    //ShaderBody += "\t\tZTest " + _zTestMode + '\n';


                    //Add GrabPass
                    if (UIUtils.CurrentDataCollector.DirtyGrabPass)
                    {
                        ShaderBody += UIUtils.CurrentDataCollector.GrabPass;
                    }

                    //add cg program
                    ShaderBody += "\t\tCGPROGRAM\n";
                    {
                        //Add Includes
                        if (UIUtils.CurrentDataCollector.DirtyIncludes)
                        {
                            ShaderBody += UIUtils.CurrentDataCollector.Includes;
                        }

                        //define as surface shader and specify lighting model
                        ShaderBody += IOUtils.PragmaTargetHeader;
                        if (isInstancedShader)
                        {
                            ShaderBody += IOUtils.InstancedPropertiesHeader;
                        }

                        // build optional parameters
                        string OptionalParameters = string.Empty;
                        //if ( !m_customBlendMode )
                        {
                            switch (m_alphaMode)
                            {
                            case AlphaMode.Opaque:
                            case AlphaMode.Masked: break;

                            case AlphaMode.Fade:
                            {
                                OptionalParameters += "alpha:fade" + Constants.OptionalParametersSep;
                            }
                            break;

                            case AlphaMode.Transparent:
                            {
                                OptionalParameters += "alpha:premul" + Constants.OptionalParametersSep;
                            }
                            break;
                            }
                        }

                        if (m_keepAlpha)
                        {
                            OptionalParameters += "keepalpha" + Constants.OptionalParametersSep;
                        }

                        OptionalParameters += ((m_castShadows) ? "addshadow" + Constants.OptionalParametersSep + "fullforwardshadows" : "noshadow") + Constants.OptionalParametersSep;
                        ShaderBody         += "\t\t#pragma surface surf " + m_currentLightModel.ToString() + Constants.OptionalParametersSep + OptionalParameters;

                        //Add code generation options
                        for (int i = 0; i < m_codeGenerationDataList.Count; i++)
                        {
                            if (m_codeGenerationDataList[i].IsActive)
                            {
                                ShaderBody += m_codeGenerationDataList[i].Value + Constants.OptionalParametersSep;
                            }
                        }
                        //Check if Custom Vertex is being used and add tag
                        ShaderBody += UIUtils.CurrentDataCollector.DirtyPerVertexData ? "vertex:" + Constants.VertexDataFunc + "\n" : "\n";

                        // Add Input struct
                        if (UIUtils.CurrentDataCollector.DirtyInputs)
                        {
                            ShaderBody += UIUtils.CurrentDataCollector.Inputs + "\n\n";
                        }

                        //Add Uniforms
                        if (UIUtils.CurrentDataCollector.DirtyUniforms)
                        {
                            ShaderBody += UIUtils.CurrentDataCollector.Uniforms + "\n";
                        }


                        //Add Instanced Properties
                        if (isInstancedShader && UIUtils.CurrentDataCollector.DirtyInstancedProperties)
                        {
                            UIUtils.CurrentDataCollector.SetupInstancePropertiesBlock(UIUtils.RemoveInvalidCharacters(ShaderName));
                            ShaderBody += UIUtils.CurrentDataCollector.InstancedProperties + "\n";
                        }

                        if (UIUtils.CurrentDataCollector.DirtyFunctions)
                        {
                            ShaderBody += UIUtils.CurrentDataCollector.Functions + "\n";
                        }

                        //Add Custom Vertex Data
                        if (UIUtils.CurrentDataCollector.DirtyPerVertexData)
                        {
                            ShaderBody += UIUtils.CurrentDataCollector.VertexData;
                        }

                        //Add Surface Shader body
                        ShaderBody += "\t\tvoid surf( Input " + Constants.InputVarStr + " , inout " + outputStruct + " )\n\t\t{\n";
                        {
                            //add local vars
                            if (UIUtils.CurrentDataCollector.DirtyLocalVariables)
                            {
                                ShaderBody += UIUtils.CurrentDataCollector.LocalVariables;
                            }

                            //add nodes ops
                            ShaderBody += UIUtils.CurrentDataCollector.Instructions;
                        }
                        ShaderBody += "\t\t}\n";
                    }
                    ShaderBody += "\n\t\tENDCG\n";
                }
                ShaderBody += "\t}\n";
                ShaderBody += "\tFallback \"Diffuse\"\n";
            }
            ShaderBody += "}\n";

            // Generate Graph info
            ShaderBody += UIUtils.CurrentWindow.GenerateGraphInfo();

            //TODO: Remove current SaveDebugShader and uncomment SaveToDisk as soon as pathname is editable
            if (!String.IsNullOrEmpty(pathname))
            {
                IOUtils.StartSaveThread(ShaderBody, (isFullPath ? pathname : (IOUtils.dataPath + pathname)));
                //IOUtils.SaveTextfileToDisk( ShaderBody, ( isFullPath ? pathname : ( IOUtils.dataPath + pathname ) ) );
            }
            else
            {
                IOUtils.StartSaveThread(ShaderBody, Application.dataPath + "/AmplifyShaderEditor/Samples/Shaders/" + m_shaderName + ".shader");
                //IOUtils.SaveTextfileToDisk( ShaderBody, Application.dataPath + "/AmplifyShaderEditor/Samples/Shaders/" + m_shaderName + ".shader" );
            }

            // Load new shader into material

            if (CurrentShader == null)
            {
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                CurrentShader = Shader.Find(ShaderName);
            }
            else
            {
                // need to always get asset datapath because a user can change and asset location from the project window
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_currentShader));
            }

            if (m_currentShader != null)
            {
                //bool setShaderDefaults = false;
                if (m_currentMaterial != null)
                {
                    m_currentMaterial.shader = m_currentShader;
                    UIUtils.CurrentDataCollector.UpdateMaterialOnPropertyNodes(m_currentMaterial);
                    UpdateMaterialEditor();
                    // need to always get asset datapath because a user can change and asset location from the project window
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_currentMaterial));

                    //setShaderDefaults = ( UIUtils.CurrentWindow.CurrentSelection == ASESelectionMode.Shader );
                }
                //else
                //{
                //	setShaderDefaults = true;
                //}

                //if ( setShaderDefaults )
                UIUtils.CurrentDataCollector.UpdateShaderOnPropertyNodes(ref m_currentShader);
            }
            //AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate );

            UIUtils.CurrentDataCollector.Destroy();
            UIUtils.CurrentDataCollector = null;

            return(m_currentShader);
        }