Exemplo n.º 1
0
        bool TestIfValid()
        {
            if (!Alive)
            {
                return(false);
            }

            bool result = true;

            if (!m_inputPorts[0].IsConnected)
            {
                if (!m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid || m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid && m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.NodeId != UniqueId)
                {
                    ContainerGraph.MarkWireNodeSequence(this, true);
                    result = false;
                }
            }

            if (!m_outputPorts[0].IsConnected)
            {
                if (!m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid || m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid && m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.NodeId != UniqueId)
                {
                    ContainerGraph.MarkWireNodeSequence(this, false);
                    result = false;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public override void SetupNodeCategories()
        {
            //base.SetupNodeCategories();
            ContainerGraph.ResetNodesData();
            int count = m_inputPorts.Count;

            for (int i = 0; i < count; i++)
            {
                if (m_inputPorts[i].IsConnected)
                {
                    NodeData   nodeData = new NodeData(m_inputPorts[i].Category);
                    ParentNode node     = m_inputPorts[i].GetOutputNode();
                    node.PropagateNodeData(nodeData, ref m_currentDataCollector);
                }
                else if (m_inputPorts[i].HasExternalLink)
                {
                    InputPort linkedPort = m_inputPorts[i].ExternalLink;
                    if (linkedPort != null && linkedPort.IsConnected)
                    {
                        NodeData   nodeData = new NodeData(linkedPort.Category);
                        ParentNode node     = linkedPort.GetOutputNode();
                        node.PropagateNodeData(nodeData, ref m_currentDataCollector);
                    }
                }
            }
        }
        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;
            }
        }
Exemplo n.º 4
0
 public override void RefreshExternalReferences()
 {
     base.RefreshExternalReferences();
     if (m_isMainOutputNode)
     {
         ContainerGraph.AssignMasterNode(this, true);
     }
 }
Exemplo n.º 5
0
 public override void ReadFromString(ref string[] nodeParams)
 {
     base.ReadFromString(ref nodeParams);
     m_isMainOutputNode = Convert.ToBoolean(GetCurrentParam(ref nodeParams));
     if (m_isMainOutputNode)
     {
         ContainerGraph.AssignMasterNode(this, true);
     }
 }
Exemplo n.º 6
0
		public override void ReadFromString( ref string[] nodeParams )
		{
			base.ReadFromString( ref nodeParams ):
			m_isMainOutputNode = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ):
			if( m_isMainOutputNode && !ContainerGraph.IsDuplicating )
			{
				ContainerGraph.AssignMasterNode( this, true ):
			}
		}
Exemplo n.º 7
0
        public void DuplicateMe()
        {
            bool        previewOpen = m_showPreview;
            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = null;
            if (ContainerGraph.ParentWindow.CurrentGraph.CurrentStandardSurface != null)
            {
                ContainerGraph.ParentWindow.CurrentGraph.CurrentStandardSurface.InvalidateMaterialPropertyCount();
            }
            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            ParentNode newNode = ContainerGraph.CreateNode(m_function, false, Vec2Position);

            newNode.RefreshExternalReferences();
            newNode.ShowPreview = previewOpen;
            if ((newNode as FunctionNode).m_reordenator && m_reordenator)
            {
                (newNode as FunctionNode).m_reordenator.OrderIndex = m_reordenator.OrderIndex;
            }
            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                if (m_outputPorts[i].IsConnected)
                {
                    if (newNode.OutputPorts != null && newNode.OutputPorts[i] != null)
                    {
                        for (int j = m_outputPorts[i].ExternalReferences.Count - 1; j >= 0; j--)
                        {
                            ContainerGraph.CreateConnection(m_outputPorts[i].ExternalReferences[j].NodeId, m_outputPorts[i].ExternalReferences[j].PortId, newNode.OutputPorts[i].NodeId, newNode.OutputPorts[i].PortId);
                        }
                    }
                }
                else
                {
                    if (newNode.OutputPorts != null && newNode.OutputPorts[i] != null)
                    {
                        ContainerGraph.DeleteConnection(false, newNode.UniqueId, i, false, false, false);
                    }
                }
            }

            for (int i = 0; i < m_inputPorts.Count; i++)
            {
                if (m_inputPorts[i].IsConnected)
                {
                    if (newNode.InputPorts != null && i < newNode.InputPorts.Count && newNode.InputPorts[i] != null)
                    {
                        ContainerGraph.CreateConnection(newNode.InputPorts[i].NodeId, newNode.InputPorts[i].PortId, m_inputPorts[i].ExternalReferences[0].NodeId, m_inputPorts[i].ExternalReferences[0].PortId);
                    }
                }
            }

            ContainerGraph.OnDuplicateEvent -= DuplicateMe;

            ContainerGraph.DestroyNode(this, false);
        }
        public override bool RecursivePreviewUpdate(Dictionary <string, bool> duplicatesDict = null)
        {
            if (duplicatesDict == null)
            {
                duplicatesDict = ContainerGraph.ParentWindow.VisitedChanged;
            }

            for (int i = 0; i < InputPorts.Count; i++)
            {
                ParentNode outNode = null;
                if (Fnode != null)
                {
                    var input = Fnode.GetInput(this);
                    if (input.ExternalReferences.Count > 0)
                    {
                        outNode = Fnode.ContainerGraph.GetNode(input.ExternalReferences[0].NodeId);
                    }
                    else if (InputPorts[i].ExternalReferences.Count > 0)
                    {
                        outNode = ContainerGraph.GetNode(InputPorts[i].ExternalReferences[0].NodeId);
                    }
                }
                else
                {
                    if (InputPorts[i].ExternalReferences.Count > 0)
                    {
                        outNode = ContainerGraph.GetNode(InputPorts[i].ExternalReferences[0].NodeId);
                    }
                }
                if (outNode != null)
                {
                    if (!duplicatesDict.ContainsKey(outNode.OutputId))
                    {
                        bool result = outNode.RecursivePreviewUpdate();
                        if (result)
                        {
                            PreviewIsDirty = true;
                        }
                    }
                    else if (duplicatesDict[outNode.OutputId])
                    {
                        PreviewIsDirty = true;
                    }
                }
            }

            bool needsUpdate = PreviewIsDirty;

            RenderNodePreview();
            if (!duplicatesDict.ContainsKey(OutputId))
            {
                duplicatesDict.Add(OutputId, needsUpdate);
            }
            return(needsUpdate);
        }
Exemplo n.º 9
0
		public override void OnNodeDoubleClicked( Vector2 currentMousePos2D )
		{
			if( Function == null )
				return;

			ContainerGraph.DeSelectAll();
			this.Selected = true;

			ContainerGraph.ParentWindow.OnLeftMouseUp();
			AmplifyShaderEditorWindow.LoadShaderFunctionToASE( Function, true );
			this.Selected = false;
		}
Exemplo n.º 10
0
 public virtual void SetupNodeCategories()
 {
     ContainerGraph.ResetNodesData();
     //int count = m_inputPorts.Count;
     //for( int i = 0; i < count; i++ )
     //{
     //	if( m_inputPorts[ i ].IsConnected )
     //	{
     //		NodeData nodeData = new NodeData( m_inputPorts[ i ].Category );
     //		ParentNode node = m_inputPorts[ i ].GetOutputNode();
     //		node.PropagateNodeData( nodeData, ref collector );
     //	}
     //}
 }
Exemplo n.º 11
0
        public override void ReadFromString(ref string[] nodeParams)
        {
            base.ReadFromString(ref nodeParams);
            m_isMainOutputNode = Convert.ToBoolean(GetCurrentParam(ref nodeParams));
            if (UIUtils.CurrentShaderVersion() > LOD_SUBSHADER_VERSION)
            {
                m_lodIndex = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            }

            if (IsLODMainMasterNode && !ContainerGraph.IsDuplicating)
            {
                ContainerGraph.AssignMasterNode(this, true);
            }
        }
