示例#1
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                if (!dataCollector.TemplateDataCollectorInstance.HasUV(m_index))
                {
                    dataCollector.TemplateDataCollectorInstance.RegisterUV(m_index, m_outputPorts[0].DataType);
                }

                string result = string.Empty;
                if (dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData(TemplateHelperFunctions.IntToUVChannelInfo[m_index], WirePortDataType.FLOAT4, PrecisionType.Float, ref result, false, dataCollector.PortCategory))
                {
                    if (m_outputPorts[0].DataType != WirePortDataType.FLOAT4)
                    {
                        result += UIUtils.GetAutoSwizzle(m_outputPorts[0].DataType);
                    }
                    return(GetOutputVectorItem(0, outputId, result));
                }
                else
                if (dataCollector.TemplateDataCollectorInstance.HasUV(m_index))
                {
                    InterpDataHelper info = dataCollector.TemplateDataCollectorInstance.GetUVInfo(m_index);
                    if (outputId == 0)
                    {
                        return(dataCollector.TemplateDataCollectorInstance.GetUVName(m_index, m_outputPorts[0].DataType));
                    }
                    else if (outputId <= TemplateHelperFunctions.DataTypeChannelUsage[info.VarType])
                    {
                        return(GetOutputVectorItem(0, outputId, info.VarName));
                    }
                    Debug.LogWarning("Attempting to access inexisting UV channel");
                }
                else
                {
                    Debug.LogWarning("Attempting to access non-registered UV");
                }
                return("0");
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                if (m_texcoordSize > 2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                }
            }

            WirePortDataType size      = (WirePortDataType)(1 << (m_texcoordSize + 1));
            string           texcoords = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_index, null, size);

            return(GetOutputVectorItem(0, outputId, texcoords));
        }
