public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                string varName = dataCollector.TemplateDataCollectorInstance.GetWorldPos();
                return(GetOutputVectorItem(0, outputId, varName));
            }

            string worldPosition = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId);

            return(GetOutputVectorItem(0, outputId, worldPosition));
        }
Пример #2
0
 public string BaseGenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
 {
     base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
     if (outputId > 0)
     {
         return(GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName));
     }
     else
     {
         return(PropertyName);
     }
 }
Пример #3
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));
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                string varName = (m_viewDirSpace == ViewSpace.World)? dataCollector.TemplateDataCollectorInstance.GetNormalizedViewDir():
                                 dataCollector.TemplateDataCollectorInstance.GetTangenViewDir();
                return(GetOutputVectorItem(0, outputId, varName));
            }


            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                if (m_viewDirSpace == ViewSpace.World)
                {
                    string precision = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, WirePortDataType.FLOAT3);
                    string worldPos  = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId);

                    dataCollector.AddLocalVariable(UniqueId, precision + " worldViewDir = normalize( UnityWorldSpaceViewDir( " + worldPos + " ) );");
                    return(GetOutputVectorItem(0, outputId, "worldViewDir"));
                }
                else
                {
                    string precision      = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, WirePortDataType.FLOAT3);
                    string worldPos       = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId);
                    string worldToTangent = GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType);

                    dataCollector.AddLocalVariable(UniqueId, precision + " tangentViewDir = mul( " + worldToTangent + ", normalize( UnityWorldSpaceViewDir( " + worldPos + " ) ) );");
                    return(GetOutputVectorItem(0, outputId, "tangentViewDir"));
                }
            }
            else
            {
                if (m_viewDirSpace == ViewSpace.World)
                {
                    if (dataCollector.DirtyNormal)
                    {
                        dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_POS), true);
                        dataCollector.AddToLocalVariables(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, "normalize( UnityWorldSpaceViewDir( " + Constants.InputVarStr + ".worldPos ) )");
                        return(GetOutputVectorItem(0, outputId, WorldDirVarStr));
                    }
                    else
                    {
                        return(base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar));
                    }
                }
                else
                {
                    dataCollector.ForceNormal = true;
                    return(base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar));
                }
            }
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                return(GetOutputVectorItem(0, outputId, dataCollector.TemplateDataCollectorInstance.GetWorldSpaceLightDir()));
            }
            ;

            dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs);
            dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_POS);

            return(GetOutputVectorItem(0, outputId, GeneratorUtils.GenerateWorldLightDirection(ref dataCollector, UniqueId, m_currentPrecisionType)));
        }
Пример #6
0
 public override void CheckIfAutoRegister(ref MasterNodeDataCollector dataCollector)
 {
     // Also testing inside shader function because node can be used indirectly over a custom expression and directly over a Function Output node
     // That isn't being used externaly making it to not be registered ( since m_connStatus it set to Connected by being connected to an output node
     if (CurrentParameterType != PropertyType.Constant && m_autoRegister && (m_connStatus != NodeConnectionStatus.Connected || InsideShaderFunction))
     {
         RegisterProperty(ref dataCollector);
         if (m_autoRegister && m_containerGraph.ParentWindow.OutsideGraph.SamplingMacros)
         {
             GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName, m_variableMode);
         }
     }
 }
Пример #7
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting)
            {
                return("float3(0,0,0)");
            }

            string normal = string.Empty;

            if (m_inputPorts[0].IsConnected)
            {
                dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType);
                dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
                dataCollector.ForceNormal = true;

                normal = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT3, ignoreLocalvar);
                if (m_normalSpace == ViewSpace.Tangent)
                {
                    normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )";
                }
            }
            else
            {
                if (dataCollector.IsFragmentCategory)
                {
                    dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType);
                    if (dataCollector.DirtyNormal)
                    {
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
                        dataCollector.ForceNormal = true;
                    }
                }

                normal = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId);
            }


            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "ShadeSH9( float4( " + normal + ", 1 ) )");
            }
            else
            {
                dataCollector.AddLocalVariable(UniqueId, "UnityGI gi" + OutputId + " = gi;");
                dataCollector.AddLocalVariable(UniqueId, PrecisionType.Float, WirePortDataType.FLOAT3, "diffNorm" + OutputId, normal);
                dataCollector.AddLocalVariable(UniqueId, "gi" + OutputId + " = UnityGI_Base( data, 1, diffNorm" + OutputId + " );");
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "gi" + OutputId + ".indirect.diffuse + diffNorm" + OutputId + " * 0.0001");
            }

            return("indirectDiffuse" + OutputId);
        }
