示例#1
0
 public static Task <byte[]> GenerateAsync(
     ShaderStage stage,
     Albedo albedo,
     Bump_Mapping bump_mapping,
     Alpha_Test alpha_test,
     Specular_Mask specular_mask,
     Material_Model material_model,
     Environment_Mapping environment_mapping,
     Self_Illumination self_illumination,
     Blend_Mode blend_mode,
     Parallax parallax,
     Misc misc,
     Distortion distortion,
     Soft_fade soft_fade
     )
 {
     return(Task.Run(() => GenerateShader(
                         stage,
                         albedo,
                         bump_mapping,
                         alpha_test,
                         specular_mask,
                         material_model,
                         environment_mapping,
                         self_illumination,
                         blend_mode,
                         parallax,
                         misc,
                         distortion,
                         soft_fade
                         )));
 }
 /// <summary>
 /// Generator instantiation for method specific shaders.
 /// </summary>
 public TerrainGenerator(Blending blending, Environment_Mapping environment_mapping, Material material_0, Material material_1, Material material_2, Material_No_Detail_Bump material_3)
 {
     this.blending            = blending;
     this.environment_mapping = environment_mapping;
     this.material_0          = material_0;
     this.material_1          = material_1;
     this.material_2          = material_2;
     this.material_3          = material_3;
     TemplateGenerationValid  = true;
 }
        public TerrainGenerator(byte[] options, bool applyFixes = false)
        {
            this.blending            = (Blending)options[0];
            this.environment_mapping = (Environment_Mapping)options[1];
            this.material_0          = (Material)options[2];
            this.material_1          = (Material)options[3];
            this.material_2          = (Material)options[4];
            this.material_3          = (Material_No_Detail_Bump)options[5];

            //ApplyFixes = applyFixes;
            TemplateGenerationValid = true;
        }
        public static ShaderGeneratorResult GenerateShader(
            ShaderStage stage,
            Albedo albedo,
            Bump_Mapping bump_mapping,
            Alpha_Test alpha_test,
            Specular_Mask specular_mask,
            Material_Model material_model,
            Environment_Mapping environment_mapping,
            Self_Illumination self_illumination,
            Blend_Mode blend_mode,
            Parallax parallax,
            Misc misc,
            Distortion distortion,
            Soft_fade soft_fade
            )
        {
            if (!HaloShaderGeneratorPrivate.IsBaseDLLLoaded)
            {
                return(null);
            }

            Type shadergeneratortype = HaloShaderGeneratorPrivate.HaloShaderGeneratorAssembly.ExportedTypes.Where(t => t.Name == "ShaderGenerator").FirstOrDefault();

            if (shadergeneratortype == null)
            {
                return(null);
            }

            var result = (byte[])shadergeneratortype.GetMethod("GenerateShader").Invoke(null, new object[] {
                stage,
                albedo,
                bump_mapping,
                alpha_test,
                specular_mask,
                material_model,
                environment_mapping,
                self_illumination,
                blend_mode,
                parallax,
                misc,
                distortion,
                soft_fade
            });

            if (result == null)
            {
                return(null);
            }

            return(new ShaderGeneratorResult(result));
        }
示例#5
0
        public CortanaGenerator(byte[] options, bool applyFixes = false)
        {
            this.albedo              = (Albedo)options[0];
            this.bump_mapping        = (Bump_Mapping)options[1];
            this.alpha_test          = (Alpha_Test)options[2];
            this.material_model      = (Material_Model)options[3];
            this.environment_mapping = (Environment_Mapping)options[4];
            this.warp         = (Warp)options[5];
            this.lighting     = (Lighting)options[6];
            this.scanlines    = (Scanlines)options[7];
            this.transparency = (Transparency)options[8];

            ApplyFixes = applyFixes;
            TemplateGenerationValid = true;
        }
示例#6
0
 /// <summary>
 /// Generator instantiation for method specific shaders.
 /// </summary>
 public CustomGenerator(Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Specular_Mask specular_mask, Material_Model material_model,
                        Environment_Mapping environment_mapping, Self_Illumination self_illumination, Blend_Mode blend_mode, Parallax parallax, Misc misc)
 {
     this.albedo              = albedo;
     this.bump_mapping        = bump_mapping;
     this.alpha_test          = alpha_test;
     this.specular_mask       = specular_mask;
     this.material_model      = material_model;
     this.environment_mapping = environment_mapping;
     this.self_illumination   = self_illumination;
     this.blend_mode          = blend_mode;
     this.parallax            = parallax;
     this.misc = misc;
     TemplateGenerationValid = true;
 }
