private void InitAssetsManager() { AssetsManagerInstance AssetManager = AssetsManagerInstance.GetManager(); //AssetManager.CreateMaterialAsset("CopperMaterial"); MetaAssets = AssetManager.LoadProjectAssets(); //Debug print tree //int k = 0; //foreach (AssetTypes key in MetaAssets.Keys) { // Console.WriteLine("[{0} assets]", key); // string[] names = new string[MetaAssets[key].Count]; // if (MetaAssets[key].Count == 0) { // Console.WriteLine(" - [empty list]"); // } // int i = 0; // foreach (MetaAsset asset in MetaAssets[key]) { // names[i] = asset.Name; // i++; // Console.WriteLine(" - {0}", asset.Name); // } // k++; //} AssetTypesDataList = MetaAssets.Keys; SetAssetTypesListValues(); this.AssetTypesList.SelectedIndex = 0; }
static public Material LoadMaterial(string assetName) { if (CachedMaterials.ContainsKey(assetName)) { return(CachedMaterials[assetName]); } MaterialAsset MA = AssetsManagerInstance.GetManager().LoadAsset <MaterialAsset>(assetName); Material mat = new Material() { Name = MA.Name, AlbedoMapAsset = MA.AlbedoMapAsset, RoughnessMapAsset = MA.RoughnessMapAsset, MetallicMapAsset = MA.MetallicMapAsset, NormalMapAsset = MA.NormalMapAsset, OcclusionMapAsset = MA.OcclusionMapAsset, PropetyBlock = new MaterialPropetyBlock() { AlbedoColor = MA.AlbedoColor, AlphaValue = MA.AlphaValue, MetallicValue = MA.MetallicValue, RoughnessValue = MA.RoughnessValue, Shift = MA.Shift, Tile = MA.Tile, }, }; MA = null; CachedMaterials.Add(assetName, mat); Debug.Log("AssetManager", "Material " + assetName + " loaded."); return(mat); }
public override void SaveAsset(BinaryWriter writer) { base.SaveAsset(writer); int i; writer.Write(FileScale); writer.Write(SerializeBlock.GetBytes(Pivot)); writer.Write(Vertices.Length); for (i = 0; i < Vertices.Length; i++) { byte[] bytes = SerializeBlock.GetBytes(Vertices[i]); writer.Write(bytes); } writer.Write(Indexes.Length); for (i = 0; i < Indexes.Length; i++) { writer.Write(Indexes[i]); } writer.Write(SerializeBlock.GetBytes(BoundingMinimum)); writer.Write(SerializeBlock.GetBytes(BoundingMaximum)); if (subAssets == null) { return; } foreach (MeshAsset subAsset in subAssets) { AssetsManagerInstance.GetManager().FSWorker.CreateAssetFile(subAsset, true); } }
public override void Show(string assetName) { base.Show(assetName); EngineRef.SetViewsControlsEnabled(false, false, false, false, false); EngineRef.CameraEntity.GetComponent <Transform>().SetTransformations(new Vector3(0f, 0, -2f), Quaternion.RotationYawPitchRoll(MathUtil.Pi, 0, 0)); PreviewEntity.SetActive(true); EngineRef.ECSWorld.Refresh(); Texture2DAsset asset = AssetsManagerInstance.GetManager().LoadAsset <Texture2DAsset>(assetName); ratio = (float)asset.Data.Width / asset.Data.Height; Vector3 scale; if (ratio >= 1) { scale = (Vector3.Right + Vector3.Up / ratio) * 3.85f; } else { scale = (Vector3.Right + Vector3.Up * ratio) * 3.85f; } scale += Vector3.ForwardLH * 0.1f; PreviewEntity.GetComponent <Transform>().Scale = scale; TestMaterial.AlbedoMapAsset = assetName; }
private void ImportAsset() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Raw assets|*.obj;*.fbx;*.bmp;*.jpg;*.png|Shader source code|*.hlsl|All files|*.*"; if (openFileDialog.ShowDialog() == FDialogResult.Cancel) { return; } string FilePath = openFileDialog.FileName; string SafeFileName = openFileDialog.SafeFileName; AssetsManagerInstance AssetManager = AssetsManagerInstance.GetManager(); string assetName = SafeFileName.Split('.')[0]; BaseAsset asset; if (AssetManager.ImportAsset(FilePath, assetName, true, out asset)) { if (asset.Type == AssetTypes.Mesh) { EngineCore.AssetsLoader.DropCachedMesh(assetName); } RefreshAssetsTable(); } else { System.Windows.MessageBox.Show("Import Failed"); } SelectedFolder = asset.Type; }
static void Main(string[] args) { var AM = AssetsManagerInstance.GetManager(); #region PreRenderUtils bool startPreRenderUtils = false; //startPreRenderUtils = true; if (startPreRenderUtils) { //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_SphereToCubeMapVS", "VS_SphereToCubeMap", true); //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_SphereToCubeMapPS", "PS_SphereToCubeMap", true); //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_IrradiancePS", "PS_Irradiance", true); //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_PreFilteredPS", "PS_PreFiltered", true); //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_IntegrateBRDFxPS", "PS_IntegrateBRDF", true); //AM.ImportShaderAsset(@"Commons\IBL_AssetsPreRender.hlsl", "IBL_PR_IntegrateQuadVS", "VS_IntegrateQuad", true); AssetsManagerInstance.GetManager().CubeMapPrerender("Mt-Washington-Cave-Room_Ref.hdr", "House"); //AssetsManagerInstance.GetManager().CubeMapPrerender("Tokyo_BigSight_3k.hdr", "House"); //AssetsManagerInstance.GetManager().CubeMapPrerender("moonless_golf_2k.hdr", "House"); //AssetsManagerInstance.GetManager().BRDFIntegrate("StandardBRDFxLUT"); Console.ReadKey(); return; } #endregion //var t = new TestShadersCompiler(); //t.TestItAll(); // Console.ReadKey(); /*MultiThreadQueue test = new MultiThreadQueue(2); * for (int i = 0; i < 100; i++) * { * test.Enqueue("Test" + i); * } * Console.ReadKey();*/ //ImportContent(); Console.ReadKey(); EngineConfiguration config = new EngineConfiguration() { AppName = "ECS SandBox", RenderBackend = EngineConfiguration.RenderBackendEnum.D3D11, RenderPath = RenderPathEnum.Deffered, //RenderPath = RenderPathEnum.Forward, EnableHDR = true, //EnableMSAA = EngineConfiguration.MSAAEnabled.x4, DebugMode = true, }; //Game game = new Game(); PBRTest game = new PBRTest(); game.Run(config); }
private static void ImportContent() { var AM = AssetsManagerInstance.GetManager(); HotReload_NOT(AM); //ImportMeshes(AM); //ImportTextures(AM); //CreateMaterials(AM); //ImportShaders(AM); }
private void RefreshAssetsTable() { AssetsManagerInstance AssetManager = AssetsManagerInstance.GetManager(); //AssetManager.CreateCubeMapAsset("C:\\Repos\\CopperCowEngine\\RawContent\\Textures\\Skybox\\miramarirrad.bmp", "MiraSkyboxIrradianceCubeMap"); MetaAssets = AssetManager.LoadProjectAssets(); SelectedFolder = MetaAssets.Keys.ToArray()[0]; NotifyPropertyChanged("Folders"); NotifyPropertyChanged("Files"); //FilesTreeDebugPrint(); }
public AssetEditorModelView(ProjectLink project) { AssetsManagerInstance.GetManager().RootPath = Path.GetDirectoryName(project.Src); //AssetsManagerInstance.GetManager().ImportAsset("PBR/DefferedPBRShader.hlsl", "DefferedPBRShader"); //AssetsManagerInstance.GetManager().ImportAsset("PBR/DefferedPBRQuadShader.hlsl", "DefferedPBRQuadShader"); EngineRef = new PreviewEngine(); EngineRef.OnSetViewsControlsEnabled += (bool zoom, bool yaw, bool pitch, bool viewPos, bool meshType) => { ControlsVisibleFlags = new bool[] { zoom, yaw, pitch, viewPos, meshType }; }; }
private void CreateNewAsset(string type) { if (type != "Material") { return; } AssetsManagerInstance AssetManager = AssetsManagerInstance.GetManager(); AssetManager.CreateMaterialAsset(); RefreshAssetsTable(); SelectedFolder = AssetTypes.Material; }
private void CommonInitialize(ProjectLink project) { AssetsManagerInstance.GetManager().RootPath = Path.GetDirectoryName(project.Src); InitializeComponent(); AssetEditorModelView ModelView = new AssetEditorModelView(project); DataContext = ModelView; RendererElement.EngineRef = ModelView.EngineRef; (AssetsTree.DataContext as AssetsTreeViewModel).OnAssetSelect += ModelView.SetPreviewAsset; ModelView.MAMV += (MaterialAssetModelView assetView) => { PropertyGridRef.SelectedObject = null; PropertyGridRef.SelectedObject = assetView; }; }
static public ModelGeometry LoadMesh(string assetName) { if (CachedMeshes.ContainsKey(assetName)) { return(CachedMeshes[assetName]); } MeshAsset MA = AssetsManagerInstance.GetManager().LoadAsset <MeshAsset>(assetName); ModelGeometry MG = new ModelGeometry(MA.FileScale, MA.Pivot, MA.Vertices, MA.Indexes, MA.BoundingMinimum, MA.BoundingMaximum); MA = null; CachedMeshes.Add(assetName, MG); Debug.Log("AssetManager", "Mesh " + assetName + " loaded."); return(MG); }
static public void LoadShader(string assetName) { ShaderAsset SA = AssetsManagerInstance.GetManager().LoadAsset <ShaderAsset>(assetName); Debug.Log("AssetManager", SA.ShaderType.ToString() + " Shader " + assetName + " loaded. "); ShaderPlusSignature pack = new ShaderPlusSignature(); ShaderBytecode sb = new ShaderBytecode(SA.Bytecode); switch (SA.ShaderType) { case ShaderTypeEnum.Vertex: pack.shader = new VertexShader(RenderBackend.Device, sb); break; case ShaderTypeEnum.Pixel: pack.shader = new PixelShader(RenderBackend.Device, sb); break; case ShaderTypeEnum.Geometry: pack.shader = new GeometryShader(RenderBackend.Device, sb); break; case ShaderTypeEnum.Compute: pack.shader = new ComputeShader(RenderBackend.Device, sb); break; case ShaderTypeEnum.Hull: pack.shader = new HullShader(RenderBackend.Device, sb); break; case ShaderTypeEnum.Domain: pack.shader = new DomainShader(RenderBackend.Device, sb); break; default: break; } ; SA = null; pack.shader.DebugName = assetName; pack.signature = ShaderSignature.GetInputSignature(sb); Shaders.Add(assetName, pack); }
private void Create_Click(object sender, RoutedEventArgs e) { if (ofDialog == null) { return; } AssetsManagerInstance AM = AssetsManagerInstance.GetManager(); string assetName = ofDialog.SafeFileName.Split('.')[0]; BaseAsset asset; if (AM.ImportAsset(ofDialog.FileName, assetName, false, out asset)) { RefreshAssetsTable(); AssetTypesList.SelectedValue = asset.Type; AssetNamesList.SelectedValue = asset.Name; } else { System.Windows.MessageBox.Show("Import Failed"); } }
private void RefreshAssetsTable() { AssetsManagerInstance AssetManager = AssetsManagerInstance.GetManager(); MetaAssets = AssetManager.LoadProjectAssets(); int k = 0; foreach (AssetTypes key in MetaAssets.Keys) { string[] names = new string[MetaAssets[key].Count]; int i = 0; foreach (MetaAsset asset in MetaAssets[key]) { names[i] = asset.Name; i++; } k++; } AssetTypesDataList = MetaAssets.Keys; AssetTypesList.ItemsSource = AssetTypesDataList; AssetNamesList.ItemsSource = MetaAssets[SelectedType]; }
public static void Save(this Texture2D texture, DeviceContext context, Device device, string path, bool withMips) { var textureCopy = new Texture2D(device, new Texture2DDescription { Width = texture.Description.Width, Height = texture.Description.Height, MipLevels = texture.Description.MipLevels, ArraySize = texture.Description.ArraySize, Format = texture.Description.Format, Usage = ResourceUsage.Staging, SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, OptionFlags = ResourceOptionFlags.None }); context.CopyResource(texture, textureCopy); if (texture.Description.ArraySize == 1) { if (textureCopy.Description.Format == Format.R16G16_Float) { DataBox dataBox = context.MapSubresource( textureCopy, 0, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out DataStream dataStream); AssetsMeta.Texture2DAsset asset2D = new AssetsMeta.Texture2DAsset(); asset2D.Name = path; asset2D.Data.Width = textureCopy.Description.Width; asset2D.Data.Height = textureCopy.Description.Height; asset2D.Data.ColorSpace = ColorSpaceEnum.Linear; asset2D.Data.ChannelsCount = ChannelsCountEnum.Two; asset2D.Data.BytesPerChannel = BytesPerChannelEnum.Two; asset2D.Data.buffer = ReadFully(dataStream); AssetsManagerInstance.GetManager().FSWorker.CreateAssetFile(asset2D, true); context.UnmapSubresource(textureCopy, 0); textureCopy.Dispose(); return; } InternalSaveTexture($"{path}.png", 0, 0, Factory, textureCopy, context); textureCopy.Dispose(); return; } AssetsMeta.TextureCubeAsset asset = new AssetsMeta.TextureCubeAsset(); asset.Name = path; asset.Data.Width = textureCopy.Description.Width; asset.Data.Height = textureCopy.Description.Height; asset.Data.ColorSpace = ColorSpaceEnum.Linear; asset.Data.ChannelsCount = 4; asset.Data.BytesPerChannel = 2; asset.Data.MipLevels = withMips ? textureCopy.Description.MipLevels : 1; asset.Data.buffer = new byte[6][][]; for (int i = 0; i < 6; i++) { asset.Data.buffer[i] = new byte[asset.Data.MipLevels][]; for (int mip = 0; mip < asset.Data.MipLevels; mip++) { DataBox dataBox = context.MapSubresource( textureCopy, mip, i, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out DataStream dataStream); byte[] allMipBytes = ReadFully(dataStream); dataStream.Dispose(); int mipSize = (int)(asset.Data.Width * Math.Pow(0.5, mip)); int pitch = mipSize * asset.Data.ChannelsCount * asset.Data.BytesPerChannel; int n = mipSize * pitch; asset.Data.buffer[i][mip] = new byte[n]; for (int j = 0; j < mipSize; j++) { for (int k = 0; k < pitch; k++) { asset.Data.buffer[i][mip][j * pitch + k] = allMipBytes[j * dataBox.RowPitch + k]; } } context.UnmapSubresource(textureCopy, textureCopy.CalculateSubResourceIndex(mip, i, out int m)); // Dont work cause wrong dataBox.RowPitch on mip levels issue. // asset.Data.buffer[i][mip] = ReadFully(dataStream); } } AssetsManagerInstance.GetManager().FSWorker.CreateAssetFile(asset, true); // DEBUG RO PNG /*if (textureCopy.Description.MipLevels != 5) { * textureCopy.Dispose(); * return; * } * * for (int mip = 0; mip < textureCopy.Description.MipLevels; mip++) { * for (int i = 0; i < texture.Description.ArraySize; i++) { * InternalSaveTexture($"{path}_{CubePostfixes[i]}_mip{mip}.png", i, mip, Factory, textureCopy, context); * } * }*/ textureCopy.Dispose(); }
private void InitBRDFxResources() { AssetsManagerInstance AM = AssetsManagerInstance.GetManager(); AssetsMeta.ShaderAsset meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_SphereToCubeMapPS"); meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_IntegrateBRDFxPS"); ShaderBytecode shaderBytecode = new ShaderBytecode(meta.Bytecode); IntegrateBRDFxPS = ToDispose(new PixelShader(m_Device, shaderBytecode)); IntegrateBRDFxPS.DebugName = "IntegrateBRDFxPS"; meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_IntegrateQuadVS"); shaderBytecode = new ShaderBytecode(meta.Bytecode); IntegrateQuadVS = ToDispose(new VertexShader(m_Device, shaderBytecode)); IntegrateQuadVS.DebugName = "IntegrateQuadVS"; if (CustomInputLayout == null) { CustomInputLayout = ToDispose(new InputLayout(m_Device, ShaderSignature.GetInputSignature(shaderBytecode), new InputElement[] { new InputElement("SV_VertexID", 0, Format.R32G32B32_Float, 0, 0), })); } if (ConstantsBuffer == null) { // Create the per environment map buffer ViewProjection matrices ConstantsBuffer = ToDispose(new Buffer( m_Device, Utilities.SizeOf <Matrix>() * 2, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0) ); ConstantsBuffer.DebugName = "ConstantsBuffer"; } IntegrateBRDFxMap = ToDispose(new Texture2D(m_Device, new Texture2DDescription() { Width = BRDFxMapSize, Height = BRDFxMapSize, Format = Format.R16G16_Float, //R8G8B8A8_UNorm for debug ArraySize = 1, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), BindFlags = BindFlags.RenderTarget, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, })); IntegrateBRDFxRTV = ToDispose(new RenderTargetView(m_Device, IntegrateBRDFxMap, new RenderTargetViewDescription() { Dimension = RenderTargetViewDimension.Texture2D, Format = IntegrateBRDFxMap.Description.Format, Texture2D = new RenderTargetViewDescription.Texture2DResource() { MipSlice = 0, } })); }
void SetupShadersAndBuffers() { AssetsManagerInstance AM = AssetsManagerInstance.GetManager(); AssetsMeta.ShaderAsset meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_SphereToCubeMapPS"); ShaderBytecode shaderBytecode = new ShaderBytecode(meta.Bytecode); SphereToCubeMapPS = ToDispose(new PixelShader(m_Device, shaderBytecode)); SphereToCubeMapPS.DebugName = "SphereToCubeMapPS"; meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_IrradiancePS"); shaderBytecode = new ShaderBytecode(meta.Bytecode); IrradiancePS = ToDispose(new PixelShader(m_Device, shaderBytecode)); IrradiancePS.DebugName = "IrradiancePS"; meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_PreFilteredPS"); shaderBytecode = new ShaderBytecode(meta.Bytecode); PreFilteredPS = ToDispose(new PixelShader(m_Device, shaderBytecode)); PreFilteredPS.DebugName = "PreFilteredPS"; meta = AM.LoadAsset <AssetsMeta.ShaderAsset>("IBL_PR_SphereToCubeMapVS"); shaderBytecode = new ShaderBytecode(meta.Bytecode); SphereToCubeMapVS = ToDispose(new VertexShader(m_Device, shaderBytecode)); SphereToCubeMapVS.DebugName = "SphereToCubeMapVS"; CustomInputLayout = ToDispose(new InputLayout(m_Device, ShaderSignature.GetInputSignature(shaderBytecode), new InputElement[] { new InputElement("SV_VertexID", 0, Format.R32G32B32_Float, 0, 0), })); // Create the per environment map buffer ViewProjection matrices ConstantsBuffer = ToDispose(new Buffer( m_Device, Utilities.SizeOf <Matrix>() * 2, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0) ); ConstantsBuffer.DebugName = "ConstantsBuffer"; BRDFParamsBuffer = ToDispose(new Buffer( m_Device, Utilities.SizeOf <BRDFParamsBufferStruct>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0) ); BRDFParamsBuffer.DebugName = "BRDFParamsBuffer"; Sampler = ToDispose(new SamplerState(m_Device, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, // Trilinear AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, ComparisonFunction = Comparison.Never, MipLodBias = 0, MinimumLod = 0, MaximumLod = float.MaxValue })); Sampler.DebugName = "DefaultTrilinearSampler"; }