Пример #8
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                string varName = (m_viewDirSpace == ViewSpace.World) ? dataCollector.TemplateDataCollectorInstance.GetViewDir(true, MasterNodePortCategory.Fragment, m_safeNormalize?NormalizeType.Safe:NormalizeType.Regular) :
                                 dataCollector.TemplateDataCollectorInstance.GetTangentViewDir(m_currentPrecisionType, true, MasterNodePortCategory.Fragment, m_safeNormalize ? NormalizeType.Safe : NormalizeType.Regular);
                return(GetOutputVectorItem(0, outputId, varName));
            }


            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                string result = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, m_viewDirSpace);
                return(GetOutputVectorItem(0, outputId, result));
            }
            else
            {
                if (m_viewDirSpace == ViewSpace.World)
                {
                    if (dataCollector.DirtyNormal || m_safeNormalize)
                    {
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_POS);
                        string result = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId);
                        return(GetOutputVectorItem(0, outputId, result));
                    }
                    else
                    {
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.VIEW_DIR, PrecisionType.Float);
                        return(GetOutputVectorItem(0, outputId, m_currentInputValueStr));
                        //return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar );
                    }
                }
                else
                {
                    if (m_safeNormalize)
                    {
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType);
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
                        dataCollector.ForceNormal = true;
                        dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_POS);
                        string result = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.Tangent);
                        return(GetOutputVectorItem(0, outputId, result));
                    }
                    else
                    {
                        dataCollector.ForceNormal = true;
                        return(base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar));
                    }
                }
            }
        }
Пример #9
0
        public override bool GetUniformData(out string dataType, out string dataName, ref bool fullValue)
        {
            m_excludeUniform = false;
            ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;

#if UNITY_2018_1_OR_NEWER
            if (outsideGraph.SamplingMacros || m_currentType == TextureType.Texture2DArray)
#else
            if ((outsideGraph.SamplingMacros && !outsideGraph.IsStandardSurface) || m_currentType == TextureType.Texture2DArray)
#endif
            {
                if (outsideGraph.IsSRP)
                {
                    if (Constants.TexDeclarationSRPMacros.ContainsKey(m_currentType))
                    {
                        dataName  = GeneratorUtils.GetPropertyDeclaraction(PropertyName, m_currentType, ";");
                        dataType  = string.Empty;
                        fullValue = true;
                        return(true);
                    }
                }
                else if (Constants.TexDeclarationStandardMacros.ContainsKey(m_currentType))
                {
#if !UNITY_2018_1_OR_NEWER
                    if (m_currentType == TextureType.Texture2DArray && outsideGraph.IsStandardSurface)
                    {
                        dataName = string.Format(Constants.TexDeclarationStandardMacros[m_currentType], PropertyName);
                    }
                    else
#endif
                    dataName  = GeneratorUtils.GetPropertyDeclaraction(PropertyName, m_currentType, ";");
                    dataType  = string.Empty;
                    fullValue = true;
                    return(true);
                }
            }

            //TODO: this is a hack and needs to be properly fixed
            if (PropertyName == "_CameraDepthTexture")
            {
                m_excludeUniform = true;
                dataType         = "UNITY_DECLARE_DEPTH_TEXTURE(";
                dataName         = m_propertyName + " )";
                return(true);
            }

            dataType = UIUtils.TextureTypeToCgType(m_currentType);
            dataName = m_propertyName;
            return(true);
        }
Пример #10
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader || ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting)
            {
                return("float3(0,0,0)");
            }

            string normal = string.Empty;

            if (m_inputPorts[0].IsConnected)
            {
                dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true);
                dataCollector.AddToInput(UniqueId, Constants.InternalData, false);
                dataCollector.ForceNormal = true;

                normal = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT3, ignoreLocalvar);
                if (m_normalSpace == ViewSpace.Tangent)
                {
                    normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )";
                }
            }
            else
            {
                if (dataCollector.IsFragmentCategory)
                {
                    dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true);
                    if (dataCollector.DirtyNormal)
                    {
                        dataCollector.AddToInput(UniqueId, Constants.InternalData, false);
                        dataCollector.ForceNormal = true;
                    }
                }

                normal = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId);
            }


            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "ShadeSH9( float4( " + normal + ", 1 ) )");
            }
            else
            {
                dataCollector.AddLocalVariable(UniqueId, "UnityGI gi" + OutputId + " = gi;");
                dataCollector.AddLocalVariable(UniqueId, "gi" + OutputId + " = UnityGI_Base( data, 1, " + normal + " );");
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "gi" + OutputId + ".indirect.diffuse");
            }

            return("indirectDiffuse" + OutputId);
        }
