コード例 #1
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            string src = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);


            bool isScaledNormal = false;

            if (m_inputPorts[1].IsConnected)
            {
                isScaledNormal = true;
            }
            else
            {
                if (m_inputPorts[1].FloatInternalData != 1)
                {
                    isScaledNormal = true;
                }
            }

            string normalMapUnpackMode = string.Empty;
            string scaleValue          = isScaledNormal?m_inputPorts[1].GeneratePortInstructions(ref dataCollector):"1.0";

            normalMapUnpackMode = string.Format(TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, isScaledNormal, scaleValue), src);
            if (isScaledNormal && !(dataCollector.IsTemplate && dataCollector.IsSRP))
            {
                dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs);
            }

            int outputUsage = 0;

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                if (m_outputPorts[i].IsConnected)
                {
                    outputUsage += 1;
                }
            }


            if (outputUsage > 1)
            {
                string varName = "localUnpackNormal" + OutputId;
                dataCollector.AddLocalVariable(UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ";");
                return(GetOutputVectorItem(0, outputId, varName));
            }
            else
            {
                return(GetOutputVectorItem(0, outputId, normalMapUnpackMode));
            }
        }
コード例 #2
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_proceduralMaterial == null)
            {
                return("(0).xxxx");
            }

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

            Texture[] textures = m_proceduralMaterial.GetGeneratedTextures();

            string uvPropertyName = string.Empty;

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                if (m_outputPorts[i].IsConnected)
                {
                    uvPropertyName = textures[i].name;
                    break;
                }
            }

            string name = textures[outputId].name + OutputId;

            dataCollector.AddToUniforms(UniqueId, string.Format(GlobalVarDecStr, textures[outputId].name));
            dataCollector.AddToProperties(UniqueId, string.Format(PropertyDecStr, textures[outputId].name) + "{}", -1);
            bool   isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation);
            string value    = string.Format("tex2D{0}({1}, {2})", (isVertex ? "lod" : string.Empty), textures[outputId].name, GetUVCoords(ref dataCollector, ignoreLocalvar, uvPropertyName));

            if (m_autoNormal && m_textureTypes[outputId] == ProceduralOutputType.Normal)
            {
                value = string.Format(TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, false, "1.0"), value);
            }

            dataCollector.AddPropertyNode(this);
            RegisterLocalVariable(outputId, value, ref dataCollector, name);

            return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory));
        }
コード例 #3
0
ファイル: TextureArrayNode.cs プロジェクト: EGSP/Flappy-Bird
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
            }


            OnPropertyNameChanged();

            CheckReference();

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

            bool instanced = false;

            if (m_referenceType == TexReferenceType.Instance && m_referenceSampler != null)
            {
                instanced = true;
            }

            if (instanced)
            {
                if (!m_referenceSampler.TexPort.IsConnected)
                {
                    base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);
                }
            }
            else if (!m_texPort.IsConnected)
            {
                base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);
            }

            string level = string.Empty;

            if (m_lodPort.Visible)
            {
                level = m_lodPort.GeneratePortInstructions(ref dataCollector);
            }

            if (isVertex && !m_lodPort.Visible)
            {
                level = "0";
            }

            string propertyName = string.Empty;

            if (instanced)
            {
                if (m_referenceSampler.TexPort.IsConnected)
                {
                    propertyName = m_referenceSampler.TexPort.GeneratePortInstructions(ref dataCollector);
                }
                else
                {
                    propertyName = m_referenceSampler.PropertyName;
                }
            }
            else if (m_texPort.IsConnected)
            {
                propertyName = m_texPort.GeneratePortInstructions(ref dataCollector);
            }
            else
            {
                propertyName = PropertyName;
            }

            string uvs = string.Empty;

            if (m_uvPort.IsConnected)
            {
                uvs = m_uvPort.GeneratePortInstructions(ref dataCollector);
            }
            else
            {
                if (dataCollector.IsTemplate)
                {
                    uvs = dataCollector.TemplateDataCollectorInstance.GetTextureCoord(m_uvSet, (instanced ? m_referenceSampler.PropertyName : PropertyName), UniqueId, m_currentPrecisionType);
                }
                else
                {
                    if (isVertex)
                    {
                        uvs = TexCoordVertexDataNode.GenerateVertexUVs(ref dataCollector, UniqueId, m_uvSet, propertyName);
                    }
                    else
                    {
                        uvs = TexCoordVertexDataNode.GenerateFragUVs(ref dataCollector, UniqueId, m_uvSet, propertyName);
                    }
                }
            }
            string index = m_indexPort.GeneratePortInstructions(ref dataCollector);

            string m_normalMapUnpackMode = "";

            if (m_autoUnpackNormals)
            {
                bool isScaledNormal = false;
                if (m_normalPort.IsConnected)
                {
                    isScaledNormal = true;
                }
                else
                {
                    if (m_normalPort.FloatInternalData != 1)
                    {
                        isScaledNormal = true;
                    }
                }

                string scaleValue = isScaledNormal?m_normalPort.GeneratePortInstructions(ref dataCollector):"1.0";
                m_normalMapUnpackMode = TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, isScaledNormal, scaleValue);
                if (isScaledNormal && (!dataCollector.IsTemplate || !dataCollector.IsSRP))
                {
                    dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs);
                }
            }

            string result = string.Empty;

            if (dataCollector.IsTemplate && dataCollector.IsSRP)
            {
                //CAREFUL mipbias here means derivative (this needs index changes)
                //TODO: unity now supports bias as well
                if (m_mipMode == MipType.MipBias)
                {
                    dataCollector.UsingArrayDerivatives = true;
                    result = propertyName + ".SampleGrad(sampler" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + ");";
                }
                else if (m_lodPort.Visible || isVertex)
                {
                    result = "SAMPLE_TEXTURE2D_ARRAY_LOD(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + ", " + level + " )";
                }
                else
                {
                    result = "SAMPLE_TEXTURE2D_ARRAY(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + " )";
                }
            }
            else
            {
                //CAREFUL mipbias here means derivative (this needs index changes)
                if (m_mipMode == MipType.MipBias)
                {
                    dataCollector.UsingArrayDerivatives = true;
                    result = "ASE_SAMPLE_TEX2DARRAY_GRAD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + " )";
                }
                else if (m_lodPort.Visible || isVertex)
                {
                    result = "UNITY_SAMPLE_TEX2DARRAY_LOD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + level + " )";
                }
                else
                {
                    result = "UNITY_SAMPLE_TEX2DARRAY" + (m_lodPort.Visible || isVertex ? "_LOD" : "") + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + (m_lodPort.Visible || isVertex ? ", " + level : "") + " )";
                }
            }

            if (m_autoUnpackNormals)
            {
                result = string.Format(m_normalMapUnpackMode, result);
            }

            RegisterLocalVariable(0, result, ref dataCollector, "texArray" + OutputId);
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
        }