public static CompiledShaderCode LoadBytecode(ResourceFactory factory, string setName, ShaderStages stage) { string name = setName + "-" + stage.ToString().ToLower(); GraphicsBackend backend = factory.BackendType; if (backend == GraphicsBackend.Vulkan || backend == GraphicsBackend.Direct3D11) { string bytecodeExtension = GetBytecodeExtension(backend); string bytecodePath = AssetHelper.GetPath(Path.Combine("Shaders.Generated", name + bytecodeExtension)); if (File.Exists(bytecodePath) && false) { return(factory.LoadProcessedShader(File.ReadAllBytes(bytecodePath))); } } string extension = GetSourceExtension(backend); string path = AssetHelper.GetPath(Path.Combine("Shaders.Generated", name + extension)); return(factory.ProcessShaderCode(stage, File.ReadAllText(path))); }
public static byte[] LoadBytecode(GraphicsBackend backend, string setName, ShaderStages stage) { string stageExt = stage == ShaderStages.Vertex ? "vert" : "frag"; string name = setName + "." + stageExt; if (backend == GraphicsBackend.Vulkan || backend == GraphicsBackend.Direct3D11) { string bytecodeExtension = GetBytecodeExtension(backend); string bytecodePath = AssetHelper.GetPath(Path.Combine("Shaders", name + bytecodeExtension)); if (File.Exists(bytecodePath)) { return(File.ReadAllBytes(bytecodePath)); } } string extension = GetSourceExtension(backend); string path = AssetHelper.GetPath(Path.Combine("Shaders.Generated", name + extension)); return(File.ReadAllBytes(path)); }
private void AddSponzaAtriumObjects(CommandList cl) { ObjParser parser = new ObjParser(); using (FileStream objStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.obj"))) { ObjFile atriumFile = parser.Parse(objStream); MtlFile atriumMtls; using (FileStream mtlStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.mtl"))) { atriumMtls = new MtlParser().Parse(mtlStream); } foreach (ObjFile.MeshGroup group in atriumFile.MeshGroups) { ConstructedMeshInfo mesh = atriumFile.GetMesh(group); MaterialDefinition materialDef = atriumMtls.Definitions[mesh.MaterialName]; ImageSharpTexture overrideTextureData = null; ImageSharpTexture alphaTexture = null; MaterialPropsAndBuffer materialProps = CommonMaterials.Brick; if (materialDef.DiffuseTexture != null) { string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.DiffuseTexture); overrideTextureData = LoadTexture(texturePath, true); } if (materialDef.AlphaMap != null) { string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.AlphaMap); alphaTexture = LoadTexture(texturePath, false); } if (materialDef.Name.Contains("vase")) { materialProps = CommonMaterials.Vase; } AddTexturedMesh(cl, mesh, overrideTextureData, alphaTexture, materialProps, Vector3.Zero, Quaternion.Identity, new Vector3(0.1f)); } } }