Exemplo n.º 12
0
        public void SetupNodeCategories()
        {
            ContainerGraph.ResetNodesData();
            int count = m_inputPorts.Count;

            for (int i = 0; i < count; i++)
            {
                if (m_inputPorts[i].IsConnected)
                {
                    NodeData   nodeData = new NodeData(m_inputPorts[i].Category);
                    ParentNode node     = m_inputPorts[i].GetOutputNode();
                    node.PropagateNodeData(nodeData, ref m_currentDataCollector);
                }
            }
        }
Exemplo n.º 13
0
        void TestIfValid()
        {
            if (!m_inputPorts[0].IsConnected)
            {
                if (!m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid || m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid && m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.NodeId != UniqueId)
                {
                    ContainerGraph.MarkWireNodeSequence(this, true);
                }
            }

            if (!m_outputPorts[0].IsConnected)
            {
                if (!m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid || m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid && m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.NodeId != UniqueId)
                {
                    ContainerGraph.MarkWireNodeSequence(this, false);
                }
            }
        }
Exemplo n.º 14
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.TesselationActive)
            {
                UIUtils.ShowMessage("Unable to use Vertex to Frag when Tessellation is active");
                return("0");
            }

            string tpName = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, m_inputPorts[0].DataType);

            string interpName = "data" + UniqueId;

            dataCollector.AddToInput(UniqueId, tpName + " " + interpName, true);

            MasterNodePortCategory portCategory = dataCollector.PortCategory;

            if (dataCollector.PortCategory != MasterNodePortCategory.Vertex && dataCollector.PortCategory != MasterNodePortCategory.Tessellation)
            {
                dataCollector.PortCategory = MasterNodePortCategory.Vertex;
            }

            bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;

            ContainerGraph.ResetNodesLocalVariables(this);

            string vertexVarValue = m_inputPorts[0].GeneratePortInstructions(ref dataCollector) + ";";

            dataCollector.AddLocalVariable(UniqueId, Constants.VertexShaderOutputStr + "." + interpName, vertexVarValue);

            dataCollector.PortCategory = portCategory;

            if (!dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables)
            {
                dataCollector.AddVertexInstruction(UIUtils.CurrentDataCollector.VertexLocalVariables, UniqueId, false);
                UIUtils.CurrentDataCollector.ClearVertexLocalVariables();
                ContainerGraph.ResetNodesLocalVariables(this);
            }

            //dataCollector.AddVertexInstruction( Constants.VertexShaderOutputStr + "." + interpName + " = interp" + m_uniqueId, m_uniqueId );
            return(Constants.InputVarStr + "." + interpName);
        }
Exemplo n.º 15
0
        public override void SetupNodeCategories()
        {
            //base.SetupNodeCategories();
            ContainerGraph.ResetNodesData();

            if (ContainerGraph.ParentWindow.CurrentGraph.CurrentStandardSurface != null)
            {
                int count = m_inputPorts.Count;
                for (int i = 0; i < count; i++)
                {
                    if (m_inputPorts[i].IsConnected)
                    {
                        NodeData   nodeData          = new NodeData(m_inputPorts[i].Category);
                        ParentNode node              = m_inputPorts[i].GetOutputNode();
                        MasterNodeDataCollector temp = ContainerGraph.ParentWindow.CurrentGraph.CurrentStandardSurface.CurrentDataCollector;
                        node.PropagateNodeData(nodeData, ref temp);
                        temp = null;
                    }
                }
            }
        }
Exemplo n.º 16
0
		public override void SetupNodeCategories()
		{
			//base.SetupNodeCategories():
			ContainerGraph.ResetNodesData():
			MasterNode masterNode = ContainerGraph.ParentWindow.CurrentGraph.CurrentMasterNode:
			if( masterNode != null )
			{
				int count = m_inputPorts.Count:
				for( int i = 0: i < count: i++ )
				{
					if( m_inputPorts[ i ].IsConnected )
					{
						NodeData nodeData = new NodeData( m_inputPorts[ i ].Category ):
						ParentNode node = m_inputPorts[ i ].GetOutputNode():
						MasterNodeDataCollector temp = masterNode.CurrentDataCollector:
						node.PropagateNodeData( nodeData, ref temp ):
						temp = null:
					}
				}
			}
		}
Exemplo n.º 17
0
        public void DuplicateMe()
        {
            ParentNode newNode = ContainerGraph.CreateNode(m_function, false, Vec2Position);

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                if (m_outputPorts[i].IsConnected)
                {
                    if (newNode.OutputPorts != null && newNode.OutputPorts[i] != null)
                    {
                        for (int j = m_outputPorts[i].ExternalReferences.Count - 1; j >= 0; j--)
                        {
                            ContainerGraph.CreateConnection(m_outputPorts[i].ExternalReferences[j].NodeId, m_outputPorts[i].ExternalReferences[j].PortId, newNode.OutputPorts[i].NodeId, newNode.OutputPorts[i].PortId);
                        }
                    }
                }
                else
                {
                    if (newNode.OutputPorts != null && newNode.OutputPorts[i] != null)
                    {
                        ContainerGraph.DeleteConnection(false, newNode.UniqueId, i, false, false, false);
                    }
                }
            }

            for (int i = 0; i < m_inputPorts.Count; i++)
            {
                if (m_inputPorts[i].IsConnected)
                {
                    if (newNode.InputPorts != null && i < newNode.InputPorts.Count && newNode.InputPorts[i] != null)
                    {
                        ContainerGraph.CreateConnection(newNode.InputPorts[i].NodeId, newNode.InputPorts[i].PortId, m_inputPorts[i].ExternalReferences[0].NodeId, m_inputPorts[i].ExternalReferences[0].PortId);
                    }
                }
            }

            ContainerGraph.OnDuplicateEvent -= DuplicateMe;

            ContainerGraph.DestroyNode(this, false);
        }
Exemplo n.º 18
0
 public virtual Shader Execute(string pathname, bool isFullPath)
 {
     ContainerGraph.ResetNodesLocalVariables();
     m_currentDataCollector = new MasterNodeDataCollector(this);
     return(null);
 }
        public void CollectData()
        {
            if (m_inputPorts.Count == 0)
            {
                return;
            }

            ContainerGraph.ResetNodesLocalVariables();
            m_currentDataCollector = new MasterNodeDataCollector(this);
            m_currentDataCollector.TemplateDataCollectorInstance.SetMultipassInfo(m_subShaderIdx, m_passIdx, m_templateMultiPass.SubShaders[m_subShaderIdx].Modules.SRPType);
            m_currentDataCollector.TemplateDataCollectorInstance.FillSpecialVariables(m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx]);
            SetupNodeCategories();

            TemplateData templateData = m_templateMultiPass.CreateTemplateData(m_shaderName, string.Empty, m_subShaderIdx, m_passIdx);

            m_currentDataCollector.TemplateDataCollectorInstance.BuildFromTemplateData(m_currentDataCollector, templateData);

            //Copy Properties
            {
                int shaderPropertiesAmount = m_templateMultiPass.AvailableShaderProperties.Count;
                for (int i = 0; i < shaderPropertiesAmount; i++)
                {
                    m_currentDataCollector.SoftRegisterUniform(m_templateMultiPass.AvailableShaderProperties[i].PropertyName);
                }
            }
            //Copy Globals from SubShader level
            {
                int subShaderGlobalAmount = m_templateMultiPass.SubShaders[m_subShaderIdx].AvailableShaderGlobals.Count;
                for (int i = 0; i < subShaderGlobalAmount; i++)
                {
                    m_currentDataCollector.SoftRegisterUniform(m_templateMultiPass.SubShaders[m_subShaderIdx].AvailableShaderGlobals[i].PropertyName);
                }
            }
            //Copy Globals from Pass Level
            {
                int passGlobalAmount = m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].AvailableShaderGlobals.Count;
                for (int i = 0; i < passGlobalAmount; i++)
                {
                    m_currentDataCollector.SoftRegisterUniform(m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].AvailableShaderGlobals[i].PropertyName);
                }
            }


            m_containerGraph.CheckPropertiesAutoRegister(ref m_currentDataCollector);

            //Sort ports by both
            List <InputPort> fragmentPorts = new List <InputPort>();
            List <InputPort> vertexPorts   = new List <InputPort>();

            SortInputPorts(ref vertexPorts, ref fragmentPorts);


            string shaderBody = templateData.TemplateBody;

            List <string> vertexInstructions   = new List <string>();
            List <string> fragmentInstructions = new List <string>();

            bool validBody = true;

            validBody = CreateInstructionsForList(templateData, ref fragmentPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions) && validBody;
            ContainerGraph.ResetNodesLocalVariablesIfNot(MasterNodePortCategory.Vertex);
            validBody = CreateInstructionsForList(templateData, ref vertexPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions) && validBody;

            templateData.ResetTemplateUsageData();

            // Fill vertex interpolators assignment
            for (int i = 0; i < m_currentDataCollector.VertexInterpDeclList.Count; i++)
            {
                vertexInstructions.Add(m_currentDataCollector.VertexInterpDeclList[i]);
            }

            vertexInstructions.AddRange(m_currentDataCollector.TemplateDataCollectorInstance.GetInterpUnusedChannels());

            //Fill common local variables and operations
            validBody = m_templateMultiPass.FillVertexInstructions(m_subShaderIdx, m_passIdx, vertexInstructions.ToArray()) && validBody;
            validBody = m_templateMultiPass.FillFragmentInstructions(m_subShaderIdx, m_passIdx, fragmentInstructions.ToArray()) && validBody;

            vertexInstructions.Clear();
            vertexInstructions = null;

            fragmentInstructions.Clear();
            fragmentInstructions = null;

            // Add Instanced Properties
            if (m_containerGraph.IsInstancedShader)
            {
                m_currentDataCollector.TabifyInstancedVars();
                m_currentDataCollector.InstancedPropertiesList.Insert(0, new PropertyDataCollector(-1, string.Format(IOUtils.InstancedPropertiesBegin, UIUtils.RemoveInvalidCharacters(m_shaderName))));
                m_currentDataCollector.InstancedPropertiesList.Add(new PropertyDataCollector(-1, IOUtils.InstancedPropertiesEnd));
                m_currentDataCollector.UniformsList.AddRange(m_currentDataCollector.InstancedPropertiesList);
            }

            //Add Functions
            m_currentDataCollector.UniformsList.AddRange(m_currentDataCollector.FunctionsList);
        }