Пример #11
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 = GeneratorUtils.GenerateUnpackNormalStr(ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, src, isScaledNormal, scaleValue);
            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 && !dataCollector.IsSRP)
            {
                string varName = "localUnpackNormal" + OutputId;
                dataCollector.AddLocalVariable(UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ";");
                return(GetOutputVectorItem(0, outputId, varName));
            }
            else
            {
                return(GetOutputVectorItem(0, outputId, normalMapUnpackMode));
            }
        }
Пример #12
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue));
            }

            //string localVarName = ScreenPosStr + m_uniqueId;
            string localVarName = string.Empty;

            bool isFragment = dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug;

            if (isFragment)
            {
                string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true);
                localVarName = screenPos + OutputId;
                //dataCollector.AddToInput( m_uniqueId, "float4 " + ScreenPosStr, true );
                string value = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName + " = " + screenPos + ";";
                dataCollector.AddLocalVariable(UniqueId, value);
            }
            else
            {
                string screenPos = GeneratorUtils.GenerateVertexScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false);
                localVarName = screenPos + OutputId;
                string localVarDecl = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName;
                string value        = string.Format(ScreenPosOnVert00Str, localVarDecl, Constants.VertexShaderInputStr);
                dataCollector.AddLocalVariable(UniqueId, value);
                //dataCollector.AddLocalVariable( m_uniqueId, string.Format( ScreenPosOnVert01Str, localVarName ) );
            }

            dataCollector.AddLocalVariable(UniqueId, HackInstruction[0], true);
            dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[1], OutputId), true);
            dataCollector.AddLocalVariable(UniqueId, HackInstruction[2], true);
            dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[3], OutputId), true);
            dataCollector.AddLocalVariable(UniqueId, HackInstruction[4], true);
            dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[5], localVarName, OutputId), true);
            dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[6], localVarName, OutputId), true);
            dataCollector.AddLocalVariable(UniqueId, HackInstruction[7], true);
            dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[8], localVarName, OutputId), true);
            dataCollector.AddLocalVariable(UniqueId, HackInstruction[9], true);
            if (m_outputTypeInt == 0)
            {
                dataCollector.AddLocalVariable(UniqueId, string.Format(ProjectionInstruction, localVarName));
            }

            m_outputPorts[0].SetLocalValue(localVarName);
            //RegisterLocalVariable(outputId, localVarName ,ref dataCollector)
            return(GetOutputColorItem(0, outputId, localVarName));
        }
Пример #13
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.MasterNodeCategory == AvailableShaderTypes.Template)
            {
                string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition((m_sizeOption == 0) ? WirePortDataType.FLOAT3 : WirePortDataType.FLOAT4);
                return(GetOutputVectorItem(0, outputId, vertexPos));
            }


            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
            }

            WirePortDataType sizeType = m_sizeOption == 0 ? WirePortDataType.FLOAT3 : WirePortDataType.FLOAT4;

            string vertexPosition = GeneratorUtils.GenerateVertexPosition(ref dataCollector, UniqueId, m_currentPrecisionType, sizeType);

            return(GetOutputVectorItem(0, outputId, vertexPosition));

            //if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
            //{
            //	string vertexVar = base.GenerateShaderForOutput( 0, ref dataCollector, ignoreLocalVar );
            //	if ( outputId != 0 )
            //	{
            //		return GetOutputVectorItem( 0, outputId, vertexVar );
            //	}
            //	else if ( m_sizeOption == 0 )
            //	{
            //		vertexVar += ".xyz";
            //	}

            //	return vertexVar;
            //}
            //else
            //{

            //	string vertexVar = GeneratorUtils.GenerateVertexPositionOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType );
            //	if ( outputId != 0 )
            //	{
            //		return GetOutputVectorItem( 0, outputId, vertexVar );
            //	}
            //	else if ( m_sizeOption == 0 )
            //	{
            //		vertexVar += ".xyz";
            //	}
            //	return GetOutputVectorItem( 0, outputId, vertexVar );
            //}
        }
