Пример #1
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]);
            }
        }
Пример #2
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(m_outputPorts[0].LocalValue);
            }

            InputPort vertexPort = GetInputPortByUniqueId(2);
            InputPort lengthPort = GetInputPortByUniqueId(0);
            InputPort offsetPort = GetInputPortByUniqueId(1);

            string distance = lengthPort.GeneratePortInstructions(ref dataCollector);
            string offset   = offsetPort.GeneratePortInstructions(ref dataCollector);

            string value    = string.Empty;
            string eyeDepth = string.Empty;

            if (dataCollector.IsTemplate)
            {
                if (vertexPort.IsConnected)
                {
                    string varName = "customSurfaceDepth" + OutputId;
                    GenerateInputInVertex(ref dataCollector, 2, varName, false);

                    string formatStr = string.Empty;
                    if (dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight)
                    {
                        formatStr = "-TransformWorldToView(TransformObjectToWorld({0})).z";
                    }
                    else
                    {
                        formatStr = "-UnityObjectToViewPos({0}).z";
                    }

                    string eyeInstruction = string.Format(formatStr, varName);
                    eyeDepth = "customEye" + OutputId;
                    dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData(eyeDepth, WirePortDataType.FLOAT, m_currentPrecisionType, eyeInstruction);
                }
                else
                {
                    eyeDepth = dataCollector.TemplateDataCollectorInstance.GetEyeDepth(m_currentPrecisionType);
                }

                value = string.Format(CameraDepthFadeFormat, eyeDepth, offset, distance);
                RegisterLocalVariable(0, value, ref dataCollector, "cameraDepthFade" + OutputId);
                return(m_outputPorts[0].LocalValue);
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                string vertexVarName = string.Empty;
                if (vertexPort.IsConnected)
                {
                    vertexVarName = vertexPort.GeneratePortInstructions(ref dataCollector);
                }
                else
                {
                    vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz";
                }

                //dataCollector.AddVertexInstruction( "float cameraDepthFade" + UniqueId + " = (( -UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z -_ProjectionParams.y - " + offset + " ) / " + distance + ");", UniqueId );
                value = string.Format(CameraDepthFadeFormat, "-UnityObjectToViewPos( " + vertexVarName + " ).z", offset, distance);
                RegisterLocalVariable(0, value, ref dataCollector, "cameraDepthFade" + OutputId);
                return(m_outputPorts[0].LocalValue);
            }

            dataCollector.AddToIncludes(UniqueId, Constants.UnityShaderVariables);

            if (dataCollector.TesselationActive)
            {
                if (vertexPort.IsConnected)
                {
                    string vertexValue = vertexPort.GeneratePortInstructions(ref dataCollector);
                    eyeDepth = "customSurfaceDepth" + OutputId;
                    RegisterLocalVariable(0, string.Format("-UnityObjectToViewPos( {0} ).z", vertexValue), ref dataCollector, eyeDepth);
                }
                else
                {
                    eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag(ref dataCollector, UniqueId, m_currentPrecisionType);
                }
            }
            else
            {
                if (vertexPort.IsConnected)
                {
                    string varName = "customSurfaceDepth" + OutputId;
                    GenerateInputInVertex(ref dataCollector, 2, varName, false);
                    dataCollector.AddToInput(UniqueId, varName, WirePortDataType.FLOAT);
                    string vertexInstruction = "-UnityObjectToViewPos( " + varName + " ).z";
                    dataCollector.AddVertexInstruction(Constants.VertexShaderOutputStr + "." + varName + " = " + vertexInstruction, UniqueId);
                    eyeDepth = Constants.InputVarStr + "." + varName;
                }
                else
                {
                    dataCollector.AddToInput(UniqueId, "eyeDepth", WirePortDataType.FLOAT);
                    string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z";
                    dataCollector.AddVertexInstruction(Constants.VertexShaderOutputStr + ".eyeDepth = " + instruction, UniqueId);
                    eyeDepth = Constants.InputVarStr + ".eyeDepth";
                }
            }

            value = string.Format(CameraDepthFadeFormat, eyeDepth, offset, distance);
            RegisterLocalVariable(0, value, ref dataCollector, "cameraDepthFade" + OutputId);
            //dataCollector.AddToLocalVariables( UniqueId, "float cameraDepthFade" + UniqueId + " = (( " + Constants.InputVarStr + ".eyeDepth -_ProjectionParams.y - "+ offset + " ) / " + distance + ");" );

            return(m_outputPorts[0].LocalValue);
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (dataCollector.IsTemplate)
            {
                if (m_inputPorts[0].IsConnected)
                {
                    string space = string.Empty;
                    if (m_viewSpaceInt == 1)
                    {
                        space = " * _ProjectionParams.w";
                    }

                    string varName = "customSurfaceDepth" + OutputId;
                    GenerateInputInVertex(ref dataCollector, 0, varName, false);
                    string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space;
                    if (dataCollector.IsSRP)
                    {
                        instruction = "-TransformWorldToView(TransformObjectToWorld( " + varName + " )).z" + space;
                    }
                    string eyeVarName = "customEye" + OutputId;
                    dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData(eyeVarName, WirePortDataType.FLOAT, m_currentPrecisionType, instruction);
                    return(eyeVarName);
                }
                else
                {
                    return(dataCollector.TemplateDataCollectorInstance.GetEyeDepth(m_currentPrecisionType, true, MasterNodePortCategory.Fragment, m_viewSpaceInt));
                }
            }

            if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation)
            {
                string vertexVarName = string.Empty;
                if (m_inputPorts[0].IsConnected)
                {
                    vertexVarName = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                }
                else
                {
                    vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz";
                }

                string vertexSpace       = m_viewSpaceInt == 1 ? " * _ProjectionParams.w" : "";
                string vertexInstruction = "-UnityObjectToViewPos( " + vertexVarName + " ).z" + vertexSpace;
                dataCollector.AddVertexInstruction("float " + m_vertexNameStr[m_viewSpaceInt] + " = " + vertexInstruction, UniqueId);

                return(m_vertexNameStr[m_viewSpaceInt]);
            }

            dataCollector.AddToIncludes(UniqueId, Constants.UnityShaderVariables);


            if (dataCollector.TesselationActive)
            {
                if (m_inputPorts[0].IsConnected)
                {
                    string space = string.Empty;
                    if (m_viewSpaceInt == 1)
                    {
                        space = " * _ProjectionParams.w";
                    }

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

                    string value = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                    RegisterLocalVariable(0, string.Format("-UnityObjectToViewPos( {0} ).z", value) + space, ref dataCollector, "customSurfaceDepth" + OutputId);
                    return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
                }
                else
                {
                    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";
                }

                if (m_inputPorts[0].IsConnected)
                {
                    string varName = "customSurfaceDepth" + OutputId;
                    GenerateInputInVertex(ref dataCollector, 0, varName, false);
                    dataCollector.AddToInput(UniqueId, varName, WirePortDataType.FLOAT);
                    string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space;
                    dataCollector.AddToVertexLocalVariables(UniqueId, Constants.VertexShaderOutputStr + "." + varName + " = " + instruction + ";");
                    return(Constants.InputVarStr + "." + varName);
                }
                else
                {
                    dataCollector.AddToInput(UniqueId, m_vertexNameStr[m_viewSpaceInt], WirePortDataType.FLOAT);
                    string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z" + space;
                    dataCollector.AddToVertexLocalVariables(UniqueId, Constants.VertexShaderOutputStr + "." + m_vertexNameStr[m_viewSpaceInt] + " = " + instruction + ";");
                    return(Constants.InputVarStr + "." + m_vertexNameStr[m_viewSpaceInt]);
                }
            }
        }