Exemplo n.º 20
0
        public void DuplicateMe()
        {
            bool previewOpen = m_showPreview;

            string allOptions = m_allFunctionSwitches.Count.ToString();

            for (int i = 0; i < m_allFunctionSwitches.Count; i++)
            {
                allOptions += "," + m_allFunctionSwitches[i].UniqueId + "," + m_allFunctionSwitches[i].GetCurrentSelectedInput();
            }

            ReadOptionsHelper = allOptions.Split(',');

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = null;
            MasterNode masterNode = ContainerGraph.ParentWindow.CurrentGraph.CurrentMasterNode;

            if (masterNode != null)
            {
                masterNode.InvalidateMaterialPropertyCount();
            }

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            ParentNode newNode = ContainerGraph.CreateNode(m_function, false, Vec2Position);

            newNode.ShowPreview = previewOpen;
            (newNode as FunctionNode).ReadOptionsHelper = ReadOptionsHelper;
            newNode.RefreshExternalReferences();
            if ((newNode as FunctionNode).m_reordenator && m_reordenator)
            {
                (newNode as FunctionNode).m_reordenator.OrderIndex = m_reordenator.OrderIndex;
            }

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                if (m_outputPorts[i].IsConnected)
                {
                    OutputPort newOutputPort = newNode.GetOutputPortByUniqueId(m_outputPorts[i].PortId);
                    if (newNode.OutputPorts != null && newOutputPort != null)
                    {
                        for (int j = m_outputPorts[i].ExternalReferences.Count - 1; j >= 0; j--)
                        {
                            ContainerGraph.CreateConnection(m_outputPorts[i].ExternalReferences[j].NodeId, m_outputPorts[i].ExternalReferences[j].PortId, newOutputPort.NodeId, newOutputPort.PortId);
                        }
                    }
                }
                //else
                //{
                //if( newNode.OutputPorts != null && newNode.OutputPorts[ i ] != null )
                //{
                //    ContainerGraph.DeleteConnection( false, newNode.UniqueId, newNode.OutputPorts[ i ].PortId, false, false, false );
                //}
                //}
            }

            for (int i = 0; i < m_inputPorts.Count; i++)
            {
                if (m_inputPorts[i].IsConnected)
                {
                    InputPort newInputPort = newNode.GetInputPortByUniqueId(m_inputPorts[i].PortId);
                    if (newNode.InputPorts != null && newInputPort != null)
                    {
                        ContainerGraph.CreateConnection(newInputPort.NodeId, newInputPort.PortId, m_inputPorts[i].ExternalReferences[0].NodeId, m_inputPorts[i].ExternalReferences[0].PortId);
                    }
                }
            }

            ContainerGraph.OnDuplicateEvent -= DuplicateMe;

            if (Selected)
            {
                ContainerGraph.DeselectNode(this);
                ContainerGraph.SelectNode(newNode, true, false);
            }

            ContainerGraph.DestroyNode(this, false);
        }
Exemplo n.º 21
0
        public override void OnNodeLayout(DrawInfo drawInfo)
        {
            if (m_nodesIds.Count > 0)
            {
                for (int i = 0; i < m_nodesIds.Count; i++)
                {
                    ParentNode node = ContainerGraph.GetNode(m_nodesIds[i]);
                    if (node)
                    {
                        AddNodeToCommentary(node);
                    }
                }
                m_nodesIds.Clear();
            }

            if (m_reRegisterNodes)
            {
                m_reRegisterNodes = false;
                m_nodesOnCommentaryDict.Clear();
                for (int i = 0; i < m_nodesOnCommentary.Count; i++)
                {
                    if (m_nodesOnCommentary[i] != null)
                    {
                        m_nodesOnCommentary[i].OnNodeStoppedMovingEvent += NodeStoppedMoving;
                        m_nodesOnCommentary[i].OnNodeDestroyedEvent     += NodeDestroyed;
                        m_nodesOnCommentaryDict.Add(m_nodesOnCommentary[i].UniqueId, m_nodesOnCommentary[i]);
                    }
                }
            }

            //base.OnLayout( drawInfo );
            CalculatePositionAndVisibility(drawInfo);

            m_headerPosition        = m_globalPosition;
            m_headerPosition.height = UIUtils.CurrentHeaderHeight;

            m_auxHeaderPos        = m_position;
            m_auxHeaderPos.height = UIUtils.HeaderMaxHeight;

            m_commentArea        = m_globalPosition;
            m_commentArea.height = COMMENTARY_BOX_HEIGHT * drawInfo.InvertedZoom;
            m_commentArea.xMin  += 10 * drawInfo.InvertedZoom;
            m_commentArea.xMax  -= 10 * drawInfo.InvertedZoom;

            if (m_resizeIconTex == null)
            {
                m_resizeIconTex = UIUtils.GetCustomStyle(CustomStyle.CommentaryResizeButton).normal.background;
            }

            // LEFT RESIZE BUTTON
            m_resizeLeftIconCoords        = m_globalPosition;
            m_resizeLeftIconCoords.x      = m_globalPosition.x + 2;
            m_resizeLeftIconCoords.y      = m_globalPosition.y + m_globalPosition.height - 2 - (m_resizeIconTex.height + ResizeButtonPos.y) * drawInfo.InvertedZoom;
            m_resizeLeftIconCoords.width  = m_resizeIconTex.width * drawInfo.InvertedZoom;
            m_resizeLeftIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;

            // RIGHT RESIZE BUTTON
            m_resizeRightIconCoords        = m_globalPosition;
            m_resizeRightIconCoords.x      = m_globalPosition.x + m_globalPosition.width - 1 - (m_resizeIconTex.width + ResizeButtonPos.x) * drawInfo.InvertedZoom;
            m_resizeRightIconCoords.y      = m_globalPosition.y + m_globalPosition.height - 2 - (m_resizeIconTex.height + ResizeButtonPos.y) * drawInfo.InvertedZoom;
            m_resizeRightIconCoords.width  = m_resizeIconTex.width * drawInfo.InvertedZoom;
            m_resizeRightIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;
        }
