Beispiel #1
0
        public override void DrawProperties()
        {
            base.DrawProperties();
            NodeUtils.DrawPropertyGroup(ref m_propertiesFoldout, Constants.ParameterLabelStr, () =>
            {
                EditorGUI.BeginChangeCheck();
                m_currentSelectedMode = EditorGUILayoutIntPopup("Type", m_currentSelectedMode, AvailableOutlineModes, AvailableOutlineValues);
                if (EditorGUI.EndChangeCheck())
                {
                    SetAdditonalTitleText(string.Format(Constants.SubTitleTypeFormatStr, AvailableOutlineModes[m_currentSelectedMode]));
                    UpdatePorts();
                }

                EditorGUI.BeginChangeCheck();
                m_currentAlphaMode = (OutlineAlphaModes)EditorGUILayoutEnumPopup(OutlineAlphaModeStr, m_currentAlphaMode);
                if (EditorGUI.EndChangeCheck())
                {
                    CheckAlphaPortVisibility();
                }

                if (m_currentAlphaMode == OutlineAlphaModes.Masked)
                {
                    if (m_masterNode == null)
                    {
                        m_masterNode = m_containerGraph.CurrentMasterNode as StandardSurfaceOutputNode;
                    }

                    if (m_masterNode != null)
                    {
                        m_masterNode.ShowOpacityMaskValueUI();
                    }
                }
                m_noFog = EditorGUILayoutToggle("No Fog", m_noFog);
            });
        }
        public void Draw(StandardSurfaceOutputNode owner)
        {
            bool value = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedRenderingOptions;

            NodeUtils.DrawPropertyGroup(ref value, RenderingOptionsStr, () =>
            {
                int codeGenCount = m_codeGenerationDataList.Count;
                // Starting from index 4 because other options are already contemplated with m_renderPath and add/receive shadows
                for (int i = 4; i < codeGenCount; i++)
                {
                    m_codeGenerationDataList[i].IsActive = !owner.EditorGUILayoutToggleLeft(m_codeGenerationDataList[i].Name, !m_codeGenerationDataList[i].IsActive);
                }
                m_lodCrossfade    = owner.EditorGUILayoutToggleLeft(LODCrossfadeContent, m_lodCrossfade);
                m_ignoreProjector = owner.EditorGUILayoutToggleLeft(IgnoreProjectorContent, m_ignoreProjector);
                EditorGUI.BeginDisabledGroup(!owner.CastShadows);
                m_useDefaultShadowCaster = owner.EditorGUILayoutToggleLeft(UseDefaultCasterContent, m_useDefaultShadowCaster);
                EditorGUI.EndDisabledGroup();
                m_forceNoShadowCasting = owner.EditorGUILayoutToggleLeft(ForceNoShadowCastingContent, m_forceNoShadowCasting);
                if (owner.ContainerGraph.IsInstancedShader)
                {
                    GUI.enabled = false;
                    owner.EditorGUILayoutToggleLeft(ForceEnableInstancingContent, true);
                    GUI.enabled = true;
                }
                else
                {
                    m_forceEnableInstancing = owner.EditorGUILayoutToggleLeft(ForceEnableInstancingContent, m_forceEnableInstancing);
                }

#if UNITY_5_6_OR_NEWER
                m_forceDisableInstancing = owner.EditorGUILayoutToggleLeft(ForceDisableInstancingContent, m_forceDisableInstancing);
#endif
                m_specularHighlightToggle = owner.EditorGUILayoutToggleLeft(SpecularHightlightsContent, m_specularHighlightToggle);
                m_reflectionsToggle       = owner.EditorGUILayoutToggleLeft(ReflectionsContent, m_reflectionsToggle);
                m_disableBatching         = (DisableBatchingTagValues)owner.EditorGUILayoutEnumPopup(DisableBatchingContent, m_disableBatching);
                Material mat = owner.ContainerGraph.CurrentMaterial;
                if (mat != null)
                {
                    mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)owner.EditorGUILayoutEnumPopup(EmissionGIFlags, mat.globalIlluminationFlags);
                }
            });
            owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedRenderingOptions = value;
        }