示例#2
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                if (m_texcoordSize > 2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                }
            }

            WirePortDataType size      = ( WirePortDataType )(1 << (m_texcoordSize + 1));
            string           texcoords = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_index, null, size);

            return(GetOutputVectorItem(0, outputId, texcoords));
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                if (dataCollector.TemplateDataCollectorInstance.HasUV(m_index))
                {
                    InterpDataHelper info = dataCollector.TemplateDataCollectorInstance.GetUVInfo(m_index);
                    if (outputId == 0)
                    {
                        return(info.VarName);
                    }
                    else if (outputId <= TemplateHelperFunctions.DataTypeChannelUsage[info.VarType])
                    {
                        return(GetOutputVectorItem(0, outputId, info.VarName));
                    }
                    Debug.LogWarning("Attempting to access inexisting UV channel");
                }
                else
                {
                    Debug.LogWarning("Attempting to access non-registered UV");
                }
                return("0");
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                if (m_texcoordSize > 2)
                {
                    dataCollector.UsingHigherSizeTexcoords = true;
                }
            }

            WirePortDataType size      = ( WirePortDataType )(1 << (m_texcoordSize + 1));
            string           texcoords = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_index, null, size);

            return(GetOutputVectorItem(0, outputId, texcoords));
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                UIUtils.ShowMessage(UniqueId, m_nodeAttribs.Name + " cannot be used on Master Node Tessellation port");
                return("-1");
            }

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

            string tiling = string.Empty;
            string offset = string.Empty;

            string portProperty = string.Empty;

            if (m_texPort.IsConnected)
            {
                portProperty = m_texPort.GeneratePortInstructions(ref dataCollector);
            }
            else 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(dataCollector.PortCategory))
                {
                    return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
                }

                string uvName   = string.Empty;
                string result   = string.Empty;
                string indexStr = m_textureCoordChannel > 0 ? (m_textureCoordChannel + 1).ToString() : "";
                string sizeDif  = string.Empty;
                if (m_texcoordSize == 3)
                {
                    sizeDif = "3";
                }
                else if (m_texcoordSize == 4)
                {
                    sizeDif = "4";
                }

                if (dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData(TemplateHelperFunctions.IntToUVChannelInfo[m_textureCoordChannel], m_outputPorts[0].DataType, PrecisionType.Float, ref result, false, dataCollector.PortCategory))
                {
                    uvName = result;
                }
                else if (dataCollector.TemplateDataCollectorInstance.HasUV(m_textureCoordChannel))
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.GetUVName(m_textureCoordChannel, m_outputPorts[0].DataType);
                }
                else
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV(m_textureCoordChannel, m_outputPorts[0].DataType);
                }
                string currPropertyName = GetValidPropertyName();
                if (!string.IsNullOrEmpty(portProperty) && portProperty != "0.0")
                {
                    currPropertyName = portProperty;
                }
                if (!string.IsNullOrEmpty(currPropertyName))
                {
                    string finalTexCoordName      = "uv" + indexStr + (m_texcoordSize > 2 ? "s" + sizeDif : "") + currPropertyName;
                    string dummyPropertyTexcoords = currPropertyName + "_ST";

                    if (m_texCoordsHelper == null)
                    {
                        m_texCoordsHelper = CreateInstance <Vector4Node>();
                        m_texCoordsHelper.ContainerGraph = ContainerGraph;
                        m_texCoordsHelper.SetBaseUniqueId(UniqueId, true);
                        m_texCoordsHelper.RegisterPropertyOnInstancing = false;
                        m_texCoordsHelper.AddGlobalToSRPBatcher        = true;
                    }

                    if (UIUtils.CurrentWindow.OutsideGraph.IsInstancedShader)
                    {
                        m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty;
                    }
                    else
                    {
                        m_texCoordsHelper.CurrentParameterType = PropertyType.Global;
                    }
                    m_texCoordsHelper.ResetOutputLocals();
                    m_texCoordsHelper.SetRawPropertyName(dummyPropertyTexcoords);
                    dummyPropertyTexcoords = m_texCoordsHelper.GenerateShaderForOutput(0, ref dataCollector, false);

                    if (m_texcoordSize > 2)
                    {
                        dataCollector.AddLocalVariable(UniqueId, 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, dataCollector.PortCategory);
                    }
                    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 = "texCoord" + OutputId;
                    tiling = m_tilingPort.GeneratePortInstructions(ref dataCollector);
                    offset = m_offsetPort.GeneratePortInstructions(ref dataCollector);

                    if (m_texcoordSize > 2)
                    {
                        dataCollector.AddLocalVariable(UniqueId, 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, dataCollector.PortCategory);
                    }
                    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(dataCollector.PortCategory)));
            }

            //SURFACE
            string propertyName = GetValidPropertyName();

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

            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
            }

            if (!m_tilingPort.IsConnected && m_tilingPort.Vector2InternalData == Vector2.one)
            {
                tiling = null;
            }
            else
            {
                tiling = m_tilingPort.GeneratePortInstructions(ref dataCollector);
            }

            if (!m_offsetPort.IsConnected && m_offsetPort.Vector2InternalData == Vector2.zero)
            {
                offset = null;
            }
            else
            {
                offset = m_offsetPort.GeneratePortInstructions(ref dataCollector);
            }

            if (!string.IsNullOrEmpty(propertyName) /*m_referenceArrayId > -1*/)
            {
                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, propertyName, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }
            else
            {
                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, null, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }

            m_outputPorts[0].SetLocalValue(m_surfaceTexcoordName, dataCollector.PortCategory);
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
        }