Exemplo n.º 22
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                return("0");
            }

            if (dataCollector.IsFragmentCategory)
            {
                UIUtils.ShowMessage(ErrorMessage);
                return("0");
            }
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return("0");
            }

            m_outputPorts[0].SetLocalValue("0", dataCollector.PortCategory);

            StandardSurfaceOutputNode masterNode = m_containerGraph.CurrentMasterNode as StandardSurfaceOutputNode;

            MasterNodeDataCollector outlineDataCollector = new MasterNodeDataCollector();

            outlineDataCollector.IsOutlineDataCollector = true;
            outlineDataCollector.DirtyNormal            = true;
            InputPort colorPort  = GetInputPortByUniqueId(0);
            InputPort alphaPort  = GetInputPortByUniqueId(2);
            InputPort vertexPort = GetInputPortByUniqueId(1);

            if (vertexPort.IsConnected)
            {
                outlineDataCollector.PortCategory = MasterNodePortCategory.Vertex;
                string outlineWidth = vertexPort.GenerateShaderForOutput(ref outlineDataCollector, vertexPort.DataType, true, true);
                outlineDataCollector.AddToVertexLocalVariables(UniqueId, PrecisionType.Float, vertexPort.DataType, "outlineVar", outlineWidth);

                outlineDataCollector.AddVertexInstruction(outlineDataCollector.SpecialLocalVariables, UniqueId, false);
                outlineDataCollector.ClearSpecialLocalVariables();

                outlineDataCollector.AddVertexInstruction(outlineDataCollector.VertexLocalVariables, UniqueId, false);
                outlineDataCollector.ClearVertexLocalVariables();

                // need to check whether this breaks other outputs or not
                ContainerGraph.ResetNodesLocalVariables();
            }

            outlineDataCollector.PortCategory = MasterNodePortCategory.Fragment;
            string outlineColor = colorPort.GeneratePortInstructions(ref outlineDataCollector);              // "\to.Emission = " + colorPort.GeneratePortInstructions( ref outlineDataCollector ) + ";";
            string alphaValue   = alphaPort.Visible ? alphaPort.GeneratePortInstructions(ref outlineDataCollector) : string.Empty;

            bool addTabs = outlineDataCollector.DirtySpecialLocalVariables || alphaPort.Available;

            outlineDataCollector.AddInstructions("\t" + outlineDataCollector.SpecialLocalVariables.TrimStart('\t'));
            outlineDataCollector.ClearSpecialLocalVariables();
            outlineDataCollector.AddInstructions((addTabs ? "\t\t\t" : "") + "o.Emission = " + outlineColor + ";");
            if (alphaPort.Visible)
            {
                if (m_currentAlphaMode == OutlineAlphaModes.Masked)
                {
                    float maskClipValue = 0.5f;

                    if (masterNode != null)
                    {
                        maskClipValue = masterNode.OpacityMaskClipValue;
                    }

                    if (masterNode.InlineOpacityMaskClipValue.IsValid)
                    {
                        RangedFloatNode fnode = UIUtils.GetNode(masterNode.InlineOpacityMaskClipValue.NodeId) as RangedFloatNode;
                        if (fnode != null)
                        {
                            outlineDataCollector.AddToProperties(fnode.UniqueId, fnode.GetPropertyValue(), fnode.OrderIndex);
                            outlineDataCollector.AddToUniforms(fnode.UniqueId, fnode.GetUniformValue());
                        }
                        else
                        {
                            IntNode inode = UIUtils.GetNode(masterNode.InlineOpacityMaskClipValue.NodeId) as IntNode;
                            outlineDataCollector.AddToProperties(inode.UniqueId, inode.GetPropertyValue(), inode.OrderIndex);
                            outlineDataCollector.AddToUniforms(inode.UniqueId, inode.GetUniformValue());
                        }
                    }
                    else
                    {
                        outlineDataCollector.AddToProperties(-1, string.Format(IOUtils.MaskClipValueProperty, OpacityMaskClipValueStr, maskClipValue), -1);
                        outlineDataCollector.AddToUniforms(-1, string.Format(IOUtils.MaskClipValueUniform, maskClipValue));
                    }

                    outlineDataCollector.AddInstructions((addTabs ? "\n\t\t\t" : "") + "clip( " + alphaValue + " - " + masterNode.InlineOpacityMaskClipValue.GetValueOrProperty(IOUtils.MaskClipValueName, false) + " );");
                }
                else
                {
                    outlineDataCollector.AddInstructions((addTabs ? "\n\t\t\t" : "") + "o.Alpha = " + alphaValue + ";");
                }
            }

            if (outlineDataCollector.UsingWorldNormal)
            {
                outlineDataCollector.AddInstructions((addTabs ? "\n\t\t\t" : "") + "o.Normal = float3(0,0,-1);");
            }

            if (masterNode != null)
            {
                //masterNode.AdditionalIncludes.AddToDataCollector( ref outlineDataCollector );
                //masterNode.AdditionalPragmas.AddToDataCollector( ref outlineDataCollector );
                //masterNode.AdditionalDefines.AddToDataCollector( ref outlineDataCollector );
                masterNode.AdditionalDirectives.AddAllToDataCollector(ref outlineDataCollector);
            }

            ContainerGraph.CurrentStandardSurface.OutlineHelper.InputList       = outlineDataCollector.InputList;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Inputs          = outlineDataCollector.Inputs;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.DirtyInput      = outlineDataCollector.DirtyInputs;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Includes        = outlineDataCollector.Includes;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Pragmas         = outlineDataCollector.Pragmas;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Defines         = outlineDataCollector.Defines;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Uniforms        = outlineDataCollector.Uniforms;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.UniformList     = outlineDataCollector.UniformsList;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.VertexData      = outlineDataCollector.VertexData;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Instructions    = outlineDataCollector.Instructions;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Functions       = outlineDataCollector.Functions;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.LocalFunctions  = outlineDataCollector.LocalFunctions;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.OutlineCullMode = m_cullMode;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.ZTestMode       = m_zTestMode;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.ZWriteMode      = m_zWriteMode;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.OffsetMode      = m_currentSelectedMode;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.CustomNoFog     = m_noFog;
            dataCollector.CustomOutlineSelectedAlpha = (int)m_currentAlphaMode;

            for (int i = 0; i < outlineDataCollector.PropertiesList.Count; i++)
            {
                dataCollector.AddToProperties(UniqueId, outlineDataCollector.PropertiesList[i].PropertyName, outlineDataCollector.PropertiesList[i].OrderIndex);
            }

            ContainerGraph.ResetNodesLocalVariablesIfNot(MasterNodePortCategory.Vertex);
            return("0");
        }
