Exemple #1
0
        public static void WriteVertexShaders(EffectCodeGenerator generator,
                                              TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            Dictionary <string, List <string> > exports = new Dictionary <string, List <string> >();

            pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WriteVertexShader(codeGenerator, symbol, s, exports));

            ScriptTextWriter writer = generator.Writer;

            // Write one vertex shader for each technique pass.
            writer.WriteLine("// -------- technique {0}, pass {1} vertex shader entrypoint --------", technique.Name, pass.Name);
            writer.WriteLine("{0}_VERTEXOUTPUT {0}_vs(const {0}_VERTEXINPUT i)", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tgVertexInput_{0} = i;", uniquePassName);
            writer.WriteLine();
            writer.WriteLine("\t{0}_VERTEXOUTPUT output = ({0}_VERTEXOUTPUT) 0;", uniquePassName);
            writer.WriteLine();

            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_vs(gVertexInput_{0}.{1}, output);", uniquePassName, f.UniqueName));

            writer.WriteLine();
            writer.WriteLine("\treturn output;");
            writer.WriteLine("}");
            writer.WriteLine();
        }
		public static void GenerateExportDeclarations(EffectCodeGenerator generator, List<ExportedValue> exportedValues)
		{
			generator.Writer.WriteLine("// exported values");
			exportedValues.ForEach(ev => generator.Writer.WriteLine("static {0} {1}; // exported value", ev.Type, ev.Name));
			generator.Writer.WriteLine();
			generator.Writer.WriteLine();
		}
		private static void WriteVertexShader(EffectCodeGenerator generator, StitchedFragmentSymbol fragment,
			string uniquePassName, Dictionary<string, List<string>> exports)
		{
			ScriptTextWriter writer = generator.Writer;

			writer.WriteLine("// -------- vertex shader {0} --------", fragment.UniqueName);

			ShaderCodeBlockNode shader = fragment.FragmentNode.VertexShaders.GetCodeBlock(generator.Context.TargetShaderProfile);

			if (shader != null)
			{
				string shaderCode = StitchedEffectPreProcessor.PreProcessCodeBlock(fragment.UniqueName, shader, exports);
				shaderCode = ReplaceOutputCalls(shaderCode, fragment.UniqueName);
				WriteShaderCode(generator, fragment, shaderCode, "VERTEXINPUT", "VERTEXOUTPUT", "vs", uniquePassName);
			}
			else
			{
				// Need to auto-generate vertex shader. Simply pass through all vertex inputs.
				writer.WriteLine("void {0}_{1}_vs({0}_{1}_VERTEXINPUT input, inout {0}_VERTEXOUTPUT output)", uniquePassName, fragment.UniqueName);
				writer.WriteLine("{");
				writer.Write(GetVertexPassThroughCode(fragment));
				writer.WriteLine("}");
			}

			writer.WriteLine();
			writer.WriteLine();
		}
Exemple #4
0
        private static void WriteVertexShader(EffectCodeGenerator generator, StitchedFragmentSymbol fragment,
                                              string uniquePassName, Dictionary <string, List <string> > exports)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- vertex shader {0} --------", fragment.UniqueName);

            ShaderCodeBlockNode shader = fragment.FragmentNode.VertexShaders.GetCodeBlock(generator.Context.TargetShaderProfile);

            if (shader != null)
            {
                string shaderCode = StitchedEffectPreProcessor.PreProcessCodeBlock(fragment.UniqueName, shader, exports);
                shaderCode = ReplaceOutputCalls(shaderCode, fragment.UniqueName);
                WriteShaderCode(generator, fragment, shaderCode, "VERTEXINPUT", "VERTEXOUTPUT", "vs", uniquePassName);
            }
            else
            {
                // Need to auto-generate vertex shader. Simply pass through all vertex inputs.
                writer.WriteLine("void {0}_{1}_vs({0}_{1}_VERTEXINPUT input, inout {0}_VERTEXOUTPUT output)", uniquePassName, fragment.UniqueName);
                writer.WriteLine("{");
                writer.Write(GetVertexPassThroughCode(fragment));
                writer.WriteLine("}");
            }

            writer.WriteLine();
            writer.WriteLine();
        }