Пример #14
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
            }

            string precisionString = UIUtils.PrecisionWirePortToCgType(CurrentPrecisionType, WirePortDataType.FLOAT);
            string value           = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);

            if (m_outputPorts[0].DataType == WirePortDataType.FLOAT3x3)
            {
                GeneratorUtils.Add3x3InverseFunction(ref dataCollector, precisionString);
                RegisterLocalVariable(0, string.Format(GeneratorUtils.Inverse3x3Header, value), ref dataCollector, "invertVal" + OutputId);
            }
            else
            {
                if (!dataCollector.HasFunction(Inverse4x4Header))
                {
                    //Hack to be used util indent is properly used
                    int currIndent = UIUtils.ShaderIndentLevel;

                    if (dataCollector.IsTemplate)
                    {
                        UIUtils.ShaderIndentLevel = 0;
                    }
                    else
                    {
                        UIUtils.ShaderIndentLevel = 1;
                        UIUtils.ShaderIndentLevel++;
                    }

                    string finalFunction = string.Empty;
                    for (int i = 0; i < Inverse4x4Function.Length; i++)
                    {
                        finalFunction += UIUtils.ShaderIndentTabs + (Inverse4x4FunctionFlags[i] ? string.Format(Inverse4x4Function[i], precisionString) : Inverse4x4Function[i]);
                    }


                    UIUtils.ShaderIndentLevel = currIndent;

                    dataCollector.AddFunction(Inverse4x4Header, finalFunction);
                }

                RegisterLocalVariable(0, string.Format(Inverse4x4Header, value), ref dataCollector, "invertVal" + OutputId);
            }

            return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
        }
Пример #15
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                //Template must have its Light Mode correctly configured on tags to work as intended
                return(dataCollector.TemplateDataCollectorInstance.GetObjectSpaceLightDir());
            }

            dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs);
            dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(PrecisionType.Float, AvailableSurfaceInputs.WORLD_POS), true);

            string vertexPos = GeneratorUtils.GenerateVertexPosition(ref dataCollector, UniqueId, WirePortDataType.FLOAT4);

            return(GeneratorUtils.GenerateObjectLightDirection(ref dataCollector, UniqueId, m_currentPrecisionType, vertexPos));
        }
Пример #16
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));
        }
Пример #17
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                UIUtils.ShowNoVertexModeNodeMessage(this);
                return("0");
            }

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

            dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs);
            dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;");

            string screenPos = string.Empty;

            if (m_inputPorts[0].IsConnected)
            {
                screenPos = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT4, false);
            }
            else
            {
                screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos);
            }


            string screenDepthInstruction = "UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + ")))";

            if (m_convertToLinear)
            {
                string viewSpace = m_viewSpaceInt == 0 ? "Eye" : "01";
                screenDepthInstruction = string.Format("Linear" + viewSpace + "Depth({0})", screenDepthInstruction);
            }
            else
            {
                if (m_viewSpaceInt == 0)
                {
                    screenDepthInstruction = string.Format("({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepthInstruction);
                }
            }

            dataCollector.AddToLocalVariables(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[m_viewSpaceInt] + OutputId, screenDepthInstruction);

            m_outputPorts[0].SetLocalValue(m_vertexNameStr[m_viewSpaceInt] + OutputId);
            return(GetOutputColorItem(0, outputId, m_vertexNameStr[m_viewSpaceInt] + OutputId));
        }
Пример #18
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                return(dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix());
            }

            dataCollector.ForceNormal = true;

            dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true);
            dataCollector.AddToInput(UniqueId, Constants.InternalData, false);

            GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType);

            return(GeneratorUtils.WorldToTangentStr);
        }
Пример #19
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                return(dataCollector.TemplateDataCollectorInstance.GetEyeDepth());
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                string vertexSpace       = m_viewSpaceInt == 1 ? " * _ProjectionParams.w" : "";
                string vertexInstruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z" + vertexSpace;
                dataCollector.AddVertexInstruction("float " + m_vertexNameStr[m_viewSpaceInt] + " = " + vertexInstruction, UniqueId);

                return(m_vertexNameStr[m_viewSpaceInt]);
            }

            dataCollector.AddToIncludes(UniqueId, Constants.UnityShaderVariables);


            if (dataCollector.TesselationActive)
            {
                string eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag(ref dataCollector, UniqueId, m_currentPrecisionType);
                if (m_viewSpaceInt == 1)
                {
                    dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[1], eyeDepth + " * _ProjectionParams.w");
                    return(m_vertexNameStr[1]);
                }
                else
                {
                    return(eyeDepth);
                }
            }
            else
            {
                string space = string.Empty;
                if (m_viewSpaceInt == 1)
                {
                    space = " * _ProjectionParams.w";
                }

                dataCollector.AddToInput(UniqueId, m_vertexNameStr[m_viewSpaceInt], WirePortDataType.FLOAT);
                string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z" + space;
                dataCollector.AddVertexInstruction(Constants.VertexShaderOutputStr + "." + m_vertexNameStr[m_viewSpaceInt] + " = " + instruction, UniqueId);

                return(Constants.InputVarStr + "." + m_vertexNameStr[m_viewSpaceInt]);
            }
        }