Exemplo n.º 23
0
        public override void Draw(DrawInfo drawInfo)
        {
            if (m_initialized)
            {
                Color bufferedColor = GUI.color;
                if (m_nodesIds.Count > 0)
                {
                    for (int i = 0; i < m_nodesIds.Count; i++)
                    {
                        ParentNode node = ContainerGraph.GetNode(m_nodesIds[i]);
                        if (node)
                        {
                            AddNodeToCommentary(node);
                        }
                    }
                    m_nodesIds.Clear();
                }

                if (m_reRegisterNodes)
                {
                    m_reRegisterNodes = false;
                    m_nodesOnCommentaryDict.Clear();
                    for (int i = 0; i < m_nodesOnCommentary.Count; i++)
                    {
                        if (m_nodesOnCommentary[i] != null)
                        {
                            m_nodesOnCommentary[i].OnNodeStoppedMovingEvent += NodeStoppedMoving;
                            m_nodesOnCommentary[i].OnNodeDestroyedEvent     += NodeDestroyed;
                            m_nodesOnCommentaryDict.Add(m_nodesOnCommentary[i].UniqueId, m_nodesOnCommentary[i]);
                        }
                    }
                }

                CalculatePositionAndVisibility(drawInfo);

                if (!string.IsNullOrEmpty(m_titleText))
                {
                    Rect titleRect = m_globalPosition;
                    titleRect.y     -= 24;
                    titleRect.height = 24;
                    GUI.Label(titleRect, m_titleText, UIUtils.GetCustomStyle(CustomStyle.CommentarySuperTitle));
                }

                // Render Node
                GUI.color = Constants.NodeBodyColor;
                GUI.Box(m_globalPosition, string.Empty, UIUtils.GetCustomStyle(CustomStyle.CommentaryBackground));

                GUI.color = Color.white;
                Rect commentArea = m_globalPosition;
                commentArea.y     -= 1;
                commentArea.height = COMMENTARY_BOX_HEIGHT * drawInfo.InvertedZoom;
                commentArea.width *= 0.93f;
                commentArea.x     += 10 * drawInfo.InvertedZoom;

                GUI.color               = m_headerColor;
                m_headerPosition        = m_globalPosition;
                m_headerPosition.height = UIUtils.CurrentHeaderHeight;

                GUI.Box(m_headerPosition, string.Empty, UIUtils.GetCustomStyle(CustomStyle.NodeHeader));

                GUI.color = bufferedColor;
                if (m_selected)
                {
                    GUI.Box(m_globalPosition, string.Empty, UIUtils.GetCustomStyle(CustomStyle.NodeWindowOn));
                }
                EditorGUI.BeginChangeCheck();
                m_commentText = EditorGUITextField(commentArea, string.Empty, m_commentText, UIUtils.GetCustomStyle(CustomStyle.CommentaryTitle));
                if (EditorGUI.EndChangeCheck())
                {
                    m_checkCommentText = true;
                }

                if (m_resizeIconTex == null)
                {
                    m_resizeIconTex = UIUtils.GetCustomStyle(CustomStyle.CommentaryResizeButton).normal.background;
                }


                // RIGHT RESIZE BUTTON

                m_resizeRightIconCoords        = m_globalPosition;
                m_resizeRightIconCoords.x      = m_globalPosition.x + m_globalPosition.width - 1 - (m_resizeIconTex.width + ResizeButtonPos.x) * drawInfo.InvertedZoom;
                m_resizeRightIconCoords.y      = m_globalPosition.y + m_globalPosition.height - 2 - (m_resizeIconTex.height + ResizeButtonPos.y) * drawInfo.InvertedZoom;
                m_resizeRightIconCoords.width  = m_resizeIconTex.width * drawInfo.InvertedZoom;
                m_resizeRightIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;

                EditorGUIUtility.AddCursorRect(m_resizeRightIconCoords, MouseCursor.ResizeUpLeft);
                if (GUI.RepeatButton(m_resizeRightIconCoords, string.Empty, UIUtils.GetCustomStyle(CustomStyle.CommentaryResizeButton)))
                {
                    if (!m_isResizingRight && !m_isResizingLeft)
                    {
                        m_isResizingRight = true;
                        ContainerGraph.ParentWindow.ForceAutoPanDir = true;
                        m_resizeStartPoint = drawInfo.TransformedMousePos;
                        ContainerGraph.MarkToDeselect();
                        ContainerGraph.MarkToSelect(UniqueId);
                    }
                }

                if (m_isResizingRight)
                {
                    if (drawInfo.CurrentEventType == EventType.MouseUp)
                    {
                        m_isResizingRight = false;
                        ContainerGraph.ParentWindow.ForceAutoPanDir = false;
                        RemoveAllNodes();
                        FireStoppedMovingEvent(false, InteractionMode.Target);
                    }
                    else
                    {
                        Vector2 currSize = (drawInfo.TransformedMousePos - m_resizeStartPoint) / drawInfo.InvertedZoom;
                        m_resizeStartPoint = drawInfo.TransformedMousePos;
                        if (m_resizeAxis != eResizeAxis.Y_AXIS)
                        {
                            m_position.width += currSize.x;
                            if (m_position.width < MIN_SIZE_X)
                            {
                                m_position.width = MIN_SIZE_X;
                            }
                        }

                        if (m_resizeAxis != eResizeAxis.X_AXIS)
                        {
                            m_position.height += currSize.y;
                            if (m_position.height < MIN_SIZE_Y)
                            {
                                m_position.height = MIN_SIZE_Y;
                            }
                        }
                    }
                }


                /// LEFT RESIZE BUTTON
                m_resizeLeftIconCoords        = m_globalPosition;
                m_resizeLeftIconCoords.x      = m_globalPosition.x + 2;
                m_resizeLeftIconCoords.y      = m_globalPosition.y + m_globalPosition.height - 2 - (m_resizeIconTex.height + ResizeButtonPos.y) * drawInfo.InvertedZoom;
                m_resizeLeftIconCoords.width  = m_resizeIconTex.width * drawInfo.InvertedZoom;
                m_resizeLeftIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;

                EditorGUIUtility.AddCursorRect(m_resizeLeftIconCoords, MouseCursor.ResizeUpRight);
                if (GUI.RepeatButton(m_resizeLeftIconCoords, string.Empty, UIUtils.GetCustomStyle(CustomStyle.CommentaryResizeButtonInv)))
                {
                    if (!m_isResizingRight && !m_isResizingLeft)
                    {
                        m_isResizingLeft = true;
                        ContainerGraph.ParentWindow.ForceAutoPanDir = true;
                        m_resizeStartPoint = drawInfo.TransformedMousePos;
                        ContainerGraph.MarkToDeselect();
                        ContainerGraph.MarkToSelect(UniqueId);
                    }
                }

                if (m_isResizingLeft)
                {
                    if (drawInfo.CurrentEventType == EventType.MouseUp)
                    {
                        m_isResizingLeft = false;
                        ContainerGraph.ParentWindow.ForceAutoPanDir = false;
                        RemoveAllNodes();
                        FireStoppedMovingEvent(false, InteractionMode.Target);
                    }
                    else
                    {
                        Vector2 currSize = (drawInfo.TransformedMousePos - m_resizeStartPoint) / drawInfo.InvertedZoom;
                        m_resizeStartPoint = drawInfo.TransformedMousePos;
                        if (m_resizeAxis != eResizeAxis.Y_AXIS)
                        {
                            m_position.x     += currSize.x;
                            m_position.width -= currSize.x;
                            if (m_position.width < MIN_SIZE_X)
                            {
                                m_position.x    -= (MIN_SIZE_X - m_position.width);
                                m_position.width = MIN_SIZE_X;
                            }
                        }

                        if (m_resizeAxis != eResizeAxis.X_AXIS)
                        {
                            m_position.height += currSize.y;
                            if (m_position.height < MIN_SIZE_Y)
                            {
                                m_position.height = MIN_SIZE_Y;
                            }
                        }
                    }
                }
                GUI.color = bufferedColor;

                if (m_checkCommentText)
                {
                    m_checkCommentText = false;
                    m_commentText      = m_commentText.Replace(IOUtils.FIELD_SEPARATOR, ' ');
                }

                if (m_checkTitleText)
                {
                    m_checkTitleText = false;
                    m_titleText      = m_titleText.Replace(IOUtils.FIELD_SEPARATOR, ' ');
                }
            }
        }
