Ejemplo n.º 1
0
        public string[] OutlineFunctionBody(ref MasterNodeDataCollector dataCollector, bool instanced, bool isShadowCaster, string shaderName, string[] billboardInfo, ref TessellationOpHelper tessOpHelper, string target, PrecisionType precision)
        {
            List <string> body = new List <string>();

            body.Add(ModeTags[dataCollector.CustomOutlineSelectedAlpha]);
            if (!string.IsNullOrEmpty(m_grabPasses))
            {
                body.Add(m_grabPasses.Replace("\t\t", string.Empty));
            }

            if (m_zWriteMode != 0)
            {
                body.Add("ZWrite " + ZBufferOpHelper.ZWriteModeValues[m_zWriteMode]);
            }
            if (m_zTestMode != 0)
            {
                body.Add("ZTest " + ZBufferOpHelper.ZTestModeValues[m_zTestMode]);
            }

            body.Add("Cull " + m_cullMode);
            body.Add("CGPROGRAM");
            if (tessOpHelper.EnableTesselation)
            {
                body.Add("#include \"" + TessellationOpHelper.TessInclude + "\"");
                body.Add("#pragma target " + target);
            }
            else
            {
                body.Add("#pragma target 3.0");
            }

            bool   customOutline = dataCollector.UsingCustomOutlineColor || dataCollector.UsingCustomOutlineWidth || dataCollector.UsingCustomOutlineAlpha;
            int    outlineMode   = customOutline ? m_offsetMode : (m_mode == OutlineMode.VertexOffset ? 0 : 1);
            string extraOptions  = (customOutline ? m_customNoFog : m_noFog) ? "nofog " : string.Empty;

            if (dataCollector.CustomOutlineSelectedAlpha > 0)
            {
                extraOptions += ModePragma[dataCollector.CustomOutlineSelectedAlpha];
            }

            string surfConfig = string.Format(OutlineSurfaceConfig, extraOptions);

            if (tessOpHelper.EnableTesselation)
            {
                tessOpHelper.WriteToOptionalParams(ref surfConfig);
            }

            body.Add(surfConfig);
            if (!isShadowCaster)
            {
                AddMultibodyString(m_defines, body);
                AddMultibodyString(m_includes, body);
                AddMultibodyString(m_pragmas, body);
            }

            //if( instanced )
            //{
            //	body.Add( OutlineInstancedHeader );
            //}

            if (customOutline)
            {
                if (isShadowCaster)
                {
                    for (int i = 0; i < InputList.Count; i++)
                    {
                        dataCollector.AddToInput(InputList[i].NodeId, InputList[i].PropertyName, true);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_inputs))
                    {
                        body.Add(m_inputs.Trim('\t', '\n'));
                    }
                }

                if (!DirtyInput && !isShadowCaster)
                {
                    body.Add(OutlineBodyStructDefault);
                }

                if (!isShadowCaster)
                {
                    body.Add(OutlineBodyStructEnd);
                }
            }
            else if (!isShadowCaster)
            {
                body.Add(OutlineBodyStructBegin);
                body.Add(OutlineBodyStructDefault);
                body.Add(OutlineBodyStructEnd);
            }

            if (instanced)
            {
                //for( int i = 0; i < OutlineBodyInstancedBegin.Length; i++ )
                //{
                //	body.Add( ( i == 0 ) ? string.Format( OutlineBodyInstancedBegin[ i ], shaderName ) : OutlineBodyInstancedBegin[ i ] );
                //}

                //if( (object)billboardInfo != null )
                //{
                //	for( int j = 0; j < billboardInfo.Length; j++ )
                //	{
                //		body.Add( string.Format( BillboardInstructionFormat, billboardInfo[ j ] ) );
                //	}
                //}

                //switch( outlineMode )
                //{
                //	case 0: body.Add( string.Format( OutlineVertexOffsetMode, WidthVariableAccessInstanced ) ); break;
                //	case 1: body.Add( string.Format( OutlineVertexScaleMode, WidthVariableAccessInstanced ) ); break;
                //	case 2: body.Add( string.Format( OutlineVertexCustomMode, WidthVariableAccessInstanced ) ); break;
                //}
                //for( int i = 0; i < OutlineBodyInstancedEnd.Length; i++ )
                //{
                //	body.Add( OutlineBodyInstancedEnd[ i ] );
                //}
                bool openCBuffer = true;
                if (customOutline)
                {
                    if (isShadowCaster)
                    {
                        for (int i = 0; i < UniformList.Count; i++)
                        {
                            dataCollector.AddToUniforms(UniformList[i].NodeId, UniformList[i].PropertyName);
                        }

                        foreach (KeyValuePair <string, string> kvp in m_localFunctions)
                        {
                            dataCollector.AddFunction(kvp.Key, kvp.Value);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Uniforms))
                        {
                            body.Add(Uniforms.Trim('\t', '\n'));
                        }

                        openCBuffer = false;
                        body.Add(string.Format(IOUtils.InstancedPropertiesBegin, shaderName));
                        if (!string.IsNullOrEmpty(InstancedProperties))
                        {
                            body.Add(InstancedProperties.Trim('\t', '\n'));
                        }
                    }
                }

                if (openCBuffer)
                {
                    body.Add(string.Format(IOUtils.InstancedPropertiesBegin, shaderName));
                }

                if (!dataCollector.UsingCustomOutlineColor)
                {
                    body.Add(precision == PrecisionType.Float ? OutlineDefaultUniformColorInstanced.Replace("half", "float") : OutlineDefaultUniformColorInstanced);
                }

                if (!dataCollector.UsingCustomOutlineWidth)
                {
                    body.Add(precision == PrecisionType.Float ? OutlineDefaultUniformWidthInstanced.Replace("half", "float") : OutlineDefaultUniformWidthInstanced);
                }

                body.Add(IOUtils.InstancedPropertiesEnd);

                //Functions
                if (customOutline && !isShadowCaster)
                {
                    body.Add(Functions);
                }

                if (tessOpHelper.EnableTesselation && !isShadowCaster)
                {
                    body.Add(tessOpHelper.Uniforms().TrimStart('\t'));
                    body.Add(tessOpHelper.GetCurrentTessellationFunction.Trim('\t', '\n') + "\n");
                }

                if (tessOpHelper.EnableTesselation)
                {
                    body.Add(OutlineTessVertexHeader);
                }
                else
                {
                    body.Add(OutlineDefaultVertexHeader);
                    body.Add(OutlineDefaultVertexOutputDeclaration);
                }

                if (customOutline)
                {
                    if (!string.IsNullOrEmpty(VertexData))
                    {
                        body.Add("\t" + VertexData.Trim('\t', '\n'));
                    }
                }

                if ((object)billboardInfo != null)
                {
                    for (int j = 0; j < billboardInfo.Length; j++)
                    {
                        body.Add(string.Format(BillboardInstructionFormat, billboardInfo[j]));
                    }
                }

                switch (outlineMode)
                {
                case 0: body.Add(string.Format(OutlineVertexOffsetMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyNameInstanced)); break;

                case 1: body.Add(string.Format(OutlineVertexScaleMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyNameInstanced)); break;

                case 2: body.Add(string.Format(OutlineVertexCustomMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyNameInstanced)); break;
                }

                for (int i = 0; i < OutlineBodyDefaultSurfBegin.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfBegin[i]);
                }
                if (dataCollector.UsingCustomOutlineColor || dataCollector.CustomOutlineSelectedAlpha > 0)
                {
                    body.Add("\t" + Instructions.Trim('\t', '\n'));
                }
                else
                {
                    for (int i = 0; i < OutlineSurfBodyInstanced.Length; i++)
                    {
                        body.Add(OutlineSurfBodyInstanced[i]);
                    }
                }

                for (int i = 0; i < OutlineBodyDefaultSurfEnd.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfEnd[i]);
                }
            }
            else
            {
                if (customOutline)
                {
                    if (isShadowCaster)
                    {
                        for (int i = 0; i < UniformList.Count; i++)
                        {
                            dataCollector.AddToUniforms(UniformList[i].NodeId, UniformList[i].PropertyName);
                        }

                        foreach (KeyValuePair <string, string> kvp in m_localFunctions)
                        {
                            dataCollector.AddFunction(kvp.Key, kvp.Value);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Uniforms))
                        {
                            body.Add(Uniforms.Trim('\t', '\n'));
                        }
                    }
                }

                if (!dataCollector.UsingCustomOutlineColor)
                {
                    body.Add(precision == PrecisionType.Float ? OutlineDefaultUniformColor.Replace("half", "float") : OutlineDefaultUniformColor);
                }

                if (!dataCollector.UsingCustomOutlineWidth)
                {
                    body.Add(precision == PrecisionType.Float ? OutlineDefaultUniformWidth.Replace("half", "float") : OutlineDefaultUniformWidth);
                }

                //Functions
                if (customOutline && !isShadowCaster)
                {
                    body.Add(Functions);
                }

                if (tessOpHelper.EnableTesselation && !isShadowCaster)
                {
                    body.Add(tessOpHelper.Uniforms().TrimStart('\t'));
                    body.Add(tessOpHelper.GetCurrentTessellationFunction.Trim('\t', '\n') + "\n");
                }

                if (tessOpHelper.EnableTesselation)
                {
                    body.Add(OutlineTessVertexHeader);
                }
                else
                {
                    body.Add(OutlineDefaultVertexHeader);
                    body.Add(OutlineDefaultVertexOutputDeclaration);
                }

                if (customOutline)
                {
                    if (!string.IsNullOrEmpty(VertexData))
                    {
                        body.Add("\t" + VertexData.Trim('\t', '\n'));
                    }
                }

                if ((object)billboardInfo != null)
                {
                    for (int j = 0; j < billboardInfo.Length; j++)
                    {
                        body.Add(string.Format(BillboardInstructionFormat, billboardInfo[j]));
                    }
                }

                switch (outlineMode)
                {
                case 0: body.Add(string.Format(OutlineVertexOffsetMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;

                case 1: body.Add(string.Format(OutlineVertexScaleMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;

                case 2: body.Add(string.Format(OutlineVertexCustomMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;
                }
                for (int i = 0; i < OutlineBodyDefaultSurfBegin.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfBegin[i]);
                }
                if (dataCollector.UsingCustomOutlineColor || dataCollector.CustomOutlineSelectedAlpha > 0)
                {
                    body.Add("\t" + Instructions.Trim('\t', '\n'));
                }
                else
                {
                    for (int i = 0; i < OutlineSurfBody.Length; i++)
                    {
                        body.Add(OutlineSurfBody[i]);
                    }
                }

                for (int i = 0; i < OutlineBodyDefaultSurfEnd.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfEnd[i]);
                }
            }

            string[] bodyArr = body.ToArray();
            body.Clear();
            body = null;
            return(bodyArr);
        }
Ejemplo n.º 2
0
        public string[] OutlineFunctionBody(ref MasterNodeDataCollector dataCollector, bool instanced, bool isShadowCaster, string shaderName, string[] billboardInfo, ref TessellationOpHelper tessOpHelper, string target)
        {
            List <string> body = new List <string>();

            for (int i = 0; i < OutlineBodyBegin.Length; i++)
            {
                body.Add(OutlineBodyBegin[i]);
            }
            if (tessOpHelper.EnableTesselation)
            {
                body.Add("#include \"" + TessellationOpHelper.TessInclude + "\"");
                body.Add("#pragma target " + target);
            }
            else
            {
                body.Add("#pragma target 3.0");
            }

            bool customOutline = dataCollector.UsingCustomOutlineColor || dataCollector.UsingCustomOutlineWidth;
            int  outlineMode   = customOutline ? m_offsetMode : (m_mode == OutlineMode.VertexOffset ? 0 : 1);

            string surfConfig = string.Format(OutlineSurfaceConfig, (customOutline ? m_customNoFog : m_noFog) ? "nofog " : string.Empty);

            if (tessOpHelper.EnableTesselation)
            {
                tessOpHelper.WriteToOptionalParams(ref surfConfig);
            }

            body.Add(surfConfig);

            if (instanced)
            {
                body.Add(OutlineInstancedHeader);
            }

            if (customOutline)
            {
                if (isShadowCaster)
                {
                    for (int i = 0; i < InputList.Count; i++)
                    {
                        dataCollector.AddToInput(InputList[i].NodeId, InputList[i].PropertyName, true);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_inputs))
                    {
                        body.Add(m_inputs.Trim('\t', '\n'));
                    }
                }

                if (!DirtyInput && !isShadowCaster)
                {
                    body.Add(OutlineBodyStructDefault);
                }

                if (!isShadowCaster)
                {
                    body.Add(OutlineBodyStructEnd);
                }
            }
            else if (!isShadowCaster)
            {
                body.Add(OutlineBodyStructBegin);
                body.Add(OutlineBodyStructDefault);
                body.Add(OutlineBodyStructEnd);
            }

            if (instanced)
            {
                for (int i = 0; i < OutlineBodyInstancedBegin.Length; i++)
                {
                    body.Add((i == 0) ? string.Format(OutlineBodyInstancedBegin[i], shaderName) : OutlineBodyInstancedBegin[i]);
                }

                if ((object)billboardInfo != null)
                {
                    for (int j = 0; j < billboardInfo.Length; j++)
                    {
                        body.Add(string.Format(BillboardInstructionFormat, billboardInfo[j]));
                    }
                }

                switch (outlineMode)
                {
                case 0: body.Add(string.Format(OutlineVertexOffsetMode, WidthVariableAccessInstanced)); break;

                case 1: body.Add(string.Format(OutlineVertexScaleMode, WidthVariableAccessInstanced)); break;

                case 2: body.Add(string.Format(OutlineVertexCustomMode, WidthVariableAccessInstanced)); break;
                }
                for (int i = 0; i < OutlineBodyInstancedEnd.Length; i++)
                {
                    body.Add(OutlineBodyInstancedEnd[i]);
                }
            }
            else
            {
                if (customOutline)
                {
                    if (isShadowCaster)
                    {
                        for (int i = 0; i < UniformList.Count; i++)
                        {
                            dataCollector.AddToUniforms(UniformList[i].NodeId, UniformList[i].PropertyName);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Uniforms))
                        {
                            body.Add(Uniforms.Trim('\t', '\n'));
                        }
                    }
                }

                if (!dataCollector.UsingCustomOutlineColor)
                {
                    body.Add(OutlineDefaultUniformColor);
                }
                if (!dataCollector.UsingCustomOutlineWidth)
                {
                    body.Add(OutlineDefaultUniformWidth);
                }

                //Functions
                if (customOutline)
                {
                    body.Add(Functions);
                }

                if (tessOpHelper.EnableTesselation && !isShadowCaster)
                {
                    body.Add(tessOpHelper.Uniforms().TrimStart('\t'));
                    body.Add(tessOpHelper.GetCurrentTessellationFunction.Trim('\t', '\n') + "\n");
                }

                if (tessOpHelper.EnableTesselation)
                {
                    body.Add(OutlineTessVertexHeader);
                }
                else
                {
                    body.Add(OutlineDefaultVertexHeader);
                    body.Add(OutlineDefaultVertexOutputDeclaration);
                }

                if (customOutline)
                {
                    if (!string.IsNullOrEmpty(VertexData))
                    {
                        body.Add("\t" + VertexData.Trim('\t', '\n'));
                    }
                }

                if ((object)billboardInfo != null)
                {
                    for (int j = 0; j < billboardInfo.Length; j++)
                    {
                        body.Add(string.Format(BillboardInstructionFormat, billboardInfo[j]));
                    }
                }

                switch (outlineMode)
                {
                case 0: body.Add(string.Format(OutlineVertexOffsetMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;

                case 1: body.Add(string.Format(OutlineVertexScaleMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;

                case 2: body.Add(string.Format(OutlineVertexCustomMode, dataCollector.UsingCustomOutlineWidth ? "outlineVar" : WidthPropertyName)); break;
                }
                for (int i = 0; i < OutlineBodyDefaultSurfBegin.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfBegin[i]);
                }
                if (dataCollector.UsingCustomOutlineColor)
                {
                    body.Add("\t" + Instructions.Trim('\t', '\n'));
                }
                else
                {
                    for (int i = 0; i < OutlineSurfBody.Length; i++)
                    {
                        body.Add(OutlineSurfBody[i]);
                    }
                }

                for (int i = 0; i < OutlineBodyDefaultSurfEnd.Length; i++)
                {
                    body.Add(OutlineBodyDefaultSurfEnd[i]);
                }
            }

            string[] bodyArr = body.ToArray();
            body.Clear();
            body = null;
            return(bodyArr);
        }