Beispiel #3
0
		public override void OnMasterNodeReplaced( MasterNode newMasterNode )
		{
			base.OnMasterNodeReplaced( newMasterNode ):
			m_functionGraph.FireMasterNodeReplacedEvent( newMasterNode ):

			StandardSurfaceOutputNode surface = newMasterNode as StandardSurfaceOutputNode:
			if( surface != null )
			{
				surface.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ):
			}
			else
			{
				if( ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0 )
				{
					List<TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList:
					int count = nodes.Count:
					for( int i = 0: i < count: i++ )
					{
						nodes[ i ].PassModule.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList ):
					}
				}
			}
		}
Beispiel #4
0
        public override void RefreshExternalReferences()
        {
            base.RefreshExternalReferences();
            if (Function == null)
            {
                return;
            }

            //Debug.Log( "RefreshExternalReferences " + m_function.FunctionName + " " + UIUtils.CurrentWindow.IsShaderFunctionWindow );

            Function.UpdateDirectivesList();

            MasterNode masterNode             = UIUtils.CurrentWindow.OutsideGraph.CurrentMasterNode;
            StandardSurfaceOutputNode surface = masterNode as StandardSurfaceOutputNode;

            if (surface != null)
            {
                //for( int i = 0; i < Function.AdditionalIncludes.IncludeList.Count; i++ )
                //{
                //	//ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Add( Function.AdditionalIncludes.IncludeList[ i ] );
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem( AdditionalLineType.Include, Function.AdditionalIncludes.IncludeList[ i ] );
                //	m_includes.Add( Function.AdditionalIncludes.IncludeList[ i ] );
                //}

                //for( int i = 0; i < Function.AdditionalPragmas.PragmaList.Count; i++ )
                //{
                //	//ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Add( Function.AdditionalPragmas.PragmaList[ i ] );
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem(AdditionalLineType.Pragma, Function.AdditionalPragmas.PragmaList[ i ] );
                //	m_pragmas.Add( Function.AdditionalPragmas.PragmaList[ i ] );
                //}
                surface.AdditionalDirectives.AddShaderFunctionItems(Function.AdditionalDirectives.DirectivesList);
            }
            else
            {
                if (ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0)
                {
                    List <TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList;
                    int count = nodes.Count;
                    for (int i = 0; i < count; i++)
                    {
                        nodes[i].PassModule.AdditionalDirectives.AddShaderFunctionItems(Function.AdditionalDirectives.DirectivesList);
                    }
                }
                else
                {
                    // Assuring that we're not editing a Shader Function, as directives setup is not needed there
                    if (!UIUtils.CurrentWindow.IsShaderFunctionWindow)
                    {
                        // This function is nested inside a shader function itself and this method
                        // was called before the main output node was created.
                        // This is possible since all nodes RefreshExternalReferences(...) are called at the end
                        // of a LoadFromMeta
                        // Need to delay this setup to after all nodes are loaded to then setup the directives
                        m_lateRefresh = true;
                        return;
                    }
                }
            }
            m_directives.AddRange(Function.AdditionalDirectives.DirectivesList);

            if (m_refreshIdsRequired)
            {
                m_refreshIdsRequired = false;
                int inputCount = m_inputPorts.Count;
                for (int i = 0; i < inputCount; i++)
                {
                    m_inputPorts[i].ChangePortId(m_allFunctionInputs[i].UniqueId);
                }

                int outputCount = m_outputPorts.Count;
                for (int i = 0; i < outputCount; i++)
                {
                    m_outputPorts[i].ChangePortId(m_allFunctionOutputs[i].UniqueId);
                }
            }

            if (ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount += m_functionGraph.InstancePropertyCount;
            }

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (ReadOptionsHelper.Length > 2)
            {
                for (int i = 1; i < ReadOptionsHelper.Length; i += 2)
                {
                    int optionId    = Convert.ToInt32(ReadOptionsHelper[i]);
                    int optionValue = Convert.ToInt32(ReadOptionsHelper[i + 1]);
                    for (int j = 0; j < m_allFunctionSwitches.Count; j++)
                    {
                        if (m_allFunctionSwitches[j].UniqueId == optionId)
                        {
                            m_allFunctionSwitches[j].SetCurrentSelectedInput(optionValue, m_allFunctionSwitches[j].GetCurrentSelectedInput());
                            break;
                        }
                    }
                }
            }

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_portsChanged = true;
        }