Exemplo n.º 24
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(m_outputPorts[0].LocalValue);
            }

            //TEMPLATES
            if (dataCollector.IsTemplate)
            {
                if (!dataCollector.IsFragmentCategory)
                {
                    return(m_inputPorts[0].GeneratePortInstructions(ref dataCollector));
                }

                string varName = "vertexToFrag" + OutputId;
                if (dataCollector.TemplateDataCollectorInstance.HasCustomInterpolatedData(varName))
                {
                    return(varName);
                }

                MasterNodePortCategory category = dataCollector.PortCategory;
                dataCollector.PortCategory = MasterNodePortCategory.Vertex;
                string data = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                dataCollector.PortCategory = category;

                dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData(varName, m_inputPorts[0].DataType, m_currentPrecisionType, data);
                //return varName;

                m_outputPorts[0].SetLocalValue(varName);
                return(m_outputPorts[0].LocalValue);
            }


            //SURFACE

            if (!dataCollector.IsFragmentCategory)
            {
                return(m_inputPorts[0].GeneratePortInstructions(ref dataCollector));
            }

            if (dataCollector.TesselationActive)
            {
                UIUtils.ShowMessage("Unable to use Vertex to Frag when Tessellation is active");
                return(m_outputPorts[0].ErrorValue);
            }


            string interpName = "data" + OutputId;

            dataCollector.AddToInput(UniqueId, interpName, m_inputPorts[0].DataType, m_currentPrecisionType);

            MasterNodePortCategory portCategory = dataCollector.PortCategory;

            dataCollector.PortCategory = MasterNodePortCategory.Vertex;

            bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;

            ContainerGraph.ResetNodesLocalVariablesIfNot(this, MasterNodePortCategory.Vertex);

            string vertexVarValue = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);

            dataCollector.AddLocalVariable(UniqueId, Constants.VertexShaderOutputStr + "." + interpName, vertexVarValue + ";");

            dataCollector.PortCategory = portCategory;

            if (!dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables)
            {
                dataCollector.AddVertexInstruction(dataCollector.VertexLocalVariables, UniqueId, false);
                dataCollector.ClearVertexLocalVariables();
                ContainerGraph.ResetNodesLocalVariablesIfNot(this, MasterNodePortCategory.Vertex);
            }

            ContainerGraph.ResetNodesLocalVariablesIfNot(this, MasterNodePortCategory.Fragment);

            //return Constants.InputVarStr + "." + interpName;

            m_outputPorts[0].SetLocalValue(Constants.InputVarStr + "." + interpName);
            return(m_outputPorts[0].LocalValue);
        }
Exemplo n.º 25
0
 public override void Destroy()
 {
     ContainerGraph.RemoveNormalDependentCount();
     base.Destroy();
 }
Exemplo n.º 26
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                UIUtils.ShowMessage(m_nodeAttribs.Name + " cannot be used on Master Node Tessellation port");
                return("-1");
            }

            bool isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation);

            string portProperty = string.Empty;

            if (m_texPort.IsConnected)
            {
                portProperty = m_texPort.GenerateShaderForOutput(ref dataCollector, m_texPort.DataType, ignoreLocalVar);
            }

            if (m_referenceArrayId > -1)
            {
                TexturePropertyNode temp = UIUtils.GetTexturePropertyNode(m_referenceArrayId);
                if (temp != null)
                {
                    portProperty = temp.BaseGenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
                }
            }

            //TEMPLATES
            if (dataCollector.MasterNodeCategory == AvailableShaderTypes.Template)
            {
                if (m_outputPorts[0].IsLocalValue)
                {
                    return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
                }

                string uvName = string.Empty;
                if (dataCollector.TemplateDataCollectorInstance.HasUV(m_textureCoordChannel))
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.GetUVName(m_textureCoordChannel);
                }
                else
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV(m_textureCoordChannel);
                    //string uvName = TemplateHelperFunctions.GenerateTextureSemantic( ref dataCollector, m_textureCoordChannel );
                    //uvName = ( dataCollector.IsFragmentCategory ? Constants.InputVarStr : Constants.VertexShaderInputStr ) + "." + uvName;
                }
                string currPropertyName = GetValidPropertyName();
                if (!string.IsNullOrEmpty(portProperty) && portProperty != "0.0")
                {
                    currPropertyName = portProperty;
                }
                if (!string.IsNullOrEmpty(currPropertyName))
                {
                    string finalTexCoordName      = "uv" + currPropertyName;
                    string dummyPropertyTexcoords = currPropertyName + "_ST";
                    dataCollector.AddToUniforms(UniqueId, "float4", dummyPropertyTexcoords);

                    if (m_texcoordSize > 2)
                    {
                        dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, m_outputPorts[0].DataType, finalTexCoordName, uvName);
                        dataCollector.AddLocalVariable(UniqueId, finalTexCoordName + ".xy", string.Format(Constants.TilingOffsetFormat, uvName + ".xy", dummyPropertyTexcoords + ".xy", dummyPropertyTexcoords + ".zw") + ";");
                        m_outputPorts[0].SetLocalValue(finalTexCoordName);
                    }
                    else
                    {
                        RegisterLocalVariable(0, string.Format(Constants.TilingOffsetFormat, uvName, dummyPropertyTexcoords + ".xy", dummyPropertyTexcoords + ".zw"), ref dataCollector, finalTexCoordName);
                    }
                    //RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, dummyPropertyTexcoords+".xy", dummyPropertyTexcoords+".zw" ), ref dataCollector, finalTexCoordName );
                }
                else
                {
                    string finalTexCoordName = "uv" + OutputId;
                    string tiling            = m_tilingPort.GeneratePortInstructions(ref dataCollector);
                    string offset            = m_offsetPort.GeneratePortInstructions(ref dataCollector);

                    if (m_texcoordSize > 2)
                    {
                        dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, m_outputPorts[0].DataType, finalTexCoordName, uvName);
                        dataCollector.AddLocalVariable(UniqueId, finalTexCoordName + ".xy", string.Format(Constants.TilingOffsetFormat, uvName + ".xy", tiling, offset) + ";");
                        m_outputPorts[0].SetLocalValue(finalTexCoordName);
                    }
                    else
                    {
                        RegisterLocalVariable(0, string.Format(Constants.TilingOffsetFormat, uvName, tiling, offset), ref dataCollector, finalTexCoordName);
                    }
                    //RegisterLocalVariable( 0, string.Format( Constants.TilingOffsetFormat, uvName, tiling, offset ), ref dataCollector, finalTexCoordName );
                }
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
            }

            //SURFACE
            string propertyName = GetValidPropertyName();

            if (!string.IsNullOrEmpty(portProperty) && portProperty != "0.0")
            {
                propertyName = portProperty;
            }

            if (!string.IsNullOrEmpty(propertyName) /*m_referenceArrayId > -1*/)
            {
                //m_referenceNode = UIUtils.GetTexturePropertyNode( m_referenceArrayId );
                //if ( m_referenceNode != null )
                //{
                //string propertyName = m_referenceNode.PropertyName;
                int    coordSet = ((m_textureCoordChannel < 0) ? 0 : m_textureCoordChannel);
                string uvName   = string.Empty;

                string dummyPropUV = "_tex" + (m_texcoordSize > 2 ? "" + m_texcoordSize : "") + "coord" + (coordSet > 0 ? (coordSet + 1).ToString() : "");
                string dummyUV     = "uv" + (coordSet > 0 ? (coordSet + 1).ToString() : "") + dummyPropUV;

                if (isVertex)
                {
                    uvName = IOUtils.GetUVChannelName(propertyName, coordSet) + m_texcoordSize.ToString() + coordSet.ToString();
                    string vertexInput = Constants.VertexShaderInputStr + ".texcoord";
                    if (coordSet > 0)
                    {
                        vertexInput += coordSet.ToString();
                    }

                    dataCollector.AddToVertexLocalVariables(UniqueId, "float" + m_texcoordSize + " " + uvName + " = " + vertexInput + ";");
                    dataCollector.AddToVertexLocalVariables(UniqueId, uvName + ".xy = " + vertexInput + ".xy * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw;");
                }
                else
                {
                    uvName = IOUtils.GetUVChannelName(propertyName, coordSet);
                    if (m_texcoordSize > 2)
                    {
                        uvName += m_texcoordSize;
                        dataCollector.UsingHigherSizeTexcoords = true;
                        dataCollector.AddToLocalVariables(UniqueId, "float" + m_texcoordSize + " " + uvName + " = " + Constants.InputVarStr + "." + dummyUV + ";");
                        dataCollector.AddToLocalVariables(UniqueId, uvName + ".xy = " + Constants.InputVarStr + "." + dummyUV + ".xy * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw;");
                    }
                    else
                    {
                        dataCollector.AddToLocalVariables(UniqueId, PrecisionType.Float, WirePortDataType.FLOAT2, uvName, Constants.InputVarStr + "." + dummyUV + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw");
                    }
                }

                dataCollector.AddToUniforms(UniqueId, "uniform float4 " + propertyName + "_ST;");
                dataCollector.AddToProperties(UniqueId, "[HideInInspector] " + dummyPropUV + "( \"\", 2D ) = \"white\" {}", 100);
                dataCollector.AddToInput(UniqueId, "float" + m_texcoordSize + " " + dummyUV, true);

                return(GetOutputVectorItem(0, outputId, uvName));
                //}
            }

            if (m_texcoordId < 0)
            {
                if (!isVertex && dataCollector.TesselationActive)
                {
                    return(GenerateFragShaderForOutput(outputId, ref dataCollector, ignoreLocalVar));
                }

                bool tessVertexMode = isVertex && dataCollector.TesselationActive;

                m_texcoordId = dataCollector.AvailableUvIndex;
                string texcoordName = TexCoordStr + m_texcoordId;



                string uvChannel = m_textureCoordChannel == 0 ? ".xy" : m_textureCoordChannel + ".xy";

                MasterNodePortCategory portCategory = dataCollector.PortCategory;
                if (dataCollector.PortCategory != MasterNodePortCategory.Vertex && dataCollector.PortCategory != MasterNodePortCategory.Tessellation)
                {
                    dataCollector.PortCategory = MasterNodePortCategory.Vertex;
                }

                // We need to reset local variables if there are already created to force them to be created in the vertex function
                int buffer = m_texcoordId;
                ContainerGraph.ResetNodesLocalVariablesIfNot(this, MasterNodePortCategory.Vertex);

                bool dirtySpecialVarsBefore = dataCollector.DirtySpecialLocalVariables;
                bool dirtyVertexVarsBefore  = dataCollector.DirtyVertexVariables;

                string tiling = m_tilingPort.GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT2, false, true);
                string offset = m_offsetPort.GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT2, false, true);
                dataCollector.PortCategory = portCategory;

                string vertexUV = Constants.VertexShaderInputStr + ".texcoord" + uvChannel;

                if (!tessVertexMode)
                {
                    dataCollector.AddToInput(UniqueId, "float" + m_texcoordSize + " " + texcoordName, true);
                }

                bool resetLocals = false;
                // new texture coordinates are calculated on the vertex shader so we need to register its local vars
                if (!dirtySpecialVarsBefore && dataCollector.DirtySpecialLocalVariables)
                {
                    dataCollector.AddVertexInstruction(dataCollector.SpecialLocalVariables, UniqueId, false);
                    dataCollector.ClearSpecialLocalVariables();
                    resetLocals = true;
                }

                if (!dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables)
                {
                    dataCollector.AddVertexInstruction(dataCollector.VertexLocalVariables, UniqueId, false);
                    dataCollector.ClearVertexLocalVariables();
                    resetLocals = true;
                }

                //Reset local variables again so they wont be caught on the fragment shader
                if (resetLocals)
                {
                    ContainerGraph.ResetNodesLocalVariablesIfNot(this, MasterNodePortCategory.Vertex);
                }

                if (tessVertexMode)
                {
                    dataCollector.AddToVertexLocalVariables(UniqueId, vertexUV + " = " + vertexUV + " * " + tiling + " + " + offset + ";");
                    m_surfaceTexcoordName = Constants.VertexShaderInputStr + "." + IOUtils.GetVertexUVChannelName(m_textureCoordChannel) + ".xy";
                }
                else
                {
                    if (dataCollector.TesselationActive)
                    {
                        if (isVertex)
                        {
                            dataCollector.AddToVertexLocalVariables(UniqueId, vertexUV + " = " + vertexUV + " * " + tiling + " + " + offset + ";");
                            m_surfaceTexcoordName = Constants.VertexShaderOutputStr + "." + texcoordName;
                        }
                        else
                        {
                            string texCoordPrefix = (m_textureCoordChannel == 0) ? string.Empty : (m_textureCoordChannel + 1).ToString();

                            dataCollector.AddToProperties(UniqueId, string.Format(DummyPropertyDec, texCoordPrefix) + " {}", -1);
                            dataCollector.AddToUniforms(UniqueId, string.Format(DummyUniformDec, texCoordPrefix));

                            dataCollector.AddToInput(UniqueId, "float2 " + string.Format(DummyTexCoordDef, texCoordPrefix), true);
                            dataCollector.AddToSpecialLocalVariables(UniqueId, string.Format(DummyTexCoordSurfDef, OutputId, Constants.InputVarStr, texCoordPrefix, tiling, offset));
                            m_surfaceTexcoordName = string.Format(DummyTexCoordSurfVar, OutputId);
                        }
                    }
                    else
                    {
                        dataCollector.AddToVertexLocalVariables(UniqueId, Constants.VertexShaderOutputStr + "." + texcoordName + ".xy = " + vertexUV + " * " + tiling + " + " + offset + ";");
                        m_surfaceTexcoordName = (isVertex ? Constants.VertexShaderOutputStr : Constants.InputVarStr) + "." + texcoordName;
                    }
                }

                m_texcoordId = buffer;
            }

            return(GetOutputVectorItem(0, outputId, m_surfaceTexcoordName));
        }