Exemple #5
0
 public static void GenerateExportDeclarations(EffectCodeGenerator generator, List <ExportedValue> exportedValues)
 {
     generator.Writer.WriteLine("// exported values");
     exportedValues.ForEach(ev => generator.Writer.WriteLine("static {0} {1}; // exported value", ev.Type, ev.Name));
     generator.Writer.WriteLine();
     generator.Writer.WriteLine();
 }
Exemple #6
0
        private static void WritePixelShaders(EffectCodeGenerator generator,
                                              TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            Dictionary <string, List <string> > exports = new Dictionary <string, List <string> >();

            pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WritePixelShader(codeGenerator, symbol, s, exports));

            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- technique {0}, pass {1} pixel shader entrypoint --------", technique.Name, pass.Name);
            writer.WriteLine("{0}_PIXELOUTPUT {0}_ps(const {0}_PIXELINPUT i)", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tgPixelInput_{0} = i;", uniquePassName);
            writer.WriteLine();
            writer.WriteLine("\t{0}_PIXELOUTPUT output = ({0}_PIXELOUTPUT) 0;", uniquePassName);
            writer.WriteLine();
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                ShaderCodeBlockNode shader = f.FragmentNode.PixelShaders.GetCodeBlock(generator.Context.TargetShaderProfile);
                if (shader != null)
                {
                    writer.WriteLine("\t{0}_{1}_ps(gPixelInput_{0}.{1}, output);", uniquePassName, f.UniqueName);
                }
            });
            writer.WriteLine();
            writer.WriteLine("\treturn output;");
            writer.WriteLine("}");
            writer.WriteLine();
        }
 public static void GenerateAllTechniques(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect,
                                          bool generateVertexShader)
 {
     foreach (TechniqueSymbol technique in stitchedEffect.Techniques)
     {
         GenerateTechnique(generator, technique, generateVertexShader);
     }
 }
		private static void WriteParams(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
		{
			if (stitchedFragment.FragmentNode.Parameters == null || !stitchedFragment.FragmentNode.Parameters.VariableDeclarations.Any())
				return;

			generator.Writer.WriteLine("// {0} params", stitchedFragment.UniqueName);
			stitchedFragment.FragmentNode.Parameters.VariableDeclarations.ForEach(p => generator.Writer.WriteLine(generator.GetVariableDeclaration(stitchedFragment, p)));
			generator.Writer.WriteLine();
		}
		private static void GenerateHeaderCode(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
		{
			if (stitchedFragment.FragmentNode.HeaderCode == null || string.IsNullOrEmpty(stitchedFragment.FragmentNode.HeaderCode.Code))
				return;

			generator.Writer.WriteLine("// {0} header code", stitchedFragment.UniqueName);
			generator.Writer.Write(stitchedFragment.FragmentNode.HeaderCode.Code.Replace("\r", Environment.NewLine));
			generator.Writer.WriteLine();
			generator.Writer.WriteLine();
		}
		public static void GenerateAllHeaderCode(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
		{
			List<string> seenFragmentTypes = new List<string>();
			foreach (StitchedFragmentSymbol stitchedFragmentNode in stitchedEffect.StitchedFragments)
			{
				if (seenFragmentTypes.Contains(stitchedFragmentNode.FragmentNode.Name))
					continue;
				GenerateHeaderCode(generator, stitchedFragmentNode);
				seenFragmentTypes.Add(stitchedFragmentNode.FragmentNode.Name);
			}
		}
Exemple #11
0
        private static void WriteParams(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
        {
            if (stitchedFragment.FragmentNode.Parameters == null || !stitchedFragment.FragmentNode.Parameters.VariableDeclarations.Any())
            {
                return;
            }

            generator.Writer.WriteLine("// {0} params", stitchedFragment.UniqueName);
            stitchedFragment.FragmentNode.Parameters.VariableDeclarations.ForEach(p => generator.Writer.WriteLine(generator.GetVariableDeclaration(stitchedFragment, p)));
            generator.Writer.WriteLine();
        }
Exemple #12
0
        private static void GenerateHeaderCode(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
        {
            if (stitchedFragment.FragmentNode.HeaderCode == null || string.IsNullOrEmpty(stitchedFragment.FragmentNode.HeaderCode.Code))
            {
                return;
            }

            generator.Writer.WriteLine("// {0} header code", stitchedFragment.UniqueName);
            generator.Writer.Write(stitchedFragment.FragmentNode.HeaderCode.Code.Replace("\r", Environment.NewLine));
            generator.Writer.WriteLine();
            generator.Writer.WriteLine();
        }
		private static void GenerateTechnique(EffectCodeGenerator generator, TechniqueSymbol technique,
			bool generateVertexShader)
		{
			ScriptTextWriter writer = generator.Writer;
			writer.WriteLine("// -------- technique {0} --------", technique.Name);
			writer.WriteLine("technique {0}", technique.Name);
			writer.WriteLine("{");

			foreach (TechniquePassSymbol pass in technique.Passes)
				GeneratePass(generator, technique, pass, generateVertexShader);

			writer.WriteLine("};");
		}
		private static void WriteSamplers(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
		{
			if (stitchedFragment.FragmentNode.Textures == null || !stitchedFragment.FragmentNode.Textures.VariableDeclarations.Any())
				return;

			generator.Writer.WriteLine("// {0} textures", stitchedFragment.UniqueName);
			stitchedFragment.FragmentNode.Textures.VariableDeclarations.ForEach(t =>
			{
				generator.Writer.WriteLine(generator.GetVariableDeclaration(stitchedFragment, t));
				generator.Writer.WriteLine("sampler {0}_{1}_sampler = sampler_state {{ Texture = ({0}_{1}); }};",
					stitchedFragment.UniqueName, t.Name);
			});
			generator.Writer.WriteLine();
		}
Exemple #15
0
        public static void GenerateAllHeaderCode(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
        {
            List <string> seenFragmentTypes = new List <string>();

            foreach (StitchedFragmentSymbol stitchedFragmentNode in stitchedEffect.StitchedFragments)
            {
                if (seenFragmentTypes.Contains(stitchedFragmentNode.FragmentNode.Name))
                {
                    continue;
                }
                GenerateHeaderCode(generator, stitchedFragmentNode);
                seenFragmentTypes.Add(stitchedFragmentNode.FragmentNode.Name);
            }
        }
		private static void GeneratePass(EffectCodeGenerator generator, TechniqueSymbol technique, TechniquePassSymbol pass,
			bool generateVertexShader)
		{
			ScriptTextWriter writer = generator.Writer;
			writer.WriteLine("\tpass {0}", pass.Name);
			writer.WriteLine("\t{");
			if (generateVertexShader)
				writer.WriteLine("\t\tVertexShader = compile vs_{0} {1}_{2}_vs();",
					generator.Context.TargetShaderProfile.GetDescription(),
					technique.Name, pass.Name);
			writer.WriteLine("\t\tPixelShader = compile ps_{0} {1}_{2}_ps();",
				generator.Context.TargetShaderProfile.GetDescription(),
				technique.Name, pass.Name);
			writer.WriteLine("\t}");
		}
		private static void WritePixelInputStructs(EffectCodeGenerator generator, 
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			generator.Writer.WriteLine("// -------- pixel input structures --------");

			SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");
			pass.ForEachFragment(generator, (g, f, s) => WritePixelInputStructure(g, f, s, semanticGenerator));

			generator.Writer.WriteLine("struct {0}_PIXELINPUT", uniquePassName);
			generator.Writer.WriteLine("{");
			pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", s, f.UniqueName));
			generator.Writer.WriteLine("};");
			generator.Writer.WriteLine();
			generator.Writer.WriteLine("static {0}_PIXELINPUT gPixelInput_{0};", uniquePassName);
			generator.Writer.WriteLine();
		}
Exemple #18
0
        private static void GenerateTechnique(EffectCodeGenerator generator, TechniqueSymbol technique,
                                              bool generateVertexShader)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- technique {0} --------", technique.Name);
            writer.WriteLine("technique {0}", technique.Name);
            writer.WriteLine("{");

            foreach (TechniquePassSymbol pass in technique.Passes)
            {
                GeneratePass(generator, technique, pass, generateVertexShader);
            }

            writer.WriteLine("};");
        }
Exemple #19
0
        private static void WriteSamplers(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment)
        {
            if (stitchedFragment.FragmentNode.Textures == null || !stitchedFragment.FragmentNode.Textures.VariableDeclarations.Any())
            {
                return;
            }

            generator.Writer.WriteLine("// {0} textures", stitchedFragment.UniqueName);
            stitchedFragment.FragmentNode.Textures.VariableDeclarations.ForEach(t =>
            {
                generator.Writer.WriteLine(generator.GetVariableDeclaration(stitchedFragment, t));
                generator.Writer.WriteLine("sampler {0}_{1}_sampler = sampler_state {{ Texture = ({0}_{1}); }};",
                                           stitchedFragment.UniqueName, t.Name);
            });
            generator.Writer.WriteLine();
        }
Exemple #20
0
        private static void WritePixelInputStructs(EffectCodeGenerator generator,
                                                   TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            generator.Writer.WriteLine("// -------- pixel input structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");

            pass.ForEachFragment(generator, (g, f, s) => WritePixelInputStructure(g, f, s, semanticGenerator));

            generator.Writer.WriteLine("struct {0}_PIXELINPUT", uniquePassName);
            generator.Writer.WriteLine("{");
            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", s, f.UniqueName));
            generator.Writer.WriteLine("};");
            generator.Writer.WriteLine();
            generator.Writer.WriteLine("static {0}_PIXELINPUT gPixelInput_{0};", uniquePassName);
            generator.Writer.WriteLine();
        }
Exemple #21
0
        private static void WritePixelShader(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment,
                                             string uniquePassName, Dictionary <string, List <string> > exports)
        {
            ShaderCodeBlockNode codeBlock = stitchedFragment.FragmentNode.PixelShaders.GetCodeBlock(generator.Context.TargetShaderProfile);

            if (codeBlock != null)
            {
                generator.Writer.WriteLine("// -------- pixel shader {0} --------", stitchedFragment.UniqueName);

                string shaderCode = StitchedEffectPreProcessor.PreProcessCodeBlock(stitchedFragment.UniqueName, codeBlock, exports);
                shaderCode = ReplaceOutputCalls(shaderCode, stitchedFragment.UniqueName);
                WriteShaderCode(generator, stitchedFragment, shaderCode, "PIXELINPUT", "PIXELOUTPUT", "ps", uniquePassName);

                generator.Writer.WriteLine();
                generator.Writer.WriteLine();
            }
        }
Exemple #22
0
        private static void GeneratePass(EffectCodeGenerator generator, TechniqueSymbol technique, TechniquePassSymbol pass,
                                         bool generateVertexShader)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("\tpass {0}", pass.Name);
            writer.WriteLine("\t{");
            if (generateVertexShader)
            {
                writer.WriteLine("\t\tVertexShader = compile vs_{0} {1}_{2}_vs();",
                                 generator.Context.TargetShaderProfile.GetDescription(),
                                 technique.Name, pass.Name);
            }
            writer.WriteLine("\t\tPixelShader = compile ps_{0} {1}_{2}_ps();",
                             generator.Context.TargetShaderProfile.GetDescription(),
                             technique.Name, pass.Name);
            writer.WriteLine("\t}");
        }
Exemple #23
0
        private static void WriteVertexOutputStructs(EffectCodeGenerator generator,
                                                     TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- vertex output structures --------");
            writer.WriteLine("struct {0}_VERTEXOUTPUT", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tfloat4 position : POSITION;");
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                if (f.FragmentNode.Interpolators != null && f.FragmentNode.Interpolators.VariableDeclarations.Any())
                {
                    g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", uniquePassName, f.UniqueName);
                }
            });
            writer.WriteLine("};");
            writer.WriteLine();
        }
		private static void WritePixelOutputStructs(EffectCodeGenerator generator,
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			ScriptTextWriter writer = generator.Writer;
			writer.WriteLine("// -------- pixel output structures --------");

			SemanticGenerator semanticGenerator = new SemanticGenerator("COLOR", 1);
			pass.ForEachFragment(generator, (g, f, n) => WritePixelOutputStructure(g, f, n, semanticGenerator));

			writer.WriteLine("struct {0}_PIXELOUTPUT", uniquePassName);
			writer.WriteLine("{");
			writer.WriteLine("\tfloat4 color : COLOR0;");
			pass.ForEachFragment(generator, (g, f, s) =>
			{
				if (f.FragmentNode.PixelOutputs != null && f.FragmentNode.PixelOutputs.VariableDeclarations.Any())
					writer.WriteLine("\t{0}_{1}_PIXELOUTPUT {1};", s, f.UniqueName);
			});
			writer.WriteLine("};");
			writer.WriteLine();
		}
		private static void WriteVertexInputStructures(EffectCodeGenerator generator, 
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			ScriptTextWriter writer = generator.Writer;

			writer.WriteLine("// -------- vertex input structures --------");

			SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");
			pass.ForEachFragment(generator, (g, f, s) => WriteVertexInputStructure(g, f, s, semanticGenerator));

			writer.WriteLine("struct {0}_VERTEXINPUT", uniquePassName);
			writer.WriteLine("{");

			pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_VERTEXINPUT {1};", uniquePassName, f.UniqueName));

			writer.WriteLine("};");
			writer.WriteLine();
			writer.WriteLine("static {0}_VERTEXINPUT gVertexInput_{0};", uniquePassName);
			writer.WriteLine();
		}
Exemple #26
0
        private static void WriteShaderStructure(EffectCodeGenerator generator,
                                                 StitchedFragmentSymbol stitchedFragment, string uniquePassName, SemanticGenerator semanticGenerator,
                                                 string structSuffix, ParameterBlockNode parameterBlock)
        {
            generator.Writer.WriteLine("struct {0}_{1}_{2}", uniquePassName, stitchedFragment.UniqueName, structSuffix);
            generator.Writer.WriteLine("{");

            if (parameterBlock != null)
            {
                parameterBlock.VariableDeclarations.ForEach(v =>
                {
                    string semantic = semanticGenerator.GetNextSemantic(v);
                    generator.Writer.WriteLine("\t{0} {1} : {2};",
                                               Token.GetString(v.DataType), v.Name, semantic);
                });
            }

            generator.Writer.WriteLine("};");
            generator.Writer.WriteLine();
        }
Exemple #27
0
        private static void WriteVertexInputStructures(EffectCodeGenerator generator,
                                                       TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- vertex input structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");

            pass.ForEachFragment(generator, (g, f, s) => WriteVertexInputStructure(g, f, s, semanticGenerator));

            writer.WriteLine("struct {0}_VERTEXINPUT", uniquePassName);
            writer.WriteLine("{");

            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_VERTEXINPUT {1};", uniquePassName, f.UniqueName));

            writer.WriteLine("};");
            writer.WriteLine();
            writer.WriteLine("static {0}_VERTEXINPUT gVertexInput_{0};", uniquePassName);
            writer.WriteLine();
        }
Exemple #28
0
        private static void WriteShaderCode(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string shaderCode,
                                            string inputStructName, string outputStructName, string functionSuffix, string uniquePassName)
        {
            string mangledCode = shaderCode;

            // Replace interpolators and sampler names which are used in the code with the mangled names.
            mangledCode = ReplaceVariableNames(stitchedFragment, stitchedFragment.FragmentNode.Parameters, mangledCode);
            //mangledCode = ReplaceVariableNames(stitchedFragment, stitchedFragment.FragmentNode.Interpolators, mangledCode);
            if (stitchedFragment.FragmentNode.Textures != null)
            {
                stitchedFragment.FragmentNode.Textures.VariableDeclarations.ForEach(t =>
                                                                                    mangledCode = Regex.Replace(mangledCode, @"(\W)(" + t.Name + @")(\W)", "$1" + stitchedFragment.UniqueName + "_$2_sampler$3"));
            }

            mangledCode = mangledCode.Replace("void main(", string.Format("void {0}_{1}_{2}(", uniquePassName, stitchedFragment.UniqueName, functionSuffix));

            // This is just here to support surface shaders. Ideally it would be done somewhere else.
            mangledCode = Regex.Replace(mangledCode, @"(\b)surface\(", string.Format("$1{0}_{1}_{2}_surface(", uniquePassName, stitchedFragment.UniqueName, functionSuffix));

            mangledCode = mangledCode.Replace("INPUT", string.Format("{0}_{1}_{2}", uniquePassName, stitchedFragment.UniqueName, inputStructName));
            mangledCode = mangledCode.Replace("OUTPUT", uniquePassName + "_" + outputStructName);

            generator.Writer.Write(mangledCode.Replace("\r", Environment.NewLine));
        }
		public static void WriteVertexShaders(EffectCodeGenerator generator, 
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			Dictionary<string, List<string>> exports = new Dictionary<string, List<string>>();
			pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WriteVertexShader(codeGenerator, symbol, s, exports));

			ScriptTextWriter writer = generator.Writer;

			// Write one vertex shader for each technique pass.
			writer.WriteLine("// -------- technique {0}, pass {1} vertex shader entrypoint --------", technique.Name, pass.Name);
			writer.WriteLine("{0}_VERTEXOUTPUT {0}_vs(const {0}_VERTEXINPUT i)", uniquePassName);
			writer.WriteLine("{");
			writer.WriteLine("\tgVertexInput_{0} = i;", uniquePassName);
			writer.WriteLine();
			writer.WriteLine("\t{0}_VERTEXOUTPUT output = ({0}_VERTEXOUTPUT) 0;", uniquePassName);
			writer.WriteLine();

			pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_vs(gVertexInput_{0}.{1}, output);", uniquePassName, f.UniqueName));

			writer.WriteLine();
			writer.WriteLine("\treturn output;");
			writer.WriteLine("}");
			writer.WriteLine();
		}
Exemple #30
0
        private static void WritePixelOutputStructs(EffectCodeGenerator generator,
                                                    TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- pixel output structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("COLOR", 1);

            pass.ForEachFragment(generator, (g, f, n) => WritePixelOutputStructure(g, f, n, semanticGenerator));

            writer.WriteLine("struct {0}_PIXELOUTPUT", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tfloat4 color : COLOR0;");
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                if (f.FragmentNode.PixelOutputs != null && f.FragmentNode.PixelOutputs.VariableDeclarations.Any())
                {
                    writer.WriteLine("\t{0}_{1}_PIXELOUTPUT {1};", s, f.UniqueName);
                }
            });
            writer.WriteLine("};");
            writer.WriteLine();
        }
		public static void WriteAllPixelOutputStructs(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
		{
			generator.ForEachPass(WritePixelOutputStructs);
		}
		private static void WriteVertexInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator)
		{
			WriteShaderInputStructure(generator, stitchedFragment, uniqueName, semanticGenerator, "VERTEXINPUT", stitchedFragment.FragmentNode.VertexAttributes, false);
		}
		private static void WritePixelInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator)
		{
			WriteShaderInputStructure(generator, stitchedFragment, uniqueName, semanticGenerator, "PIXELINPUT", stitchedFragment.FragmentNode.Interpolators, true);
		}
		public static void GenerateAllTechniques(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect,
			bool generateVertexShader)
		{
			foreach (TechniqueSymbol technique in stitchedEffect.Techniques)
				GenerateTechnique(generator, technique, generateVertexShader);
		}
		internal void ForEachFragment(EffectCodeGenerator generator, Action<EffectCodeGenerator, StitchedFragmentSymbol, string> action)
		{
			foreach (StitchedFragmentSymbol stitchedFragmentNode in Fragments)
				action(generator, stitchedFragmentNode, string.Format("{0}_{1}", Technique.Name, Name));
		}
		private static void WriteShaderInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator, string structSuffix,
			ParameterBlockNode parameterBlock, bool alwaysUseTexCoords)
		{
			WriteShaderStructure(generator, stitchedFragment, uniqueName, semanticGenerator, structSuffix, parameterBlock);
		}