示例#5
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 tiling = string.Empty;
            string offset = string.Empty;

            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;
                    tiling = m_tilingPort.GeneratePortInstructions(ref dataCollector);
                    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 (m_outputPorts[0].IsLocalValue)
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
            }

            tiling = m_tilingPort.GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT2, false, true);
            offset = m_offsetPort.GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT2, false, true);
            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 );
                ////}

                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, propertyName, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }
            else
            {
                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, null, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }
            //{
            //	if ( !isVertex && dataCollector.TesselationActive )
            //	{
            //		return GenerateFragShaderForOutput( outputId, ref dataCollector, ignoreLocalVar );
            //	}

            //	bool tessVertexMode = isVertex && dataCollector.TesselationActive;

            //	string texcoordName = TexCoordStr + OutputId;

            //	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
            //	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 )
            //	{
            //		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
            //	{
            //		//m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs( ref dataCollector, UniqueId, m_textureCoordChannel, null, m_texcoordSize == 2 ? WirePortDataType.FLOAT2 : WirePortDataType.FLOAT3, tiling, offset, OutputId );
            //		dataCollector.AddToVertexLocalVariables( UniqueId, Constants.VertexShaderOutputStr + "." + texcoordName + ".xy = " + vertexUV + " * " + tiling + " + " + offset + ";" );
            //		m_surfaceTexcoordName = ( isVertex ? Constants.VertexShaderOutputStr : Constants.InputVarStr ) + "." + texcoordName;
            //	}
            //}

            m_outputPorts[0].SetLocalValue(m_surfaceTexcoordName, dataCollector.PortCategory);
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
        }