Пример #20
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(m_outputPorts[0].LocalValue);
            }

            dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_POS), true);
            if (dataCollector.IsFragmentCategory)
            {
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, string.Format(WorldDirFuncStr, Constants.InputVarStr + ".worldPos"));
            }
            else
            {
                string worldPosVar = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId);
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, string.Format(WorldDirFuncStr, worldPosVar));
            }

            string normal = string.Empty;

            if (m_inputPorts[0].IsConnected)
            {
                normal = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT3, ignoreLocalvar, true);
            }
            else
            {
                dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true);
                dataCollector.AddToInput(UniqueId, Constants.InternalData, false);
                normal = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId);
                //string normalWorld = "WorldNormalVector( " + Constants.InputVarStr + ", float3( 0, 0, 1 ) );";
                //dataCollector.AddToLocalVariables( m_uniqueId, "float3 worldNormal = "+ normalWorld );
                //normal = "worldNormal";
                //dataCollector.ForceNormal = true;
            }

            string bias  = m_inputPorts[1].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true);
            string scale = m_inputPorts[2].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true);
            string power = m_inputPorts[3].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true);

            string ndotl = "dot( " + normal + ", " + WorldDirVarStr + " )";

            string fresnelFinalVar = FresnedFinalVar + OutputId;
            string result          = string.Format("({0} + {1}*pow( 1.0 - {2} , {3}))", bias, scale, ndotl, power);

            RegisterLocalVariable(0, result, ref dataCollector, fresnelFinalVar);
            return(m_outputPorts[0].LocalValue);
        }
Пример #21
0
        public string GetUVCoords(ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar, bool isProjecting)
        {
            if (m_inputPorts[0].IsConnected)
            {
                string result = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, (isProjecting ? WirePortDataType.FLOAT4 : WirePortDataType.FLOAT2), ignoreLocalVar, true);
                if (isProjecting)
                {
                    return("UNITY_PROJ_COORD( " + result + " )");
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                string localVarName = string.Empty;

                if (dataCollector.IsTemplate)
                {
                    localVarName = dataCollector.TemplateDataCollectorInstance.GetScreenPos();
                }
                else
                {
                    //dataCollector.AddToInput( UniqueId, "float4 " + ScreenPosStr, true );

                    string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos);

                    localVarName = screenPos + OutputId;
                    string value = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName + " = " + screenPos + ";";
                    dataCollector.AddLocalVariable(UniqueId, value, true);
                }

                dataCollector.AddLocalVariable(UniqueId, HackInstruction[0], true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[1], OutputId), true);
                dataCollector.AddLocalVariable(UniqueId, HackInstruction[2], true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[3], OutputId), true);
                dataCollector.AddLocalVariable(UniqueId, HackInstruction[4], true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[5], localVarName, OutputId), true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[6], localVarName, OutputId), true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[7], localVarName), true);
                dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[8], localVarName), true);
                return("UNITY_PROJ_COORD( " + localVarName + " )");
            }
        }
Пример #22
0
        public virtual string GenerateSamplerPropertyName(int outputId, ref MasterNodeDataCollector dataCollector)
        {
            string generatedSamplerState = string.Empty;

            if (outputId > 0 || m_forceSamplingMacrosGen)
            {
                generatedSamplerState = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName, m_variableMode);
            }

            if (outputId > 0)
            {
                return(generatedSamplerState);
            }
            else
            {
                return(PropertyName);
            }
        }