Exemple #37
0
 private static void WriteShaderInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator, string structSuffix,
                                               ParameterBlockNode parameterBlock, bool alwaysUseTexCoords)
 {
     WriteShaderStructure(generator, stitchedFragment, uniqueName, semanticGenerator, structSuffix, parameterBlock);
 }
		private static void WriteShaderStructure(EffectCodeGenerator generator,
			StitchedFragmentSymbol stitchedFragment, string uniquePassName, SemanticGenerator semanticGenerator,
			string structSuffix, ParameterBlockNode parameterBlock)
		{
			generator.Writer.WriteLine("struct {0}_{1}_{2}", uniquePassName, stitchedFragment.UniqueName, structSuffix);
			generator.Writer.WriteLine("{");

			if (parameterBlock != null)
				parameterBlock.VariableDeclarations.ForEach(v =>
				{
					string semantic = semanticGenerator.GetNextSemantic(v);
					generator.Writer.WriteLine("\t{0} {1} : {2};",
						Token.GetString(v.DataType), v.Name, semantic);
				});

			generator.Writer.WriteLine("};");
			generator.Writer.WriteLine();
		}
Exemple #39
0
 private static void WriteVertexInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator)
 {
     WriteShaderInputStructure(generator, stitchedFragment, uniqueName, semanticGenerator, "VERTEXINPUT", stitchedFragment.FragmentNode.VertexAttributes, false);
 }