示例#6
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[outputId].IsLocalValue(dataCollector.PortCategory))
            {
                return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory));
            }

            if (m_useUnity)
            {
                string uvValue     = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                string angleOffset = m_inputPorts[1].GeneratePortInstructions(ref dataCollector);
                string cellDensity = m_inputPorts[2].GeneratePortInstructions(ref dataCollector);
                dataCollector.AddFunction(UnityVoroniNoiseFunctionsBody[0], UnityVoroniNoiseFunctionsBody, false);
                string varName  = "unityVoronoy" + OutputId;
                string varValue = string.Format(UnityVoronoiNoiseFunc, uvValue, angleOffset, cellDensity);
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, varName, varValue);
                m_outputPorts[0].SetLocalValue(varName + ".x", dataCollector.PortCategory);
                m_outputPorts[1].SetLocalValue(varName + ".y", dataCollector.PortCategory);
                return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory));
            }
            else
            {
                string scaleValue = m_inputPorts[2].GeneratePortInstructions(ref dataCollector);

                string timeVarValue = m_inputPorts[1].GeneratePortInstructions(ref dataCollector);
                string timeVarName  = "time" + OutputId;
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, timeVarName, timeVarValue);

                ChangeFunction(scaleValue);

                string voronoiHashFunc            = string.Empty;
                string VoronoiHashHeaderFormatted = string.Format(VoronoiHashHeader, OutputId);
                IOUtils.AddFunctionHeader(ref voronoiHashFunc, VoronoiHashHeaderFormatted);
                for (int i = 0; i < VoronoiHashBody.Length; i++)
                {
                    IOUtils.AddFunctionLine(ref voronoiHashFunc, VoronoiHashBody[i]);
                }
                IOUtils.CloseFunctionBody(ref voronoiHashFunc);
                dataCollector.AddFunction(VoronoiHashHeaderFormatted, voronoiHashFunc);

                string smoothnessName = "0";
                if (m_calculateSmoothValue)
                {
                    smoothnessName = "voronoiSmooth" + outputId;
                    string smoothnessValue = m_inputPorts[3].GeneratePortInstructions(ref dataCollector);
                    dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, smoothnessName, smoothnessValue);
                }

                string voronoiFunc = string.Empty;
                IOUtils.AddFunctionHeader(ref voronoiFunc, string.Format(VoronoiHeader, OutputId));
                for (int i = 0; i < VoronoiBody.Length; i++)
                {
                    if (i == 9)
                    {
                        IOUtils.AddFunctionLine(ref voronoiFunc, string.Format(VoronoiBody[i], OutputId));
                    }
                    else
                    {
                        IOUtils.AddFunctionLine(ref voronoiFunc, VoronoiBody[i]);
                    }
                }
                IOUtils.CloseFunctionBody(ref voronoiFunc);
                dataCollector.AddFunction(string.Format(VoronoiHeader, OutputId), voronoiFunc);

                string uvs = string.Empty;
                if (m_inputPorts[0].IsConnected)
                {
                    uvs = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                }
                else
                {
                    if (dataCollector.IsTemplate)
                    {
                        uvs = dataCollector.TemplateDataCollectorInstance.GenerateAutoUVs(0);
                    }
                    else
                    {
                        uvs = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, 0);
                    }
                }

                dataCollector.AddLocalVariable(UniqueId, string.Format("float2 coords{0} = {1} * {2};", OutputId, uvs, scaleValue));
                dataCollector.AddLocalVariable(UniqueId, string.Format("float2 id{0} = 0;", OutputId));

                if (m_octaves == 1)
                {
                    dataCollector.AddLocalVariable(UniqueId, string.Format("float voroi{0} = {1};", OutputId, string.Format(VoronoiFunc, OutputId, "coords" + OutputId, timeVarName, "id" + OutputId, smoothnessName)));
                }
                else
                {
                    dataCollector.AddLocalVariable(UniqueId, string.Format("float fade{0} = 0.5;", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, string.Format("float voroi{0} = 0;", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, string.Format("float rest{0} = 0;", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, "for( int it = 0; it <" + m_octaves + "; it++ ){");
                    dataCollector.AddLocalVariable(UniqueId, string.Format("voroi{0} += fade{0} * voronoi{0}( coords{0}, time{0}, id{0},{1} );", OutputId, smoothnessName));
                    dataCollector.AddLocalVariable(UniqueId, string.Format("rest{0} += fade{0};", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, string.Format("coords{0} *= 2;", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, string.Format("fade{0} *= 0.5;", OutputId));
                    dataCollector.AddLocalVariable(UniqueId, "}");
                    dataCollector.AddLocalVariable(UniqueId, string.Format("voroi{0} /= rest{0};", OutputId));
                }
                m_outputPorts[0].SetLocalValue("voroi" + OutputId, dataCollector.PortCategory);
                m_outputPorts[1].SetLocalValue("id" + OutputId, dataCollector.PortCategory);
                return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory));
            }
        }
		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 tiling = string.Empty:
			string offset = string.Empty:

			string portProperty = string.Empty:
			if( m_texPort.IsConnected )
				portProperty = m_texPort.GeneratePortInstructions( ref dataCollector ):

			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( dataCollector.PortCategory ) )
					return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):

				string uvName = string.Empty:
				if( dataCollector.TemplateDataCollectorInstance.HasUV( m_textureCoordChannel ) )
				{
					uvName = dataCollector.TemplateDataCollectorInstance.GetUVName( m_textureCoordChannel, m_outputPorts[ 0 ].DataType ):
				}
				else
				{
					uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV( m_textureCoordChannel, m_outputPorts[ 0 ].DataType ):
				}
				string currPropertyName = GetValidPropertyName():
				if( !string.IsNullOrEmpty( portProperty ) && portProperty != "0.0" )
				{
					currPropertyName = portProperty:
				}
				if( !string.IsNullOrEmpty( currPropertyName ) )
				{
					string finalTexCoordName = "uv" + m_textureCoordChannel + currPropertyName:
					string dummyPropertyTexcoords = currPropertyName + "_ST":

					if( m_texCoordsHelper == null )
					{
						m_texCoordsHelper = CreateInstance<Vector4Node>():
						m_texCoordsHelper.ContainerGraph = ContainerGraph:
						m_texCoordsHelper.SetBaseUniqueId( UniqueId, true ):
						m_texCoordsHelper.RegisterPropertyOnInstancing = false:
					}

					if( UIUtils.CurrentWindow.OutsideGraph.IsInstancedShader )
					{
						m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty:
					}
					else
					{
						m_texCoordsHelper.CurrentParameterType = PropertyType.Global:
					}
					m_texCoordsHelper.ResetOutputLocals():
					m_texCoordsHelper.SetRawPropertyName( dummyPropertyTexcoords ):
					dummyPropertyTexcoords = m_texCoordsHelper.GenerateShaderForOutput( 0, ref dataCollector, false ):

					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, dataCollector.PortCategory ):
					}
					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" + m_textureCoordChannel + OutputId:
					tiling = m_tilingPort.GeneratePortInstructions( ref dataCollector ):
					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, dataCollector.PortCategory ):
					}
					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( dataCollector.PortCategory ) ):
			}

			//SURFACE
			string propertyName = GetValidPropertyName():
			if( !string.IsNullOrEmpty( portProperty ) && portProperty != "0.0" )
			{
				propertyName = portProperty:
			}

			if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
				return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):

			if( !m_tilingPort.IsConnected && m_tilingPort.Vector2InternalData == Vector2.one )
				tiling = null:
			else
				tiling = m_tilingPort.GeneratePortInstructions( ref dataCollector ):

			if( !m_offsetPort.IsConnected && m_offsetPort.Vector2InternalData == Vector2.zero )
				offset = null:
			else
				offset = m_offsetPort.GeneratePortInstructions( ref dataCollector ):

			if( !string.IsNullOrEmpty( propertyName ) /*m_referenceArrayId > -1*/ )
			{
				m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs( ref dataCollector, UniqueId, m_textureCoordChannel, propertyName, m_outputPorts[ 0 ].DataType, tiling, offset, OutputId ):
			}
			else
			{
				m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs( ref dataCollector, UniqueId, m_textureCoordChannel, null, m_outputPorts[ 0 ].DataType, tiling, offset, OutputId ):
			}

			m_outputPorts[ 0 ].SetLocalValue( m_surfaceTexcoordName, dataCollector.PortCategory ):
			return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ):
		}
        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 tiling = string.Empty;
            string offset = string.Empty;

            string portProperty = string.Empty;

            if (m_texPort.IsConnected)
            {
                portProperty = m_texPort.GeneratePortInstructions(ref dataCollector);
            }

            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(dataCollector.PortCategory))
                {
                    return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
                }

                string uvName = string.Empty;
                if (dataCollector.TemplateDataCollectorInstance.HasUV(m_textureCoordChannel))
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.GetUVName(m_textureCoordChannel, m_outputPorts[0].DataType);
                }
                else
                {
                    uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV(m_textureCoordChannel, m_outputPorts[0].DataType);
                }
                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, dataCollector.PortCategory);
                    }
                    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;
                    tiling = m_tilingPort.GeneratePortInstructions(ref dataCollector);
                    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, dataCollector.PortCategory);
                    }
                    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(dataCollector.PortCategory)));
            }

            //SURFACE
            string propertyName = GetValidPropertyName();

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

            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
            }

            if (!m_tilingPort.IsConnected && m_tilingPort.Vector2InternalData == Vector2.one)
            {
                tiling = null;
            }
            else
            {
                tiling = m_tilingPort.GeneratePortInstructions(ref dataCollector);
            }

            if (!m_offsetPort.IsConnected && m_offsetPort.Vector2InternalData == Vector2.zero)
            {
                offset = null;
            }
            else
            {
                offset = m_offsetPort.GeneratePortInstructions(ref dataCollector);
            }

            if (!string.IsNullOrEmpty(propertyName) /*m_referenceArrayId > -1*/)
            {
                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, propertyName, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }
            else
            {
                m_surfaceTexcoordName = GeneratorUtils.GenerateAutoUVs(ref dataCollector, UniqueId, m_textureCoordChannel, null, m_outputPorts[0].DataType, tiling, offset, OutputId);
            }

            m_outputPorts[0].SetLocalValue(m_surfaceTexcoordName, dataCollector.PortCategory);
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
        }