Пример #23
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                UIUtils.ShowNoVertexModeNodeMessage(this);
                return("0");
            }

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

            dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs);
            dataCollector.AddToUniforms(UniqueId, "uniform sampler2D_float _CameraDepthTexture;");

            dataCollector.AddCodeComments(true, new string[] { "Start - Stylized Water custom depth" });
            string screenPos     = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true);
            string screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, true);

            string screenDepth = "UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + ")))";

            screenDepth = string.Format("LinearEyeDepth({0})", screenDepth);

            string distance = "lerp( 1.0 , ( 1.0 / _ProjectionParams.z ) , unity_OrthoParams.w)";

            dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";");

            string depthVal = " ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / (  " + distance + " );";

            dataCollector.AddLocalVariable(UniqueId, "float distanceDepth" + OutputId + " = " + depthVal);

            dataCollector.AddLocalVariable(UniqueId, "#if SHADER_API_MOBILE && UNITY_VERSION >= 20183 //Build only, abs() function causes offset in depth on mobile in 2018.3", true);
            dataCollector.AddLocalVariable(UniqueId, "#else", true);
            dataCollector.AddLocalVariable(UniqueId, "distanceDepth" + OutputId + " = " + "abs(distanceDepth" + OutputId + ");", true);

            dataCollector.AddLocalVariable(UniqueId, "#endif", true);


            m_outputPorts[0].SetLocalValue("distanceDepth" + OutputId, MasterNodePortCategory.Fragment);
            dataCollector.AddCodeComments(true, new string[] { "End - Stylized Water custom depth" });

            return(GetOutputColorItem(0, outputId, "distanceDepth" + OutputId));
        }
Пример #24
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (dataCollector.IsTemplate)
            {
                return(dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix(CurrentPrecisionType));
            }

            if (dataCollector.IsFragmentCategory)
            {
                dataCollector.ForceNormal = true;

                dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType);
                dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
            }

            GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType);

            return(GeneratorUtils.WorldToTangentStr);
        }
Пример #25
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                return(GetOutputVectorItem(0, outputId, dataCollector.TemplateDataCollectorInstance.GetWorldBinormal()));
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                dataCollector.ForceNormal = true;

                dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true);
                dataCollector.AddToInput(UniqueId, Constants.InternalData, false);
            }

            string worldBitangent = GeneratorUtils.GenerateWorldBitangent(ref dataCollector, UniqueId);

            return(GetOutputVectorItem(0, outputId, worldBitangent));
        }
Пример #26
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                return(GetOutputVectorItem(0, outputId, dataCollector.TemplateDataCollectorInstance.GetWorldBinormal(m_currentPrecisionType)));
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                dataCollector.ForceNormal = true;

                dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType);
                dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false);
            }

            string worldBitangent = GeneratorUtils.GenerateWorldBitangent(ref dataCollector, UniqueId);

            return(GetOutputVectorItem(0, outputId, worldBitangent));
        }
Пример #27
0
        public string BaseGenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
            string generatedSamplerState = string.Empty;

            if (outputId > 0 || m_forceSamplingMacrosGen)
            {
                generatedSamplerState = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName);
            }

            if (outputId > 0)
            {
                return(generatedSamplerState);
            }
            else
            {
                return(PropertyName);
            }
        }
Пример #28
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                UIUtils.ShowNoVertexModeNodeMessage(this);
                return("0");
            }

            dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs);
            dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;");

            string screenPos   = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true);
            string screenDepth = "LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + "))))";
            string distance    = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);

            dataCollector.AddToLocalVariables(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";");
            dataCollector.AddToLocalVariables(UniqueId, "float distanceDepth" + OutputId + " = abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPos + ".z/ " + screenPos + ".w ) ) / ( " + distance + " ) );");
            return("distanceDepth" + OutputId);
        }
Пример #29
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));
            }

            if (dataCollector.IsFragmentCategory && !dataCollector.UsingCustomScreenPos)
            {
                base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
            }

            string screenPos = string.Empty;

            if (m_outputTypeInt == 0)
            {
                if (dataCollector.IsTemplate)
                {
                    screenPos = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized();
                }
                else
                {
                    screenPos = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, false);
                }
            }
            else
            {
                if (dataCollector.IsTemplate)
                {
                    screenPos = dataCollector.TemplateDataCollectorInstance.GetScreenPos();
                }
                else
                {
                    screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false);
                }
            }



            m_outputPorts[0].SetLocalValue(screenPos);
            return(GetOutputVectorItem(0, outputId, screenPos));
        }
Пример #30
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            //Forcing world pos into float precision because positions shouldn't use fixed
            m_currentPrecisionType = PrecisionType.Float;

            if (dataCollector.IsTemplate)
            {
                string varName = dataCollector.TemplateDataCollectorInstance.GetWorldPos();
                return(GetOutputVectorItem(0, outputId, varName));
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug)
            {
                base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar);
            }

            string worldPosition = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId);

            return(GetOutputVectorItem(0, outputId, worldPosition));
        }