示例#7
0
        public CortanaGenerator(Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Material_Model material_model,
                                Environment_Mapping environment_mapping, Warp warp, Lighting lighting, Scanlines scanlines, Transparency transparency, bool applyFixes = false)
        {
            this.albedo              = albedo;
            this.bump_mapping        = bump_mapping;
            this.alpha_test          = alpha_test;
            this.material_model      = material_model;
            this.environment_mapping = environment_mapping;
            this.warp         = warp;
            this.lighting     = lighting;
            this.scanlines    = scanlines;
            this.transparency = transparency;

            ApplyFixes = applyFixes;
            TemplateGenerationValid = true;
        }
示例#8
0
        public CustomGenerator(byte[] options, bool applyFixes = false)
        {
            this.albedo              = (Albedo)options[0];
            this.bump_mapping        = (Bump_Mapping)options[1];
            this.alpha_test          = (Alpha_Test)options[2];
            this.specular_mask       = (Specular_Mask)options[3];
            this.material_model      = (Material_Model)options[4];
            this.environment_mapping = (Environment_Mapping)options[5];
            this.self_illumination   = (Self_Illumination)options[6];
            this.blend_mode          = (Blend_Mode)options[7];
            this.parallax            = (Parallax)options[8];
            this.misc = (Misc)options[9];

            //ApplyFixes = applyFixes;
            TemplateGenerationValid = true;
        }
示例#9
0
        public static byte[] GenerateShader(
            ShaderStage stage,
            Albedo albedo,
            Bump_Mapping bump_mapping,
            Alpha_Test alpha_test,
            Specular_Mask specular_mask,
            Material_Model material_model,
            Environment_Mapping environment_mapping,
            Self_Illumination self_illumination,
            Blend_Mode blend_mode,
            Parallax parallax,
            Misc misc,
            Distortion distortion,
            Soft_fade soft_fade
            )
        {
            string template = $"shader.hlsl";

            List <D3D.SHADER_MACRO> macros = new List <D3D.SHADER_MACRO>();

            switch (stage)
            {
            //case ShaderStage.Default:
            case ShaderStage.Albedo:
            //case ShaderStage.Static_Per_Pixel:
            //case ShaderStage.Static_Per_Vertex:
            //case ShaderStage.Static_Sh:
            case ShaderStage.Static_Prt_Ambient:
            case ShaderStage.Static_Prt_Linear:
            case ShaderStage.Static_Prt_Quadratic:
            //case ShaderStage.Dynamic_Light:
            //case ShaderStage.Shadow_Generate:
            case ShaderStage.Active_Camo:
                //case ShaderStage.Lightmap_Debug_Mode:
                //case ShaderStage.Static_Per_Vertex_Color:
                //case ShaderStage.Dynamic_Light_Cinematic:
                //case ShaderStage.Sfx_Distort:
                break;

            default:
                return(null);
            }

            // prevent the definition helper from being included
            macros.Add(new D3D.SHADER_MACRO {
                Name = "_DEFINITION_HELPER_HLSLI", Definition = "1"
            });

            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderType>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Albedo>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bump_Mapping>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Alpha_Test>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Specular_Mask>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Material_Model>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Environment_Mapping>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Self_Illumination>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Blend_Mode>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Parallax>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Misc>());

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_ps", albedo, "calc_albedo_", "_ps"));
            if (albedo == Albedo.Constant_Color)
            {
                macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_vs", albedo, "calc_albedo_", "_vs"));
            }

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_bumpmap_ps", bump_mapping, "calc_bumpmap_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_bumpmap_vs", bump_mapping, "calc_bumpmap_", "_vs"));

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_alpha_test_ps", alpha_test, "calc_alpha_test_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_specular_mask_ps", specular_mask, "calc_specular_mask_", "_ps"));

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_self_illumination_ps", self_illumination, "calc_self_illumination_", "_ps"));

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_ps", parallax, "calc_parallax_", "_ps"));
            switch (parallax)
            {
            case Parallax.Simple_Detail:
                macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_vs", Parallax.Simple, "calc_parallax_", "_vs"));
                break;

            default:
                macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_vs", parallax, "calc_parallax_", "_vs"));
                break;
            }

            macros.Add(ShaderGeneratorBase.CreateMacro("material_type", material_model, "material_type_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type", environment_mapping, "envmap_type_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", blend_mode, "blend_type_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", stage, "shaderstage_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", stage, "shadertype_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("albedo_arg", albedo, "k_albedo_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("self_illumination_arg", self_illumination, "k_self_illumination_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("material_type_arg", material_model, "k_material_model_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type_arg", environment_mapping, "k_environment_mapping_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", blend_mode, "k_blend_mode_"));

            var shader_bytecode = ShaderGeneratorBase.GenerateSource(template, macros, "entry_" + stage.ToString().ToLower(), "ps_3_0");

            return(shader_bytecode);
        }