Beispiel #5
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");
        }
Beispiel #6
0
		public override void RefreshExternalReferences()
		{
			base.RefreshExternalReferences();
			if( Function == null )
				return;

			Function.UpdateDirectivesList();

			MasterNode masterNode = ContainerGraph.ParentWindow.OutsideGraph.CurrentMasterNode;
			StandardSurfaceOutputNode surface = masterNode  as StandardSurfaceOutputNode;

			if( surface != null )
			{
				//for( int i = 0; i < Function.AdditionalIncludes.IncludeList.Count; i++ )
				//{
				//	//ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Add( Function.AdditionalIncludes.IncludeList[ i ] );
				//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem( AdditionalLineType.Include, Function.AdditionalIncludes.IncludeList[ i ] );
				//	m_includes.Add( Function.AdditionalIncludes.IncludeList[ i ] );
				//}

				//for( int i = 0; i < Function.AdditionalPragmas.PragmaList.Count; i++ )
				//{
				//	//ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Add( Function.AdditionalPragmas.PragmaList[ i ] );
				//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.AddShaderFunctionItem(AdditionalLineType.Pragma, Function.AdditionalPragmas.PragmaList[ i ] );
				//	m_pragmas.Add( Function.AdditionalPragmas.PragmaList[ i ] );
				//}
				surface.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList );
			}
			else
			{
				if( ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0 )
				{
					List<TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList;
					int count = nodes.Count;
					for( int i = 0; i < count; i++ )
					{
						nodes[ i ].PassModule.AdditionalDirectives.AddShaderFunctionItems( Function.AdditionalDirectives.DirectivesList );
					}
				}
			}
			m_directives.AddRange( Function.AdditionalDirectives.DirectivesList );

			if( m_refreshIdsRequired )
			{
				m_refreshIdsRequired = false;
				int inputCount = m_inputPorts.Count;
				for( int i = 0; i < inputCount; i++ )
				{
					m_inputPorts[ i ].ChangePortId( m_allFunctionInputs[ i ].UniqueId );
				}

				int outputCount = m_outputPorts.Count;
				for( int i = 0; i < outputCount; i++ )
				{
					m_outputPorts[ i ].ChangePortId( m_allFunctionOutputs[ i ].UniqueId );
				}
			}

			if( ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph )
				ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount += m_functionGraph.InstancePropertyCount;

			ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
			ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

			if( ReadOptionsHelper.Length > 2 )
			{
				for( int i = 1; i < ReadOptionsHelper.Length; i += 2 )
				{
					int optionId = Convert.ToInt32( ReadOptionsHelper[ i ] );
					int optionValue = Convert.ToInt32( ReadOptionsHelper[ i + 1 ] );
					for( int j = 0; j < m_allFunctionSwitches.Count; j++ )
					{
						if( m_allFunctionSwitches[ j ].UniqueId == optionId )
						{
							m_allFunctionSwitches[ j ].SetCurrentSelectedInput( optionValue, m_allFunctionSwitches[ j ].GetCurrentSelectedInput() );
							break;
						}
					}
				}
			}

			ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

			m_portsChanged = true;
		}