Exemplo n.º 27
0
 public virtual Shader Execute(string pathname, bool isFullPath)
 {
     ContainerGraph.ResetNodesLocalVariables();
     return(null);
 }
Exemplo n.º 28
0
        public override Shader Execute(string pathname, bool isFullPath)
        {
            if (m_currentTemplate == null)
            {
                return(m_currentShader);
            }

            //Create data collector
            ForceReordering();
            base.Execute(pathname, isFullPath);

            SetupNodeCategories();

            m_currentDataCollector.TemplateDataCollectorInstance.BuildFromTemplateData(m_currentDataCollector, m_currentTemplate);
            int shaderPropertiesAmount = m_currentTemplate.AvailableShaderProperties.Count;

            for (int i = 0; i < shaderPropertiesAmount; i++)
            {
                m_currentDataCollector.SoftRegisterUniform(m_currentTemplate.AvailableShaderProperties[i]);
            }
            m_containerGraph.CheckPropertiesAutoRegister(ref m_currentDataCollector);

            //Sort ports by both
            List <InputPort> fragmentPorts = new List <InputPort>();
            List <InputPort> vertexPorts   = new List <InputPort>();

            SortInputPorts(ref vertexPorts, ref fragmentPorts);

            string shaderBody = m_currentTemplate.TemplateBody;

            List <string> vertexInstructions   = new List <string>();
            List <string> fragmentInstructions = new List <string>();

            bool validBody = true;

            validBody = CreateInstructionsForList(ref fragmentPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions) && validBody;
            ContainerGraph.ResetNodesLocalVariablesIfNot(MasterNodePortCategory.Vertex);
            validBody = CreateInstructionsForList(ref vertexPorts, ref shaderBody, ref vertexInstructions, ref fragmentInstructions) && validBody;

            m_currentTemplate.ResetTemplateUsageData();

            // Fill vertex interpolators assignment
            for (int i = 0; i < m_currentDataCollector.VertexInterpDeclList.Count; i++)
            {
                vertexInstructions.Add(m_currentDataCollector.VertexInterpDeclList[i]);
            }

            vertexInstructions.AddRange(m_currentDataCollector.TemplateDataCollectorInstance.GetInterpUnusedChannels());
            //Fill common local variables and operations

            validBody = m_currentTemplate.FillVertexInstructions(ref shaderBody, vertexInstructions.ToArray()) && validBody;
            validBody = m_currentTemplate.FillFragmentInstructions(ref shaderBody, fragmentInstructions.ToArray()) && validBody;

            // Add Instanced Properties
            if (m_containerGraph.IsInstancedShader)
            {
                m_currentDataCollector.TabifyInstancedVars();
                m_currentDataCollector.InstancedPropertiesList.Insert(0, new PropertyDataCollector(-1, string.Format(IOUtils.InstancedPropertiesBegin, UIUtils.RemoveInvalidCharacters(m_shaderName))));
                m_currentDataCollector.InstancedPropertiesList.Add(new PropertyDataCollector(-1, IOUtils.InstancedPropertiesEnd));
                m_currentDataCollector.UniformsList.AddRange(m_currentDataCollector.InstancedPropertiesList);
            }

            //Add Functions
            m_currentDataCollector.UniformsList.AddRange(m_currentDataCollector.FunctionsList);

            // Fill common tags
            m_currentDataCollector.IncludesList.AddRange(m_currentDataCollector.PragmasList);

            validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.ShaderNameId, ref shaderBody, string.Format(TemplatesManager.NameFormatter, m_shaderName)) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplatePassTag, ref shaderBody, m_currentDataCollector.GrabPassList) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplatePragmaTag, ref shaderBody, m_currentDataCollector.IncludesList) && validBody;
            //validBody = m_currentTemplate.FillTemplateBody( TemplatesManager.TemplateTagsTag, ref shaderBody, m_currentDataCollector.TagsList ) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplatePropertyTag, ref shaderBody, m_currentDataCollector.BuildUnformatedPropertiesStringArr()) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplateGlobalsTag, ref shaderBody, m_currentDataCollector.UniformsList) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.VertexDataId, ref shaderBody, m_currentDataCollector.VertexInputList.ToArray()) && validBody;
            validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.InterpDataId, ref shaderBody, m_currentDataCollector.InterpolatorList.ToArray()) && validBody;

            if (m_currentTemplate.BlendData.ValidBlendMode)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.BlendData.BlendModeId, ref shaderBody, m_blendOpHelper.CurrentBlendFactor) && validBody;
            }

            if (m_currentTemplate.BlendData.ValidBlendOp)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.BlendData.BlendOpId, ref shaderBody, m_blendOpHelper.CurrentBlendOp) && validBody;
            }

            if (m_currentTemplate.DepthData.ValidZWrite)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.DepthData.ZWriteModeId, ref shaderBody, m_depthOphelper.CurrentZWriteMode) && validBody;
            }

            if (m_currentTemplate.DepthData.ValidZTest)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.DepthData.ZTestModeId, ref shaderBody, m_depthOphelper.CurrentZTestMode) && validBody;
            }

            if (m_currentTemplate.DepthData.ValidOffset)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.DepthData.OffsetId, ref shaderBody, m_depthOphelper.CurrentOffset) && validBody;
            }

            if (m_currentTemplate.CullModeData.DataCheck == TemplateDataCheck.Valid)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.CullModeData.CullModeId, ref shaderBody, m_cullModeHelper.GenerateShaderData(false)) && validBody;
            }

            if (m_currentTemplate.ColorMaskData.DataCheck == TemplateDataCheck.Valid)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.ColorMaskData.ColorMaskId, ref shaderBody, m_colorMaskHelper.GenerateShaderData(false)) && validBody;
            }

            if (m_currentTemplate.StencilData.DataCheck == TemplateDataCheck.Valid)
            {
                CullMode cullMode = (m_currentTemplate.CullModeData.DataCheck == TemplateDataCheck.Valid) ? m_cullModeHelper.CurrentCullMode : CullMode.Back;
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.StencilData.StencilBufferId, ref shaderBody, m_stencilBufferHelper.CreateStencilOp(cullMode)) && validBody;
            }

            if (m_currentTemplate.TagData.DataCheck == TemplateDataCheck.Valid)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.TagData.TagsId, ref shaderBody, m_tagsHelper.GenerateTags()) && validBody;
            }

            if (m_currentDataCollector.TemplateDataCollectorInstance.HasVertexInputParams)
            {
                validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplateInputsVertParamsTag, ref shaderBody, m_currentDataCollector.TemplateDataCollectorInstance.VertexInputParamsStr) && validBody;
            }

            if (m_currentDataCollector.TemplateDataCollectorInstance.HasFragmentInputParams)
            {
                validBody = m_currentTemplate.FillTemplateBody(TemplatesManager.TemplateInputsFragParamsTag, ref shaderBody, m_currentDataCollector.TemplateDataCollectorInstance.FragInputParamsStr) && validBody;
            }

            m_currentTemplate.FillEmptyTags(ref shaderBody);

            //m_currentTemplate.InsertSnippets( ref shaderBody );

            vertexInstructions.Clear();
            vertexInstructions = null;

            fragmentInstructions.Clear();
            fragmentInstructions = null;
            if (validBody)
            {
                UpdateShaderAsset(ref pathname, ref shaderBody, isFullPath);
            }

            return(m_currentShader);
        }
