static void TestSharedPixelShader(ShaderType shaderType, ShaderStage stage, int methodIndex, int optionIndex) { IShaderGenerator generator = GetShaderGenerator(shaderType); byte[] bytecode; string disassembly; if (generator.IsSharedPixelShaderUsingMethods(stage)) { if (methodIndex == -1 || optionIndex == -1) { for (int i = 0; i < generator.GetMethodCount(); i++) { if (generator.IsMethodSharedInEntryPoint(stage, i) && generator.IsPixelShaderShared(stage)) { for (int j = 0; j < generator.GetMethodOptionCount(i); j++) { var result = generator.GenerateSharedPixelShader(stage, i, j); if (result != null) { bytecode = generator.GenerateSharedPixelShader(stage, i, j).Bytecode; disassembly = D3DCompiler.Disassemble(bytecode); WriteShaderFile($"generated_{stage.ToString().ToLower()}_{i}_{j}.glps", disassembly); } } } } } else { var result = generator.GenerateSharedPixelShader(stage, -1, -1); if (result != null) { bytecode = result.Bytecode; disassembly = D3DCompiler.Disassemble(bytecode); WriteShaderFile($"generated_{stage.ToString().ToLower()}_{methodIndex}_{optionIndex}.glps", disassembly); } } } else { var result = generator.GenerateSharedPixelShader(stage, -1, -1); if (result != null) { bytecode = result.Bytecode; disassembly = D3DCompiler.Disassemble(bytecode); WriteShaderFile($"generated_{stage.ToString().ToLower()}.glps", disassembly); } } }
static void TestSharedVertexBlack(VertexType vertexType, ShaderStage stage) { var gen = new ShaderBlackGenerator(); var bytecode = gen.GenerateSharedVertexShader(vertexType, stage).Bytecode; WriteShaderFile($"generated_shader_black_{stage.ToString().ToLower()}_{vertexType.ToString().ToLower()}.glvs", D3DCompiler.Disassemble(bytecode)); }
public static string GetTestSharedVertexShader(VertexType vertex, ShaderStage stage) { var vertexShaderPath = Path.Combine(ReferencePath, $"{ShaderType}_shared_vertex_shaders.glvs"); vertexShaderPath = Path.Combine(vertexShaderPath, $"{vertex.ToString().ToLower()}"); vertexShaderPath = Path.Combine(vertexShaderPath, $"{stage.ToString().ToLower()}.shared_vertex_shader"); return(vertexShaderPath); }
public static void DisplayVertexShaderTestResults(bool success, VertexType vertex, ShaderStage stage, bool usesD3DX) { if (IgnoreD3DX && usesD3DX) { return; } if (!success) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Generated shader for {stage.ToString().ToLower()} vertex format {vertex.ToString().ToLower()} is not identical to reference." + (usesD3DX ? " USES D3DX." : "")); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Generated shader for {stage.ToString().ToLower()} vertex format {vertex.ToString().ToLower()} is identical to reference."); Console.ResetColor(); } }
public static void DisplaySharedPixelShaderTestResults(bool success, int methodIndex, int optionIndex, ShaderStage stage, bool usesD3DX) { if (IgnoreD3DX && usesD3DX) { return; } if (!success) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Generated shader for {stage.ToString().ToLower()}_{methodIndex}_{optionIndex} is not identical to reference." + (usesD3DX ? " USES D3DX." : "")); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Generated shader for {stage.ToString().ToLower()}_{methodIndex}_{optionIndex} is identical to reference."); Console.ResetColor(); } }
static void TestSharedVertexShader(ShaderType shaderType, VertexType vertexType, ShaderStage stage) { IShaderGenerator generator = GetShaderGenerator(shaderType); if (generator.IsEntryPointSupported(stage) && generator.IsVertexShaderShared(stage) && generator.IsVertexFormatSupported(vertexType)) { var bytecode = generator.GenerateSharedVertexShader(vertexType, stage).Bytecode; var disassembly = D3DCompiler.Disassemble(bytecode); WriteShaderFile($"generated_{stage.ToString().ToLower()}_{vertexType.ToString().ToLower()}.glvs", disassembly); } }
static void TestPixelShader(ShaderType shaderType, ShaderStage stage, List <int> methods) { IShaderGenerator generator = GetTemplateShaderGenerator(shaderType, methods); if (generator.IsEntryPointSupported(stage) && !generator.IsPixelShaderShared(stage)) { var bytecode = generator.GeneratePixelShader(stage).Bytecode; var parameters = generator.GetPixelShaderParameters(); var disassembly = D3DCompiler.Disassemble(bytecode); string filename = $"generated_{stage.ToString().ToLower()}_{string.Join("_", methods)}.pixl"; WriteShaderFile(filename, disassembly); } }
public static string GetTestSharedPixelShader(ShaderStage stage, int methodIndex = -1, int optionIndex = -1) { var vertexShaderPath = Path.Combine(ReferencePath, $"{ShaderType}_shared_pixel_shaders.glps"); var filename = $"{stage.ToString().ToLower()}"; if (methodIndex != -1 && optionIndex != -1) { filename += $"_{methodIndex}_{optionIndex}"; } vertexShaderPath = Path.Combine(vertexShaderPath, $"{filename}.shared_pixel_shader"); return(vertexShaderPath); }
/// <summary> /// Determine an unique identifier that specify the compiled shader object. /// </summary> /// <param name="cctx"> /// A <see cref="ShaderCompilerContext"/> determining the compiler parameteres. /// </param> /// <param name="libraryId"> /// A <see cref="String"/> that identifies the shader object in library. /// </param> /// <param name="sObjectStage"> /// A <see cref="ShaderObject.ShaderStage"/> that specify the shader object stage. /// </param> /// <returns> /// It returns a string that identify the a shader object classified with <paramref name="libraryId"/>, by /// specifying <paramref name="cctx"/> as compiled parameters, for the shader stage <paramref name="sObjectStage"/>. /// </returns> internal static string ComputeCompilerHash(ShaderCompilerContext cctx, string libraryId, ShaderStage sObjectStage) { StringBuilder hashMessage = new StringBuilder(); if (cctx == null) { throw new ArgumentNullException("cctx"); } if (libraryId == null) { throw new ArgumentNullException("libraryId"); } // Take into account the shader object library identifier hashMessage.Append(libraryId); // Take into account the shader object library stage hashMessage.Append(sObjectStage.ToString()); // Take into account the shader version hashMessage.Append(cctx.ShaderVersion); // Take into account the shader program compilation symbols foreach (String define in cctx.Defines) { hashMessage.AppendFormat("{0}", define); } // Take into account the shader program include paths foreach (string includePath in cctx.Includes) { hashMessage.AppendFormat("{0}", includePath); } // Hash all information byte[] hashBytes; using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create("SHA256")) { hashBytes = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(hashMessage.ToString())); } // ConvertItemType has to string return(Convert.ToBase64String(hashBytes)); }
// For glsLang args string StageStringFromFlags(ShaderStage stage) { switch (stage) { case ShaderStage.Vertex: { return("vert"); } case ShaderStage.TesselationControl: { return("tesc"); } case ShaderStage.TesselationEvaluation: { return("tese"); } case ShaderStage.Geometry: { return("geom"); } case ShaderStage.Fragment: { return("frag"); } case ShaderStage.Compute: { return("comp"); } } throw new Exception("Invalid shader stage: " + stage.ToString()); }
public ShaderGeneratorResult GenerateSharedPixelShader(ShaderStage entryPoint, int methodIndex, int optionIndex) { if (!IsEntryPointSupported(entryPoint) || !IsPixelShaderShared(entryPoint)) { return(null); } Alpha_Test alphaTestOption = Alpha_Test.None; switch ((FoliageMethods)methodIndex) { case FoliageMethods.Alpha_Test: alphaTestOption = (Alpha_Test)optionIndex; break; default: return(null); } 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 <ShaderType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Alpha_Test>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_alpha_test_ps", alphaTestOption, "calc_alpha_test_", "_ps")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"glps_foliage.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
/// <summary> /// Determine an unique identifier that specify the compiled shader object. /// </summary> /// <param name="cctx"> /// A <see cref="ShaderCompilerContext"/> determining the compiler parameteres. /// </param> /// <param name="libraryId"> /// A <see cref="String"/> that identifies the shader object in library. /// </param> /// <param name="sObjectStage"> /// A <see cref="ShaderObject.ShaderStage"/> that specify the shader object stage. /// </param> /// <returns> /// It returns a string that identify the a shader object classified with <paramref name="libraryId"/>, by /// specifying <paramref name="cctx"/> as compiled parameters, for the shader stage <paramref name="sObjectStage"/>. /// </returns> internal static string ComputeCompilerHash(ShaderCompilerContext cctx, string libraryId, ShaderStage sObjectStage) { StringBuilder hashMessage = new StringBuilder(); if (cctx == null) throw new ArgumentNullException("cctx"); if (libraryId == null) throw new ArgumentNullException("libraryId"); // Take into account the shader object library identifier hashMessage.Append(libraryId); // Take into account the shader object library stage hashMessage.Append(sObjectStage.ToString()); // Take into account the shader version hashMessage.Append(cctx.ShaderVersion); // Take into account the shader program compilation symbols foreach (String define in cctx.Defines) hashMessage.AppendFormat("{0}", define); // Take into account the shader program include paths foreach (string includePath in cctx.Includes) hashMessage.AppendFormat("{0}", includePath); // Hash all information byte[] hashBytes; using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create("SHA256")) { hashBytes = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(hashMessage.ToString())); } // ConvertItemType has to string return (Convert.ToBase64String(hashBytes)); }
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 <Waveshape>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Watercolor>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Reflection>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Refraction>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bankalpha>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Appearance>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Global_Shape>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Foam>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Reach_Compatibility>()); macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); // // The following code properly names the macros (like in rmdf) // macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Water, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_waveshape_ps", waveshape, "calc_waveshape_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_watercolor_ps", watercolor, "calc_watercolor_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_reflection_ps", reflection, "calc_reflection_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_refraction_ps", refraction, "calc_refraction_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_bankalpha_ps", bankalpha, "calc_bankalpha_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_foam_ps", foam, "calc_foam_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("waveshape_arg", waveshape, "k_waveshape_")); macros.Add(ShaderGeneratorBase.CreateMacro("watercolor_arg", watercolor, "k_watercolor_")); macros.Add(ShaderGeneratorBase.CreateMacro("reflection_arg", reflection, "k_reflection_")); macros.Add(ShaderGeneratorBase.CreateMacro("refraction_arg", refraction, "k_refraction_")); macros.Add(ShaderGeneratorBase.CreateMacro("bankalpha_arg", bankalpha, "k_bankalpha_")); macros.Add(ShaderGeneratorBase.CreateMacro("appearance_arg", appearance, "k_appearance_")); macros.Add(ShaderGeneratorBase.CreateMacro("global_shape_arg", global_shape, "k_global_shape_")); macros.Add(ShaderGeneratorBase.CreateMacro("foam_arg", foam, "k_foam_")); macros.Add(ShaderGeneratorBase.CreateMacro("reach_compatibility_arg", reach_compatibility, "k_reach_compatibility_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_water.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
internal void CompileFromSource(ResolvedShader resolved) { if (_handle > 0) { GL.DeleteProgram(_handle); } _handle = GL.CreateShaderProgram((ShaderType)_stage, 1, new string[] { resolved.Code }); string log = GL.GetProgramInfoLog(_handle); _lastLog = log; int isLinked = -1; GL.GetProgram(_handle, GetProgramParameterName.LinkStatus, out isLinked); if (isLinked != 1) { _valid = false; _device.TextOutput.Print(OutputTypeGlob.Error, "Error compiling " + _stage.ToString() + " shader " + BaseSource.Filename); GL.DeleteProgram(_handle); _handle = 0; var lines = Regex.Split(log, "\r\n|\r|\n"); StringBuilder outputSb = new StringBuilder(); // Find error messages and translate resolved code line number to local line number in the responsible file foreach (var line in lines) { var match = Regex.Match(line, @"^ERROR:.*:([0-9]+):.*$"); var match2 = Regex.Match(line, @"^0\(([0-9]+)\)"); outputSb.AppendLine(line); if (match.Success) { int lineNum = int.Parse(match.Groups[1].Value); outputSb.AppendLine("At: " + resolved.GetLineOrigin(lineNum)); } else if (match2.Success) { int lineNum = int.Parse(match2.Groups[1].Value) - 1; outputSb.AppendLine("At: " + resolved.GetLineOrigin(lineNum)); } } _device.TextOutput.Print(OutputTypeGlob.Debug, outputSb.ToString()); } else { _valid = true; } // Query the work group size _workGroupSizeX = 0; _workGroupSizeY = 0; _workGroupSizeZ = 0; if (_stage == ShaderStage.Compute && _handle != 0) { int[] wgSize = new int[3]; GL.GetProgram(_handle, (GetProgramParameterName)0x8267, wgSize); _workGroupSizeX = wgSize[0]; _workGroupSizeY = wgSize[1]; _workGroupSizeZ = wgSize[2]; } if (_handle != 0) { Utils.SetObjectLabel(ObjectLabelIdentifier.Program, _handle, BaseSource.Filename); FinalizeCompilation(); } }
public static byte[] GenerateShaderCortana( ShaderStage stage ) { string template = $"shader_cortana.hlsl"; List <D3D.SHADER_MACRO> macros = new List <D3D.SHADER_MACRO>(); switch (stage) { case ShaderStage.Active_Camo: break; default: return(null); } // prevent the definition helper from being included macros.Add(new D3D.SHADER_MACRO { Name = "_DEFINITION_HELPER_HLSLI", Definition = "1" }); var shader_bytecode = ShaderGeneratorBase.GenerateSource(template, macros, "entry_" + stage.ToString().ToLower(), "ps_3_0"); return(shader_bytecode); }
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 <Warp>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Base>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Overlay_A>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Overlay_B>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Blend_Mode>()); // // Convert to shared enum // 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_screen_warp", warp, "calc_screen_warp_")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_base", _base, "calc_base_")); macros.Add(ShaderGeneratorBase.CreateMacro("overlay_type_a", overlay_a, "overlay_")); macros.Add(ShaderGeneratorBase.CreateMacro("overlay_type_b", overlay_b, "overlay_")); macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", sBlendMode, "blend_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Screen, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", sBlendMode, "k_blend_mode_")); //macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_screen.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
public ShaderGeneratorResult GenerateSharedVertexShader(VertexType vertexType, ShaderStage entryPoint) { if (!IsVertexFormatSupported(vertexType) || !IsEntryPointSupported(entryPoint)) { return(null); } 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 <Shared.ShaderType>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_vertex_transform", vertexType, "calc_vertex_transform_", "")); macros.Add(ShaderGeneratorBase.CreateVertexMacro("input_vertex_format", vertexType)); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Black, "shadertype_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource(@"glvs_shader_black.hlsl", macros, $"entry_{entryPoint.ToString().ToLower()}", "vs_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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.Add(new D3D.SHADER_MACRO { Name = "_TERRAIN_HELPER_HLSLI", Definition = "1" }); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Blending>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Environment_Mapping>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Material>()); // // Convert to shared enum // var sEnvironmentMapping = Enum.Parse(typeof(Shared.Environment_Mapping), environment_mapping.ToString()); // // The following code properly names the macros (like in rmdf) // Material material_3_translated = material_3 == Material_No_Detail_Bump.Off ? Material.Off : material_3 == Material_No_Detail_Bump.Diffuse_Only ? Material.Diffuse_Only : Material.Diffuse_Plus_Specular; macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", blending)); macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type", sEnvironmentMapping, "envmap_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Terrain, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", blending, "k_blend_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type_arg", sEnvironmentMapping, "k_environment_mapping_")); macros.Add(ShaderGeneratorBase.CreateMacro("material_type_0_arg", material_0, "k_material_")); macros.Add(ShaderGeneratorBase.CreateMacro("material_type_1_arg", material_1, "k_material_")); macros.Add(ShaderGeneratorBase.CreateMacro("material_type_2_arg", material_2, "k_material_")); macros.Add(ShaderGeneratorBase.CreateMacro("material_type_3_arg", material_3_translated, "k_material_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_terrain.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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 <Render_Pass>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Specular>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bump_Mapping>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Tinting>()); // // Convert to shared enum // var sAlbedo = Enum.Parse(typeof(Shared.Albedo), albedo.ToString()); var sBlendMode = Enum.Parse(typeof(Shared.Blend_Mode), blend_mode.ToString()); // // The following code properly names the macros (like in rmdf) // // TODO fix //macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", sBlendMode, "blend_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_blend_mode", blend_mode, "blend_mode_")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_ps", sAlbedo, "calc_albedo_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_render_pass", render_pass, "render_pass_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_specular", specular, "specular_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_bump_mapping", bump_mapping, "bump_mapping_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_tinting", tinting, "tinting_")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Decal, "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("decal_render_pass_arg", render_pass, "k_decal_render_pass_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_specular_arg", specular, "k_decal_specular_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_bump_mapping_arg", bump_mapping, "k_decal_bump_mapping_")); macros.Add(ShaderGeneratorBase.CreateMacro("decal_tinting_arg", tinting, "k_decal_tinting_")); macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); macros.Add(ShaderGeneratorBase.CreateMacro("DECAL_IS_SIMPLE", DecalIsSimple ? 1 : 0)); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_decal.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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)); }
public static string BuildPixelShaderEntryPointName(ShaderStage stage) { return($"{stage.ToString().ToLower()}.pixel_shader"); }
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 <Albedo>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bump_Mapping>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.Alpha_Test>()); 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.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); // // Convert to shared enum // 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 sBlendMode = Shared.Blend_Mode.Opaque; // // The following code properly names the macros (like in rmdf) // macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_ps", albedo, "calc_albedo_", "_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_alpha_test_ps", sAlphaTest, "calc_alpha_test_", "_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("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Cortana, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("albedo_arg", albedo, "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("blend_type_arg", sBlendMode, "k_blend_mode_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_cortana.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
public ShaderGeneratorResult GenerateSharedVertexShader(VertexType vertexType, ShaderStage entryPoint) { if (!IsVertexFormatSupported(vertexType) || !IsEntryPointSupported(entryPoint)) { return(null); } List <D3D.SHADER_MACRO> macros = new List <D3D.SHADER_MACRO>(); macros.Add(new D3D.SHADER_MACRO { Name = "_VERTEX_SHADER_HELPER_HLSLI", Definition = "1" }); macros.Add(new D3D.SHADER_MACRO { Name = "_TERRAIN_HELPER_HLSLI", Definition = "1" }); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <VertexType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_vertex_transform", vertexType, "calc_vertex_transform_", "")); macros.Add(ShaderGeneratorBase.CreateMacro("transform_dominant_light", vertexType, "transform_dominant_light_", "")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_distortion", vertexType, "calc_distortion_", "")); macros.Add(ShaderGeneratorBase.CreateVertexMacro("input_vertex_format", vertexType)); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("vertextype", vertexType, "k_vertextype_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Terrain, "shadertype_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource(@"glvs_terrain.hlsl", macros, $"entry_{entryPoint.ToString().ToLower()}", "vs_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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 <Shared.Fog>()); // // 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 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("light_volume_fog", sFog, "fog_")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Light_Volume, "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("fog_arg", sFog, "k_fog_")); macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_light_volume.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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 <Test>()); // // The following code properly names the macros (like in rmdf) // macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.ZOnly, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("test_arg", test, "k_test_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_zonly.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
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); }
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)); }
public ShaderGeneratorResult GeneratePixelShader(ShaderStage entryPoint) { if (!IsEntryPointSupported(entryPoint)) { return(null); } 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>()); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource($"pixl_shader_black.hlsl", macros, "entry_" + entryPoint.ToString().ToLower(), "ps_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
public ShaderGeneratorResult GenerateSharedVertexShader(VertexType vertexType, ShaderStage entryPoint) { if (!IsVertexFormatSupported(vertexType) || !IsEntryPointSupported(entryPoint)) { return(null); } 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 <VertexType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Waveshape>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Watercolor>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Reflection>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Refraction>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bankalpha>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Appearance>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Global_Shape>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Foam>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Reach_Compatibility>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_vertex_transform", vertexType, "calc_vertex_transform_", "")); macros.Add(ShaderGeneratorBase.CreateMacro("transform_unknown_vector", vertexType, "transform_unknown_vector_", "")); macros.Add(ShaderGeneratorBase.CreateVertexMacro("input_vertex_format", vertexType)); macros.Add(ShaderGeneratorBase.CreateMacro("transform_dominant_light", vertexType, "transform_dominant_light_", "")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("vertextype", vertexType, "k_vertextype_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Water, "k_shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("APPLY_HLSL_FIXES", ApplyFixes ? 1 : 0)); macros.Add(ShaderGeneratorBase.CreateMacro("waveshape_arg", waveshape, "k_waveshape_")); macros.Add(ShaderGeneratorBase.CreateMacro("watercolor_arg", watercolor, "k_watercolor_")); macros.Add(ShaderGeneratorBase.CreateMacro("reflection_arg", reflection, "k_reflection_")); macros.Add(ShaderGeneratorBase.CreateMacro("refraction_arg", refraction, "k_refraction_")); macros.Add(ShaderGeneratorBase.CreateMacro("bankalpha_arg", bankalpha, "k_bankalpha_")); macros.Add(ShaderGeneratorBase.CreateMacro("appearance_arg", appearance, "k_appearance_")); macros.Add(ShaderGeneratorBase.CreateMacro("global_shape_arg", global_shape, "k_global_shape_")); macros.Add(ShaderGeneratorBase.CreateMacro("foam_arg", foam, "k_foam_")); macros.Add(ShaderGeneratorBase.CreateMacro("reach_compatibility_arg", reach_compatibility, "k_reach_compatibility_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource(@"glvs_water.hlsl", macros, $"entry_{entryPoint.ToString().ToLower()}", "vs_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
public static MethodDefinition GetEntryPoint(this Shader shader, ShaderStage type) { return(shader.Declarations.OfType <MethodDefinition>().FirstOrDefault(f => f.Attributes.OfType <AttributeDeclaration>().Any(a => a.Name == "EntryPoint" && (string)a.Parameters[0].Value == type.ToString()))); }
public override string GenerateChudVertexShader(ChudShader chudShader, ShaderStage entry) { var bytecode = GenericVertexShaderGenerator.GenerateVertexShader(chudShader.ToString(), entry.ToString().ToLower(), true).Bytecode; return(D3DCompiler.Disassemble(bytecode)); }