Beispiel #1
0
        public StageCode NewStage()
        {
            StageCode stage = new StageCode();

            Stages.Add(stage);
            return(stage);
        }
Beispiel #2
0
        public static string BuildShaderSource(QShaderData shader)
        {
            //devuelve el codigo del Fx
            ShaderCode shaderCode = new ShaderCode();


            shaderCode.AuxFuntions.Add(CreateSquareFunction());
            shaderCode.AuxFuntions.Add(CreateTriangleFunction());

            shaderCode.VsStruct.Add("float4 Pos : POSITION;");
            shaderCode.VsStruct.Add("float3 Normal : NORMAL;");
            shaderCode.VsStruct.Add("float4 Color : COLOR;");
            shaderCode.VsStruct.Add("float2 Tex0 : TEXCOORD0;");
            shaderCode.VsStruct.Add("float2 Tex1 : TEXCOORD1;");


            shaderCode.PsStruct.Add("float4 Pos : POSITION;");
            shaderCode.PsStruct.Add("float3 Normal : NORMAL;");
            shaderCode.PsStruct.Add("float4 Color : COLOR;");
            shaderCode.PsStruct.Add("float2 Tex0 : TEXCOORD0;");
            shaderCode.PsStruct.Add("float2 Tex1 : TEXCOORD1;");


            shaderCode.Globals.Add("float4x4 g_mWorld;// : WORLD;");
            shaderCode.Globals.Add("float4x4 g_mViewProj;// : VIEWPROJECTION;");
            shaderCode.Globals.Add("float g_time;// : TIME;");
            shaderCode.Globals.Add("sampler2D texture0 : register(s0);");
            shaderCode.Globals.Add("sampler2D texture1 : register(s1);");



            foreach (QShaderStage qstage in shader.Stages)
            {
                StageCode stageCode = shaderCode.NewStage();
                stageCode.VertexLines = BuildVertexShader(shader, qstage);
                stageCode.PixelLines  = BuildPixelShader(shader, qstage);
                stageCode.StatesLines = BuildEffectState(shader, qstage);
            }

            return(shaderCode.Build());
        }
Beispiel #3
0
        public string Build()
        {
            //genero el texto Propiamente diacho
            string ShaderText = "//prueba de generacion automatica de shaders\n";

            //agrego las variables globales
            foreach (string s in Globals)
            {
                ShaderText += s + "\n";
            }

            //Espacios
            ShaderText += "\n";
            ShaderText += "\n";

            //Estructura VSInput
            ShaderText += "struct VSInput\n";
            ShaderText += "{\n";
            foreach (string s in VsStruct)
            {
                ShaderText += "\t" + s + "\n";
            }
            ShaderText += "};\n";

            //Espacios
            ShaderText += "\n";
            ShaderText += "\n";

            //Estructura PSInput
            ShaderText += "struct PSInput\n";
            ShaderText += "{\n";
            foreach (string s in PsStruct)
            {
                ShaderText += "\t" + s + "\n";
            }
            ShaderText += "};\n";

            //Espacios
            ShaderText += "\n";
            ShaderText += "\n";

            //funciones auxiliares
            foreach (string s in AuxFuntions)
            {
                ShaderText += s + "\n";
            }

            for (int i = 0; i < Stages.Count; i++)
            {
                StageCode stage = Stages[i];

                //Espacios
                ShaderText += "\n";
                ShaderText += "\n";

                //Funcion del vertexShader
                ShaderText += "PSInput VertexShader" + i + "(VSInput In)\n";
                ShaderText += "{\n";
                foreach (string s in stage.VertexLines)
                {
                    ShaderText += "\t" + s + "\n";
                }
                ShaderText += "}\n";

                //Espacios
                ShaderText += "\n";
                ShaderText += "\n";

                //Funcion del PixelShader
                ShaderText += "float4 PixelShader" + i + "(PSInput In):COLOR\n";
                ShaderText += "{\n";
                foreach (string s in stage.PixelLines)
                {
                    ShaderText += "\t" + s + "\n";
                }
                ShaderText += "}\n";
            }


            //Espacios
            ShaderText += "\n";
            ShaderText += "\n";

            //Generacion de la tecnica
            ShaderText += "technique tec0\n";
            ShaderText += "{\n";
            for (int i = 0; i < Stages.Count; i++)
            {
                StageCode stage = Stages[i];

                if (i > 0)
                {
                    //Espacios
                    ShaderText += "\n";
                    ShaderText += "\n";
                }

                //genero la pasada
                ShaderText += "\tpass p" + i + "\n";
                ShaderText += "\t{\n";

                //seteo el estado de la pasada
                foreach (string s in stage.StatesLines)
                {
                    ShaderText += "\t\t" + s + "\n";
                }
                ShaderText += "\t\tVertexShader = compile vs_3_0 VertexShader" + i + "();\n";
                ShaderText += "\t\tPixelShader = compile ps_3_0 PixelShader" + i + "();\n";
                ShaderText += "\t}\n";
            }
            ShaderText += "}\n";


            return(ShaderText);
        }
Beispiel #4
0
 public StageCode NewStage()
 {
     StageCode stage = new StageCode();
     Stages.Add(stage);
     return stage;
 }