Beispiel #1
0
        public override Shader Execute(string pathname, bool isFullPath)
        {
            if (m_currentTemplate == null)
            {
                return(m_currentShader);
            }

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

            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].PropertyName);
            }

            //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;
            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 TEMPLATE_MODULES
            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.CullModeData.DataCheck == TemplateDataCheck.Valid)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.CullModeData.CullModeId, ref shaderBody, m_cullModeHelper.GenerateShaderData()) && validBody;
            }

            if (m_currentTemplate.ColorMaskData.DataCheck == TemplateDataCheck.Valid)
            {
                validBody = m_currentTemplate.FillTemplateBody(m_currentTemplate.ColorMaskData.ColorMaskId, ref shaderBody, m_colorMaskHelper.GenerateShaderData()) && 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;
            }
#endif
            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);
        }
Beispiel #2
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.BlendData.ValidAlphaToMask )
			{
				validBody = m_currentTemplate.FillTemplateBody( m_currentTemplate.BlendData.AlphaToMaskId, ref shaderBody, m_blendOpHelper.CurrentAlphaToMask ) && 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:
		}