Exemple #40
0
 public static void WriteAllPixelOutputStructs(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WritePixelOutputStructs);
 }
Exemple #41
0
 public static void WriteAllPixelShaders(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WritePixelShaders);
 }
Exemple #42
0
 public static void GenerateAllParameters(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachFragment(WriteParams);
 }
Exemple #43
0
 private static void WritePixelInputStructure(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string uniqueName, SemanticGenerator semanticGenerator)
 {
     WriteShaderInputStructure(generator, stitchedFragment, uniqueName, semanticGenerator, "PIXELINPUT", stitchedFragment.FragmentNode.Interpolators, true);
 }
		private static void WriteShaderCode(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment, string shaderCode,
			string inputStructName, string outputStructName, string functionSuffix, string uniquePassName)
		{
			string mangledCode = shaderCode;

			// Replace interpolators and sampler names which are used in the code with the mangled names.
			mangledCode = ReplaceVariableNames(stitchedFragment, stitchedFragment.FragmentNode.Parameters, mangledCode);
			//mangledCode = ReplaceVariableNames(stitchedFragment, stitchedFragment.FragmentNode.Interpolators, mangledCode);
			if (stitchedFragment.FragmentNode.Textures != null)
				stitchedFragment.FragmentNode.Textures.VariableDeclarations.ForEach(t =>
					mangledCode = Regex.Replace(mangledCode, @"(\W)(" + t.Name + @")(\W)", "$1" + stitchedFragment.UniqueName + "_$2_sampler$3"));

			mangledCode = mangledCode.Replace("void main(", string.Format("void {0}_{1}_{2}(", uniquePassName, stitchedFragment.UniqueName, functionSuffix));

			// This is just here to support surface shaders. Ideally it would be done somewhere else.
			mangledCode = Regex.Replace(mangledCode, @"(\b)surface\(", string.Format("$1{0}_{1}_{2}_surface(", uniquePassName, stitchedFragment.UniqueName, functionSuffix));

			mangledCode = mangledCode.Replace("INPUT", string.Format("{0}_{1}_{2}", uniquePassName, stitchedFragment.UniqueName, inputStructName));
			mangledCode = mangledCode.Replace("OUTPUT", uniquePassName + "_" + outputStructName);

			generator.Writer.Write(mangledCode.Replace("\r", Environment.NewLine));
		}
