Пример #1
0
        public ShaderGeneratorResult GeneratePixelShader(ShaderStage entryPoint)
        {
            if (!TemplateGenerationValid)
            {
                throw new System.Exception("Generator initialized with shared shader constructor. Use template constructor.");
            }

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

            macros.Add(new D3D.SHADER_MACRO {
                Name = "_DEFINITION_HELPER_HLSLI", Definition = "1"
            });
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Albedo>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bump_Mapping>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Alpha_Test>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Specular_Mask>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Material_Model>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Environment_Mapping>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Self_Illumination>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Blend_Mode>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Parallax>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Misc>());

            //
            // Convert to shared enum
            //

            var sAlbedo             = Enum.Parse(typeof(Shared.Albedo), albedo.ToString());
            var sAlphaTest          = Enum.Parse(typeof(Shared.Alpha_Test), alpha_test.ToString());
            var sMaterialModel      = Enum.Parse(typeof(Shared.Material_Model), material_model.ToString());
            var sEnvironmentMapping = Enum.Parse(typeof(Shared.Environment_Mapping), environment_mapping.ToString());
            var sSelfIllumination   = Enum.Parse(typeof(Shared.Self_Illumination), self_illumination.ToString());
            var sBlendMode          = Enum.Parse(typeof(Shared.Blend_Mode), blend_mode.ToString());

            //
            // The following code properly names the macros (like in rmdf)
            //

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

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_alpha_test_ps", sAlphaTest, "calc_alpha_test_", "_ps"));

            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_specular_mask_ps", specular_mask, "calc_", "_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("calc_self_illumination_ps", sSelfIllumination, "calc_self_illumination_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_material_analytic_specular", sMaterialModel, "calc_material_analytic_specular_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_material_area_specular", sMaterialModel, "calc_material_area_specular_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_lighting_ps", sMaterialModel, "calc_lighting_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("calc_dynamic_lighting_ps", sMaterialModel, "calc_dynamic_lighting_", "_ps"));

            macros.Add(ShaderGeneratorBase.CreateMacro("material_type", sMaterialModel, "material_type_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type", sEnvironmentMapping, "envmap_type_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", sBlendMode, "blend_type_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("albedo_arg", sAlbedo, "k_albedo_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("material_type_arg", sMaterialModel, "k_material_model_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type_arg", sEnvironmentMapping, "k_environment_mapping_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("self_illumination_arg", sSelfIllumination, "k_self_illumination_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", sBlendMode, "k_blend_mode_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("misc_arg", misc, "k_misc_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Custom, "shadertype_"));

            // prevent crash
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Distortion>());
            macros.Add(ShaderGeneratorBase.CreateMacro("distortion_arg", "Off", "k_distortion_"));
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Soft_Fade>());
            macros.Add(ShaderGeneratorBase.CreateMacro("soft_fade_arg", Shared.Soft_Fade.Off, "k_soft_fade_"));

            byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_custom.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0");

            return(new ShaderGeneratorResult(shaderBytecode));
        }
Пример #2
0
        public ShaderGeneratorResult GeneratePixelShader(ShaderStage entryPoint)
        {
            if (!TemplateGenerationValid)
            {
                throw new System.Exception("Generator initialized with shared shader constructor. Use template constructor.");
            }

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

            macros.Add(new D3D.SHADER_MACRO {
                Name = "_DEFINITION_HELPER_HLSLI", Definition = "1"
            });
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Albedo>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Blend_Mode>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Specialized_Rendering>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Lighting>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Render_Targets>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Depth_Fade>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Black_Point>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Fog>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Frame_Blend>());
            macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Self_Illumination>());

            //
            // Convert to shared enum
            //

            var sAlbedo           = Enum.Parse(typeof(Shared.Albedo), albedo.ToString());
            var sBlendMode        = Enum.Parse(typeof(Shared.Blend_Mode), blend_mode.ToString());
            var sSelfIllumination = Enum.Parse(typeof(Shared.Self_Illumination), self_illumination.ToString());
            var sDepthFade        = Enum.Parse(typeof(Shared.Depth_Fade), depth_fade.ToString());
            var sBlackPoint       = Enum.Parse(typeof(Shared.Black_Point), black_point.ToString());
            var sFog = Enum.Parse(typeof(Shared.Fog), fog.ToString());

            //
            // The following code properly names the macros (like in rmdf)
            //

            macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_ps", sAlbedo, "calc_albedo_", "_ps"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", sBlendMode, "blend_type_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("particle_specialized_rendering", specialized_rendering, "specialized_rendering_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("particle_lighting", lighting, "lighting_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("particle_render_targets", render_targets, "render_targets_"));
            //macros.Add(ShaderGeneratorBase.CreateMacro("calc_depth_fade", sDepthFade, "calc_depth_fade_"));
            //macros.Add(ShaderGeneratorBase.CreateMacro("calc_black_point", sBlackPoint, "calc_black_point_"));
            //macros.Add(ShaderGeneratorBase.CreateMacro("calc_fog", sFog, "calc_fog_"));
            //macros.Add(ShaderGeneratorBase.CreateMacro("calc_frame_blend", frame_blend, "calc_frame_blend_"));
            //macros.Add(ShaderGeneratorBase.CreateMacro("calc_self_illumination_ps", sSelfIllumination, "calc_self_illumination_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Particle, "k_shadertype_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("albedo_arg", sAlbedo, "k_albedo_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", sBlendMode, "k_blend_mode_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("specialized_rendering_arg", specialized_rendering, "k_specialized_rendering_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("lighting_arg", lighting, "k_lighting_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("render_targets_arg", render_targets, "k_render_targets_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("depth_fade_arg", sDepthFade, "k_depth_fade_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("black_point_arg", sBlackPoint, "k_black_point_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("fog_arg", sFog, "k_fog_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("frame_blend_arg", frame_blend, "k_frame_blend_"));
            macros.Add(ShaderGeneratorBase.CreateMacro("self_illumination_arg", sSelfIllumination, "k_self_illumination_"));

            macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0));

            byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_particle.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0");

            return(new ShaderGeneratorResult(shaderBytecode));
        }