Exemplo n.º 29
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsFragmentCategory)
            {
                UIUtils.ShowMessage(ErrorMessage);
                return("0");
            }
            if (m_outputPorts[0].IsLocalValue)
            {
                return("0");
            }

            m_outputPorts[0].SetLocalValue("0");

            MasterNodeDataCollector outlineDataCollector = new MasterNodeDataCollector();

            outlineDataCollector.IsOutlineDataCollector = true;
            if (m_inputPorts[1].IsConnected)
            {
                outlineDataCollector.PortCategory = MasterNodePortCategory.Vertex;
                string outlineWidth = m_inputPorts[1].GenerateShaderForOutput(ref outlineDataCollector, m_inputPorts[1].DataType, true, true);
                outlineDataCollector.AddToVertexLocalVariables(UniqueId, PrecisionType.Float, m_inputPorts[1].DataType, "outlineVar", outlineWidth);

                outlineDataCollector.AddVertexInstruction(outlineDataCollector.SpecialLocalVariables, UniqueId, false);
                outlineDataCollector.ClearSpecialLocalVariables();

                outlineDataCollector.AddVertexInstruction(outlineDataCollector.VertexLocalVariables, UniqueId, false);
                outlineDataCollector.ClearVertexLocalVariables();

                // need to check whether this breaks other outputs or not
                ContainerGraph.ResetNodesLocalVariables();
            }

            outlineDataCollector.PortCategory = MasterNodePortCategory.Fragment;
            string outlineColor = m_inputPorts[0].GeneratePortInstructions(ref outlineDataCollector);                // "\to.Emission = " + m_inputPorts[ 0 ].GeneratePortInstructions( ref outlineDataCollector ) + ";";

            bool addTabs = outlineDataCollector.DirtySpecialLocalVariables;

            outlineDataCollector.AddInstructions("\t" + outlineDataCollector.SpecialLocalVariables.TrimStart('\t'));
            outlineDataCollector.ClearSpecialLocalVariables();
            outlineDataCollector.AddInstructions((addTabs ? "\t\t\t" : "") + "o.Emission = " + outlineColor + ";");

            if (dataCollector.UsingWorldNormal)
            {
                outlineDataCollector.AddInstructions((addTabs ? "\n\t\t\t" : "") + "o.Normal = float3(0,0,-1);");
            }

            ContainerGraph.CurrentStandardSurface.OutlineHelper.InputList    = outlineDataCollector.InputList;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Inputs       = outlineDataCollector.Inputs;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.DirtyInput   = outlineDataCollector.DirtyInputs;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Pragmas      = outlineDataCollector.Pragmas;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Uniforms     = outlineDataCollector.Uniforms;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.UniformList  = outlineDataCollector.UniformsList;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.VertexData   = outlineDataCollector.VertexData;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Instructions = outlineDataCollector.Instructions;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.Functions    = outlineDataCollector.Functions;

            ContainerGraph.CurrentStandardSurface.OutlineHelper.OffsetMode  = m_currentSelectedMode;
            ContainerGraph.CurrentStandardSurface.OutlineHelper.CustomNoFog = m_noFog;

            for (int i = 0; i < outlineDataCollector.PropertiesList.Count; i++)
            {
                dataCollector.AddToProperties(UniqueId, outlineDataCollector.PropertiesList[i].PropertyName, outlineDataCollector.PropertiesList[i].OrderIndex);
            }

            return("0");
        }
Exemplo n.º 30
0
 public virtual void SetupNodeCategories()
 {
     ContainerGraph.ResetNodesData();
 }