Exemple #45
0
 public static void WriteAllVertexInputStructures(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WriteVertexInputStructures);
 }
		private static void WritePixelShader(EffectCodeGenerator generator, StitchedFragmentSymbol stitchedFragment,
			string uniquePassName, Dictionary<string, List<string>> exports)
		{
			ShaderCodeBlockNode codeBlock = stitchedFragment.FragmentNode.PixelShaders.GetCodeBlock(generator.Context.TargetShaderProfile);
			if (codeBlock != null)
			{
				generator.Writer.WriteLine("// -------- pixel shader {0} --------", stitchedFragment.UniqueName);

				string shaderCode = StitchedEffectPreProcessor.PreProcessCodeBlock(stitchedFragment.UniqueName, codeBlock, exports);
				shaderCode = ReplaceOutputCalls(shaderCode, stitchedFragment.UniqueName);
				WriteShaderCode(generator, stitchedFragment, shaderCode, "PIXELINPUT", "PIXELOUTPUT", "ps", uniquePassName);

				generator.Writer.WriteLine();
				generator.Writer.WriteLine();
			}
		}
		private static void WriteVertexOutputStructs(EffectCodeGenerator generator, 
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			ScriptTextWriter writer = generator.Writer;

			writer.WriteLine("// -------- vertex output structures --------");
			writer.WriteLine("struct {0}_VERTEXOUTPUT", uniquePassName);
			writer.WriteLine("{");
			writer.WriteLine("\tfloat4 position : POSITION;");
			pass.ForEachFragment(generator, (g, f, s) =>
			{
				if (f.FragmentNode.Interpolators != null && f.FragmentNode.Interpolators.VariableDeclarations.Any())
					g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", uniquePassName, f.UniqueName);
			});
			writer.WriteLine("};");
			writer.WriteLine();
		}
		public static void WriteAllVertexInputStructures(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
		{
			generator.ForEachPass(WriteVertexInputStructures);
		}
		public static void WriteAllVertexShaders(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
		{
			generator.ForEachPass(WriteVertexShaders);
		}
		public static void GenerateAllSamplers(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
		{
			generator.ForEachFragment(WriteSamplers);
		}
		private static void WritePixelShaders(EffectCodeGenerator generator, 
			TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
		{
			Dictionary<string, List<string>> exports = new Dictionary<string, List<string>>();
			pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WritePixelShader(codeGenerator, symbol, s, exports));

			ScriptTextWriter writer = generator.Writer;
			writer.WriteLine("// -------- technique {0}, pass {1} pixel shader entrypoint --------", technique.Name, pass.Name);
			writer.WriteLine("{0}_PIXELOUTPUT {0}_ps(const {0}_PIXELINPUT i)", uniquePassName);
			writer.WriteLine("{");
			writer.WriteLine("\tgPixelInput_{0} = i;", uniquePassName);
			writer.WriteLine();
			writer.WriteLine("\t{0}_PIXELOUTPUT output = ({0}_PIXELOUTPUT) 0;", uniquePassName);
			writer.WriteLine();
			pass.ForEachFragment(generator, (g, f, s) =>
			{
				ShaderCodeBlockNode shader = f.FragmentNode.PixelShaders.GetCodeBlock(generator.Context.TargetShaderProfile);
				if (shader != null)
					writer.WriteLine("\t{0}_{1}_ps(gPixelInput_{0}.{1}, output);", uniquePassName, f.UniqueName);
			});
			writer.WriteLine();
			writer.WriteLine("\treturn output;");
			writer.WriteLine("}");
			writer.WriteLine();
		}