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 static void HotReload_NOT(AssetsManagerInstance AM) { AM.ImportAsset(@"Deffered\CommonVS.hlsl", "CommonVS", true); //AM.ImportShaderAsset(@"Commons\ScreenQuadPS.hlsl", "ScreenQuadPS", "PSMain", true); //AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "MSAA_LightPassPS", "PSMain", "MSAA", true); //AM.ImportShaderAsset(@"Commons\ScreenQuadPS.hlsl", "MSAA_ScreenQuadPS", "PSMain", "MSAA", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassPS", "PSMain", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferPS", "FillGBufferPS", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferSkyboxPS", "FillGBufferPS", "TEXTURE_CUBE_ALBEDO_MAP", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferMaskedPS", "FillGBufferPS", "MASKED", true); //AM.ImportShaderAsset(@"Deffered\DownscalingCS.hlsl", "DownsamplingFirstCS", "DownScaleFirstPass", true); //AM.ImportShaderAsset(@"Deffered\DownscalingCS.hlsl", "DownsamplingSecondCS", "DownScaleSecondPass", true); AM.ImportShaderAsset(@"Commons\ScreenQuadPS.hlsl", "ScreenQuadPS", "PSMain", true); AM.ImportShaderAsset(@"Commons\ScreenQuadVS.hlsl", "ScreenQuadVS", "VSMain", true); Dictionary <string, string> pathNamePairs = new Dictionary <string, string>(); //pathNamePairs.Add("Textures/SnowRock/rock-snow-ice1-2k_Base_Color.png", "SnowRockAlbedoMap"); foreach (string path in pathNamePairs.Keys) { AM.ImportAsset(RawContentPath + path, pathNamePairs[path], true); } //AM.CreateMaterialAsset("SnowRockMaterial", "SnowRockAlbedoMap", // "SnowRockNormalMap", "SnowRockRoughnessMap", // "SnowRockMetallicMap", "SnowRockOcclusionMap"); }
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; }
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; }
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); } }
private static void CreateMaterials(AssetsManagerInstance AM) { AM.CreateMaterialAsset("SponzaCurtainBlueMaterial", "SponzaCurtainBlueAlbedo", "SponzaCurtainBlueNormal"); AM.CreateMaterialAsset("SponzaCurtainRedMaterial", "SponzaCurtainRedAlbedo", "SponzaCurtainBlueNormal"); AM.CreateMaterialAsset("SponzaCurtainGreenMaterial", "SponzaCurtainGreenAlbedo", "SponzaCurtainBlueNormal"); AM.CreateMaterialAsset("SponzaFabricBlueMaterial", "SponzaFabricBlueAlbedo", "SponzaFabricBlueNormal"); AM.CreateMaterialAsset("SponzaFabricRedMaterial", "SponzaFabricRedAlbedo", "SponzaFabricBlueNormal"); AM.CreateMaterialAsset("SponzaFabricGreenMaterial", "SponzaFabricGreenAlbedo", "SponzaFabricBlueNormal"); AM.CreateMaterialAsset("SponzaArchMaterial", "SponzaArcAlbedo", "SponzaArcNormal"); AM.CreateMaterialAsset("SponzaFloorMaterial", "SponzaFloorAlbedo", "SponzaFloorNormal"); AM.CreateMaterialAsset("SponzaRoofMaterial", "SponzaRoofAlbedo", "SponzaRoofNormal"); AM.CreateMaterialAsset("SponzaColumnAMaterial", "SponzaColumnAAlbedo", "SponzaColumnANormal"); AM.CreateMaterialAsset("SponzaColumnBMaterial", "SponzaColumnBAlbedo", "SponzaColumnBNormal"); AM.CreateMaterialAsset("SponzaColumnCMaterial", "SponzaColumnCAlbedo", "SponzaColumnCNormal"); AM.CreateMaterialAsset("LionMaterial", "LionAlbedo", "LionNormal"); AM.CreateMaterialAsset("CopperMaterial", "CopperAlbedoMap", "CopperNormalMap", "CopperRoughnessMap", "CopperMetallicMap"); AM.CreateMaterialAsset("MetalSplotchyMaterial", "MetalSplotchyAlbedoMap", "MetalSplotchyNormalMap", "MetalSplotchyRoughnessMap", "MetalSplotchyMetallicMap"); AM.CreateMaterialAsset("SnowRockMaterial", "SnowRockAlbedoMap", "SnowRockNormalMap", "SnowRockRoughnessMap", "SnowRockMetallicMap", "SnowRockOcclusionMap"); }
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 static void ImportTextures(AssetsManagerInstance AM) { Dictionary <string, string> pathNamePairs = new Dictionary <string, string>(); pathNamePairs.Add(@"Textures\WoodenLatticeMap.png", "WoodenLatticeMap"); pathNamePairs.Add(@"SponzaMaps\sponza_floor_a_diff.png", "SponzaFloorAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_floor_a_diff_NRM.png", "SponzaFloorNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_roof_diff.png", "SponzaRoofAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_roof_diff_NRM.png", "SponzaRoofNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_column_a_diff.png", "SponzaColumnAAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_column_a_ddn.png", "SponzaColumnANormal"); pathNamePairs.Add(@"SponzaMaps\sponza_column_b_diff.png", "SponzaColumnBAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_column_b_ddn.png", "SponzaColumnBNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_column_c_diff.png", "SponzaColumnCAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_column_c_ddn.png", "SponzaColumnCNormal"); pathNamePairs.Add(@"SponzaMaps\lion.png", "LionAlbedo"); pathNamePairs.Add(@"SponzaMaps\lion_ddn.png", "LionNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_curtain_blue_diff.png", "SponzaCurtainBlueAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_curtain_blue_diff_NRM.png", "SponzaCurtainBlueNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_curtain_diff.png", "SponzaCurtainRedAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_curtain_green_diff.png", "SponzaCurtainGreenAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_fabric_blue_diff.png", "SponzaFabricBlueAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_fabric_blue_diff_NRM.png", "SponzaFabricBlueNormal"); pathNamePairs.Add(@"SponzaMaps\sponza_fabric_diff.png", "SponzaFabricRedAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_fabric_green_diff.png", "SponzaFabricGreenAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_arch_diff.png", "SponzaArcAlbedo"); pathNamePairs.Add(@"SponzaMaps\sponza_arch_diff_NRM.png", "SponzaArcNormal"); pathNamePairs.Add(@"Textures\MetalMat\oxidized-copper-albedo.png", "CopperAlbedoMap"); pathNamePairs.Add(@"Textures\MetalMat\oxidized-copper-normal-ue.png", "CopperNormalMap"); pathNamePairs.Add(@"Textures\MetalMat\oxidized-copper-roughness.png", "CopperRoughnessMap"); pathNamePairs.Add(@"Textures\MetalMat\oxidized-copper-metal.png", "CopperMetallicMap"); pathNamePairs.Add(@"Textures\DebugTextureGrid.jpg", "DebugTextureMap"); pathNamePairs.Add(@"Textures\cow.jpg", "CowAlbedoMap"); pathNamePairs.Add(@"Textures\MetalMat\metal-splotchy-albedo.png", "MetalSplotchyAlbedoMap"); pathNamePairs.Add(@"Textures\MetalMat\metal-splotchy-normal-dx.png", "MetalSplotchyNormalMap"); pathNamePairs.Add(@"Textures\MetalMat\metal-splotchy-rough.png", "MetalSplotchyRoughnessMap"); pathNamePairs.Add(@"Textures\MetalMat\metal-splotchy-metal.png", "MetalSplotchyMetallicMap"); pathNamePairs.Add(@"Textures\SnowRock\rock-snow-ice1-2k_Base_Color.png", "SnowRockAlbedoMap"); pathNamePairs.Add(@"Textures\SnowRock\rock-snow-ice1-2k_Normal-dx.png", "SnowRockNormalMap"); pathNamePairs.Add(@"Textures\SnowRock\rock-snow-ice1-2k_Roughness.png", "SnowRockRoughnessMap"); pathNamePairs.Add(@"Textures\SnowRock\rock-snow-ice1-2k_Metallic.png", "SnowRockMetallicMap"); pathNamePairs.Add(@"Textures\SnowRock\rock-snow-ice1-2k_Ambient_Occlusion.png", "SnowRockOcclusionMap"); foreach (string path in pathNamePairs.Keys) { AM.ImportAsset(RawContentPath + path, pathNamePairs[path], true); } }
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; }; }
private static void ImportShaders(AssetsManagerInstance AM) { AM.ImportAsset(@"Commons\CommonVS.hlsl", "CommonVS", true); AM.ImportShaderAsset(@"Deffered\LightVolumes.hlsl", "LightVolumesVS", "LightVolumesVS", true); AM.ImportShaderAsset(@"Deffered\LightVolumes.hlsl", "LightVolumesHS", "LightVolumesHS", true); AM.ImportShaderAsset(@"Deffered\LightVolumes.hlsl", "PointLightVolumeDS", "LightVolumeDS", "POINT_LIGHT", true); AM.ImportShaderAsset(@"Deffered\LightVolumes.hlsl", "SpotLightVolumeDS", "LightVolumeDS", "SPOT_LIGHT", true); AM.ImportShaderAsset(@"Deffered\LightVolumes.hlsl", "CapsuleLightVolumeDS", "LightVolumeDS", "CAPSULE_LIGHT", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferVS", "FillGBufferVS", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferPS", "FillGBufferPS", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferSkyboxPS", "FillGBufferPS", "TEXTURE_CUBE_ALBEDO_MAP", true); AM.ImportShaderAsset(@"Deffered\FillGBuffer.hlsl", "FillGBufferMaskedPS", "FillGBufferPS", "MASKED", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassVS", "VSMain", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassPS", "PSMain", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "MSAA_LightPassPS", "PSMain", "MSAA", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassDirectionalPS", "PSDirectionalLight", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassDirectionalPS", "PSDirectionalLight", "MSAA", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassPointPS", "PSPointLight", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "MSAA_LightPassPointPS", "PSPointLight", "MSAA", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "LightPassPointQuadPS", "PSPointLight", "SQUAD", true); AM.ImportShaderAsset(@"Deffered\LightPass.hlsl", "MSAA_LightPassPointQuadPS", "PSPointLight", "SQUAD", "MSAA", true); AM.ImportShaderAsset(@"Commons\ScreenQuadPS.hlsl", "ScreenQuadPS", "PSMain", true); AM.ImportShaderAsset(@"Commons\ScreenQuadPS.hlsl", "MSAA_ScreenQuadPS", "PSMain", "MSAA", true); AM.ImportAsset(@"Commons\ScreenQuadVS.hlsl", "ScreenQuadVS", true); //Forward AM.ImportAsset(@"PBR\PBRForwardPS.hlsl", "PBRForwardPS", true); AM.ImportAsset(@"Unlit\FwdSkySpherePS.hlsl", "FwdSkySpherePS", true); AM.ImportAsset(@"ForwardPlus\LightCullingCS.hlsl", "LightCullingCS"); AM.ImportAsset(@"ForwardPlus\ForwardPlusPosOnlyVS.hlsl", "ForwardPlusPosOnlyVS", true); AM.ImportAsset(@"ForwardPlus\ForwardPlusPosTexVS.hlsl", "ForwardPlusPosTexVS", true); AM.ImportAsset(@"ForwardPlus\ForwardPlusPosTexPS.hlsl", "ForwardPlusPosTexPS", true); AM.ImportAsset(@"ForwardPlus\ForwardPlusScenePS.hlsl", "ForwardPlusScenePS", true); AM.ImportAsset(@"Unlit\ReflectionSpherePS.hlsl", "ReflectionSpherePS", true); AM.ImportAsset(@"Commons\DepthShadowsVS.hlsl", "DepthShadowsVS", true); AM.ImportAsset(@"Commons\DepthShadowsPS.hlsl", "DepthShadowsPS", true); AM.ImportAsset(@"Commons\DownSamplingPS.hlsl", "DownSamplingPS", true); AM.ImportAsset(@"Unlit\VelocityPS.hlsl", "VelocityPS", true); AM.ImportAsset(@"Unlit\MaskedVelocityPS.hlsl", "MaskedVelocityPS", true); }
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); }
private static void ImportMeshes(AssetsManagerInstance AM) { Dictionary <string, NamePlusScale> pathNamePairs = new Dictionary <string, NamePlusScale>(); pathNamePairs.Add("Sponza.fbx", new NamePlusScale("SponzaMesh", 0.03f)); pathNamePairs.Add("Cow.obj", new NamePlusScale("CowMesh", 0.0033f)); pathNamePairs.Add("skysphere_mesh.FBX", new NamePlusScale("SkyDomeMesh")); pathNamePairs.Add("cube1m.FBX", new NamePlusScale("Cube1mMesh")); foreach (string path in pathNamePairs.Keys) { AM.CreateMeshAsset(RawContentPath + path, pathNamePairs[path].name, pathNamePairs[path].scale); } }
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]; }
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"; }
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(); }