Esempio n. 1
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
            }


            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;
                    }
                }
                if (isScaledNormal)
                {
                    string scaleValue = m_normalPort.GeneratePortInstructions(ref dataCollector);
                    dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs);
                    m_normalMapUnpackMode = "UnpackScaleNormal( {0} ," + scaleValue + " )";
                }
                else
                {
                    m_normalMapUnpackMode = "UnpackNormal( {0} )";
                }
            }

            string result = string.Empty;

            //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));
        }
Esempio n. 2
0
        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();

            if (CheckReference())
            {
                OrderIndex       = m_referenceSampler.RawOrderIndex;
                OrderIndexOffset = m_referenceSampler.OrderIndexOffset;
            }

            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, propertyName /*( instanced ? m_referenceSampler.PropertyName : PropertyName )*/, UniqueId, 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 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)
            {
                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";
                result = GeneratorUtils.GenerateUnpackNormalStr(ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, result, isScaledNormal, scaleValue);
                if (isScaledNormal && (!dataCollector.IsTemplate || !dataCollector.IsSRP))
                {
                    dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs);
                }
            }

            RegisterLocalVariable(0, result, ref dataCollector, "texArray" + OutputId);
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory)));
        }
Esempio n. 3
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
            }


            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)
            {
                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 uvs = string.Empty;

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

            int connectionNumber = 0;

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                connectionNumber += m_outputPorts[i].ConnectionCount;
            }

            string propertyName = string.Empty;

            if (!instanced)
            {
                propertyName = PropertyName;
            }
            else
            {
                propertyName = m_referenceSampler.PropertyName;
            }


            string m_normalMapUnpackMode = "";

            if (m_autoUnpackNormals)
            {
                bool isScaledNormal = false;
                if (m_normalPort.IsConnected)
                {
                    isScaledNormal = true;
                }
                else
                {
                    if (m_normalPort.FloatInternalData != 1)
                    {
                        isScaledNormal = true;
                    }
                }
                if (isScaledNormal)
                {
                    string scaleValue = m_normalPort.GeneratePortInstructions(ref dataCollector);
                    dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs);
                    m_normalMapUnpackMode = "UnpackScaleNormal( {0} ," + scaleValue + " )";
                }
                else
                {
                    m_normalMapUnpackMode = "UnpackNormal( {0} )";
                }
            }

            string 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);
            }

            //if ( connectionNumber > 1 )
            //{
            RegisterLocalVariable(0, result, ref dataCollector, "texArray" + OutputId);
            //dataCollector.AddToLocalVariables( UniqueId, "float" + ( m_autoUnpackNormals ? "3" : "4" ) + " texArray" + m_uniqueId + " = " + result + ";" );
            return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue));
            //}
            //else
            //{

            //	return GetOutputVectorItem( 0, outputId, result );
            //}
        }
Esempio n. 4
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            OnPropertyNameChanged();

            CheckReference();

            bool instanced = false;

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

            if (!instanced)
            {
                base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);
            }

            string level = string.Empty;

            if (InputPorts[2].Visible)
            {
                level = InputPorts[2].GeneratePortInstructions(ref dataCollector);
            }


            string uvs = string.Empty;

            if (InputPorts[0].IsConnected)
            {
                uvs = InputPorts[0].GeneratePortInstructions(ref dataCollector);
            }
            else
            {
                uvs = TexCoordVertexDataNode.GenerateFragUVs(ref dataCollector, m_uniqueId, m_uvSet, (instanced ? m_referenceSampler.PropertyName : PropertyName));
            }
            string index = InputPorts[1].GeneratePortInstructions(ref dataCollector);

            int connectionNumber = 0;

            for (int i = 0; i < m_outputPorts.Count; i++)
            {
                connectionNumber += m_outputPorts[i].ConnectionCount;
            }

            string propertyName = string.Empty;

            if (!instanced)
            {
                propertyName = PropertyName;
            }
            else
            {
                propertyName = m_referenceSampler.PropertyName;
            }

            string result = "UNITY_SAMPLE_TEX2DARRAY" + (InputPorts[2].Visible ? "_LOD" : "") + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + (InputPorts[2].Visible ? ", " + level : "") + " )";

            if (connectionNumber > 1)
            {
                dataCollector.AddToLocalVariables(m_uniqueId, "float4 texArray" + m_uniqueId + " = " + result + ";");
                return(GetOutputVectorItem(0, outputId, "texArray" + m_uniqueId));
            }
            else
            {
                return(GetOutputVectorItem(0, outputId, result));
            }
        }