public Skybox(GraphicsDevice device) { float x = 0.525731f; float z = 0.850651f; var vertices = new SkyboxVertex[12] { new SkyboxVertex(-x, 0f, z), new SkyboxVertex(x, 0f, z), new SkyboxVertex(-x, 0f, -z), new SkyboxVertex(x, 0f, -z), new SkyboxVertex(0f, z, x), new SkyboxVertex(0f, z, -x), new SkyboxVertex(0f, -z, x), new SkyboxVertex(0f, -z, -x), new SkyboxVertex(z, x, 0f), new SkyboxVertex(-z, x, 0f), new SkyboxVertex(z, -x, 0f), new SkyboxVertex(-z, -x, 0f), }; var indices = new int[60] { 1, 4, 0, 4, 9, 0, 4, 5, 9, 8, 5, 4, 1, 8, 4, 1, 10, 8, 10, 3, 8, 8, 3, 5, 3, 2, 5, 3, 7, 2, 3, 10, 7, 10, 6, 7, 6, 11, 7, 6, 0, 11, 6, 1, 0, 10, 1, 6, 11, 0, 9, 2, 11, 9, 5, 2, 9, 11, 2, 7 }; vertexBuffer = Buffer <SkyboxVertex> .New(device, vertices, BufferFlags.VertexBuffer); indexBuffer = Buffer <int> .New(device, indices, BufferFlags.IndexBuffer); skyboxEffect = EffectLoader.Load(@"Graphics/Shaders/Skybox.fx"); skyboxTex = Texture2D.Load(device, @"G:\Users\Athrun\Documents\Stratum\trunk\src\Stratum\WorldEngine\Earth\milkyWay.tif"); }
public virtual void Initialize() { GraphicsDevice device = Engine.GraphicsContext.Device; wireFrame = EffectLoader.Load(@"World/Earth/Shaders/DeferredTerrain.fx"); vertexBuffer = Buffer <TerrainVertex> .New <TerrainVertex>(device, SharpDX.Utilities.SizeOf <TerrainVertex>() * 4 * 1000, BufferFlags.VertexBuffer, SharpDX.Direct3D11.ResourceUsage.Dynamic); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="device"></param> /// <param name="filename">エフェクトパス</param> /// <param name="resourceManager">リソースマネージャー</param> public EffectObject(PPDDevice device, Resource.ResourceManager resourceManager, PathObject filename) : base(device) { this.resourceManager = resourceManager; manager = EffectLoader.Load(filename, LoadFunc); if (manager == null) { MessageBox.Show("Failed to load effect:" + filename); return; } manager.Finish += manager_Finish; Alignment = EffectAlignment.Center; PlayType = EffectManager.PlayType.Once; }
public Renderer() { IGraphicsContext context = Engine.GraphicsContext; int width = context.Device.BackBuffer.Width; int height = context.Device.BackBuffer.Height; sceneTarget = RenderTarget2D.New(context.Device, width, height, PixelFormat.R8G8B8A8.UNorm); texToTargetEffect = EffectLoader.Load(@"Graphics/Shaders/CopyTextureToTarget.fx"); gbuffer = context.GBuffer; font = FontLoader.Load(@"Graphics/Fonts/Arial16.xml"); fpsClock = new Stopwatch(); fpsText = string.Empty; }
private void AddEffectInfo() { var path = Path.Combine(WindowUtility.MainForm.CurrentProjectDir, Path.Combine("Resource", treeView1.SelectedNode.FullPath)); if (!File.Exists(path)) { return; } try { var refs = EffectLoader.GetEffectReference(path); var manager = EffectLoader.Load(path, false, (fn) => { }); AddInfo(Utility.Language["ReferenceEffect"], String.Join(", ", refs)); AddInfo(Utility.Language["FrameCount"], manager.FrameLength); AddInfo(Utility.Language["StartFrame"], manager.StartFrame); int layerCount = 0; var effects = new Queue <IEffect>(); effects.Enqueue(manager); while (effects.Count > 0) { var effect = effects.Dequeue(); if (effect.Effects.Count == 0) { layerCount++; } else { foreach (IEffect childEffect in effect.Effects) { effects.Enqueue(childEffect); } } } AddInfo(Utility.Language["LayerCount"], layerCount); AddInfo(Utility.Language["FPS"], manager.FPS); var effectPanel = new EffectPanel(); effectPanel.SetLang(); effectPanel.OpenFile(path); ChangePanel(effectPanel); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void OpenEffect(string effectfilename) { ResetEffect(EffectLoader.Load(effectfilename, (filename) => { try { var image = Image.FromFile(filename); if (!canvasDock.ImagePool.ContainsKey(filename)) { canvasDock.ImagePool.Add(filename, image); } } catch { MessageBox.Show("Failed to load image"); } })); openfilename = effectfilename; if (this.最近使用したファイルToolStripMenuItem.DropDownItems.ContainsKey(effectfilename)) { var tsmis = this.最近使用したファイルToolStripMenuItem.DropDownItems.Find(effectfilename, false); if (tsmis.Length == 1) { this.最近使用したファイルToolStripMenuItem.DropDownItems.Remove(tsmis[0]); this.最近使用したファイルToolStripMenuItem.DropDownItems.Insert(0, tsmis[0]); } } else { var tsmi = new ToolStripMenuItem(effectfilename) { Name = effectfilename }; tsmi.Click += tsmi_Click; this.最近使用したファイルToolStripMenuItem.DropDownItems.Insert(0, tsmi); if (this.最近使用したファイルToolStripMenuItem.DropDownItems.Count > 5) { this.最近使用したファイルToolStripMenuItem.DropDownItems.RemoveAt(this.最近使用したファイルToolStripMenuItem.DropDownItems.Count - 1); } } }
public void OpenFile(string path) { dict = new Dictionary <string, Image>(StringComparer.OrdinalIgnoreCase); var dir = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)); effectManager = EffectLoader.Load(path, false, (fn) => { var filename = Path.Combine(dir, fn); using (Image image = Image.FromFile(filename)) { if (!dict.ContainsKey(filename)) { dict.Add(filename, new Bitmap(image)); } } }); effectManager.Finish += effectManager_Finish; canvasPanel.DrawAndRefresh(); }
public override void Execute() { var em = EffectLoader.Load(filename, (fn) => { var image = Image.FromFile(fn); if (!ImagePool.ContainsKey(fn)) { ImagePool.Add(fn, image); } } ); var be = new BaseEffect { Filename = filename }; be.SetDefault(); be.Effects = em.Effects; be.FPS = em.FPS; manager.Effects.Insert(insertindex, be); }
public Atmosphere() { GraphicsDevice device = Engine.GraphicsContext.Device; transmittanceT = RenderTarget2D.New(device, TRANSMITTANCE_W, TRANSMITTANCE_H, PixelFormat.R16G16B16A16.Float); irradianceT = RenderTarget2D.New(device, SKY_W, SKY_H, PixelFormat.R16G16B16A16.Float); inscatterT = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float); deltaET = RenderTarget2D.New(device, SKY_W, SKY_H, PixelFormat.R16G16B16A16.Float); deltaSRT = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float); deltaSMT = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float); deltaJT = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float); atmosphere = EffectLoader.Load(@"World/Atmosphere/Shaders/atmosphere.fx"); copyInscatter1 = EffectLoader.Load(@"World/Atmosphere/Shaders/copyInscatter1.fx"); copyInscatterN = EffectLoader.Load(@"World/Atmosphere/Shaders/copyInscatterN.fx"); copyIrradiance = EffectLoader.Load(@"World/Atmosphere/Shaders/copyIrradiance.fx"); inscatter1 = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatter1.fx"); inscatterN = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatterN.fx"); inscatterS = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatterS.fx"); irradiance1 = EffectLoader.Load(@"World/Atmosphere/Shaders/irradiance1.fx"); irradianceN = EffectLoader.Load(@"World/Atmosphere/Shaders/irradianceN.fx"); transmittance = EffectLoader.Load(@"World/Atmosphere/Shaders/transmittance.fx"); QuadVert[] verts = new QuadVert[6] { new QuadVert(-1, -1, 0), new QuadVert(-1, 1, 0), new QuadVert(1, 1, 0), new QuadVert(1, 1, 0), new QuadVert(1, -1, 0), new QuadVert(-1, -1, 0) }; vb = SharpDX.Toolkit.Graphics.Buffer.New <QuadVert>(device, verts, BufferFlags.VertexBuffer); PreProcess(); }
private static object DoLoad(string file, string ext) { if (ext == "grf") { return(File.OpenRead(file)); } else { using (var br = ReadSync(file)) { if (br == null) { throw new Exception($"Could not load file: {file}"); } switch (ext) { // Images case "jpg": case "jpeg": case "png": return(new RawImage() { data = br.ToArray() }); case "bmp": return(loader.LoadBMP(br)); case "tga": return(TGALoader.LoadTGA(br)); // Text case "txt": case "xml": case "lua": return(Encoding.UTF8.GetString(br.ToArray())); case "spr": SPR spr = SpriteLoader.Load(br); spr.SwitchToRGBA(); spr.Compile(); spr.filename = file; return(spr); case "str": return(EffectLoader.Load(br, Path.GetDirectoryName(file).Replace("\\", "/"))); case "act": return(ActionLoader.Load(br)); // Binary case "gat": return(AltitudeLoader.Load(br)); case "rsw": return(WorldLoader.Load(br)); case "gnd": return(GroundLoader.Load(br)); case "rsm": return(ModelLoader.Load(br)); // Audio case "wav": WAVLoader.WAVFile wav = WAVLoader.OpenWAV(br.ToArray()); AudioClip clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false); clip.SetData(wav.leftChannel, 0); return(clip); case "mp3": case "ogg": break; case "json": return(JObject.Parse(Encoding.UTF8.GetString(br.ToArray()))); default: throw new Exception($"Unsuported file format: {ext} for file {file}"); } } } return(null); }
private void UnPackAll(PackReader packReader, string spriteDirName, DateTime lastWriteTime) { var imageList = new List <string>(); var effectImageList = new Dictionary <string, List <string> >(); foreach (var fileName in packReader.FileList) { if (!fileName.StartsWith("Effect", StringComparison.Ordinal)) { continue; } var split = fileName.Split('\\'); if (split.Length < 3) { continue; } var effectName = split[1]; var effectImageName = split[2]; var normalizedEffectImageName = SpriteDictionary.RemoveScale(effectImageName); var key = Path.Combine("Effect", effectName, normalizedEffectImageName); if (!effectImageList.TryGetValue(key, out List <string> effectImageNames)) { effectImageNames = new List <string>(); effectImageList.Add(key, effectImageNames); } effectImageNames.Add(fileName); } foreach (string resourceName in packReader.FileList) { var ppdpsr = packReader.Read(resourceName); var split = resourceName.Split('\\'); if (split.Length == 2) { switch (split[0]) { case "Image": imageList.Add(resourceName); break; case "Effect": if (Path.GetExtension(resourceName) == ".etd") { EffectLoader.Load(ppdpsr, resourceName, (ReadResourceCallBack)((filename) => { if (effectImageList.ContainsKey(filename)) { foreach (var imageFileName in effectImageList[filename]) { imageList.Add(imageFileName); } } }), f => packReader.Read(f)); } break; case "Sound": byte[] data = new byte[ppdpsr.Length]; ppdpsr.Read(data, 0, data.Length); soundDict.Add(resourceName, data); break; case "Others": data = new byte[ppdpsr.Length]; ppdpsr.Read(data, 0, data.Length); othersDict.Add(resourceName, data); break; } } } var spriteManager = new PPDPackSpriteManager(packReader, imageList.ToArray(), spriteDirName, lastWriteTime); spriteManager.Pack(); resourceManager = new SpriteResourceManager(device, spriteManager); }
public object GetResource(string resourceName, ResourceKind resourceKind, Dictionary <string, object> param) { if (initialized) { Vector2 position = param != null && param.ContainsKey("Position") ? (Vector2)param["Position"] : Vector2.Zero; switch (resourceKind) { case ResourceKind.Effect: var path = String.Format("Effect\\{0}", resourceName); if (EffectLoader.IsCached(path)) { return(new EffectObject(device, resourceManager, EffectLoader.Load(null, path, f => { return; }, f => null)) { Position = position }); } return(null); case ResourceKind.Image: var isCenter = (bool)param["IsCenter"]; return(new PictureObject(device, resourceManager, pathManager.Combine("Image", resourceName), isCenter) { Position = position }); case ResourceKind.Sound: soundID++; var name = String.Format("Sound\\{0}_{1}", resourceName, soundID); var soundResource = new SoundResource(sound, name, soundDict[String.Format("Sound\\{0}", resourceName)]); resourceManager.Add(name, soundResource); return(soundResource); case ResourceKind.Number: var alignment = (Alignment)param["Alignment"]; var maxDigit = (int)param["MaxDigit"]; return(new NumberPictureObject(device, resourceManager, pathManager.Combine("Image", resourceName)) { Position = position, Alignment = alignment, MaxDigit = maxDigit }); case ResourceKind.Others: return(new MemoryStream(othersDict[String.Format("Others\\{0}", resourceName)])); case ResourceKind.Rectangle: return(new RectangleComponent(device, resourceManager, (Color4)param["Color"])); case ResourceKind.VertexBuffer: var vertexInfo = device.GetModule <ShaderCommon>().CreateVertex((int)param["VertexCount"]); createdVertices.Add(vertexInfo); return(vertexInfo); case ResourceKind.Polygon: var filename = pathManager.Combine("Image", resourceName); var imageResource = resourceManager.GetResource <ImageResourceBase>(filename); if (imageResource == null) { imageResource = (ImageResourceBase)resourceManager.Add(filename, ImageResourceFactoryManager.Factory.Create(device, filename, false)); } var primitiveType = (PrimitiveType)param["PrimitiveType"]; var primitiveCount = (int)param["PrimitiveCount"]; var startIndex = (int)param["StartIndex"]; var vertexCount = (int)param["VertexCount"]; return(new PolygonObject(device, imageResource, (VertexInfo)param["Vertex"]) { PrimitiveType = primitiveType, PrimitiveCount = primitiveCount, StartIndex = startIndex, VertexCount = vertexCount, }); } } return(null); }
protected void VobDefFromSQLResults(AbstractRunnable s, DBAgent.FinishedQueueEventHandlerArgs e) { try { var cgi = GetColGetTypeInfo(); // convert the received database-results List <List <List <object> > > sqlResults = e.GetSQLResults(); DBTables.ConvertSQLResults(sqlResults, cgi); int i_VobDef = DBTableLoadOrder.IndexOf("VobDef"); List <DBTables.ColumnGetTypeInfo> cgt_VobDef = cgi[i_VobDef]; List <List <object> > tableVobDef = sqlResults[DBTableLoadOrder.IndexOf("VobDef")]; int i_VobDefEffect = DBTableLoadOrder.IndexOf("VobDefEffect"); List <DBTables.ColumnGetTypeInfo> cgt_VobDefEffect = cgi[i_VobDefEffect]; List <List <object> > tableVobDefEffect = sqlResults[DBTableLoadOrder.IndexOf("VobDefEffect")]; Dictionary <int, Effect> effectByID = null; //EffectLoader effectLoader = new EffectLoader(dbFilePath, "Vob"); EffectLoader effectLoader = new EffectLoader(GetDBFilePath(), "DefEffect", "DefChange"); effectLoader.Load(true, (object sender, EffectLoader.FinishedLoadingEffectsArgs eff) => { effectByID = eff.EffectsByID; }); if ((effectByID == null) || (effectByID.Count < 1)) { MakeLogError("Aborting generation of VobDef because no Effects were loaded!"); return; } List <IDAndEffectIDs> idAndEffectIDList = null; if (!TryGenerateIDAndEffectIDList(tableVobDefEffect, out idAndEffectIDList)) { MakeLogWarning("The provided parameter tableVobDefEffect was either null " + "or didn't contain any elements!"); } List <int> failedIndices; if (!TryGenerateVobDefs(idAndEffectIDList, effectByID, out vobDefByID, out failedIndices)) { MakeLogError("Generation of VobDef failed!"); StringBuilder sb = new StringBuilder(); sb.Append("Failed to generate VobDef with [temporary index | VobDefID]: "); for (int i = 0; i < failedIndices.Count; i++) { sb.Append("["); sb.Append(i); sb.Append("|"); if ((failedIndices[i] < 0) || (failedIndices[i] > (idAndEffectIDList.Count - 1))) { sb.Append("?"); } else { sb.Append(failedIndices[i]); } sb.Append("],"); } MakeLogError(sb.ToString()); return; } } catch (Exception ex) { MakeLogError("Failed to finish generating VodDef-objects from sqlResults: " + ex); } }
private static object DoLoad(string file, string ext) { //string fileWOExt = file.Replace("." + ext, ""); switch (ext) { case "grf": return(File.OpenRead(file)); // Regular images files case "jpg": case "jpeg": case "png": using (var br = ReadSync(file)) { return(new RawImage() { data = br.ToArray() }); } case "bmp": using (var br = ReadSync(file)) return(loader.LoadBMP(br)); case "tga": using (var br = ReadSync(file)) return(TGALoader.LoadTGA(br)); // Texts case "txt": case "xml": case "lua": using (var br = ReadSync(file)) { if (br != null) { return(Encoding.UTF8.GetString(br.ToArray())); } else { return(null); } } case "spr": using (var br = ReadSync(file)) { if (br != null) { SPR spr = SpriteLoader.Load(br); spr.SwitchToRGBA(); spr.Compile(); spr.filename = file; return(spr); } else { return(null); } } case "str": using (var br = ReadSync(file)) { if (br != null) { STR str = EffectLoader.Load(br); return(str); } else { return(null); } } // Binary case "gat": using (var br = ReadSync(file)) return(new Altitude(br)); case "rsw": using (var br = ReadSync(file)) return(WorldLoader.Load(br)); case "gnd": using (var br = ReadSync(file)) return(GroundLoader.Load(br)); case "rsm": using (var br = ReadSync(file)) return(ModelLoader.Load(br)); // Audio case "wav": using (var br = ReadSync(file)) { WAVLoader.WAVFile wav = WAVLoader.OpenWAV(br.ToArray()); AudioClip clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false); clip.SetData(wav.leftChannel, 0); return(clip); } case "mp3": case "ogg": case "act": //return new Action(ReadSync(file)).compile(); Debug.LogWarning("Can't read " + file + "\nLoader for " + ext + " is not implemented"); break; default: throw new System.Exception("Unknown file format: " + file); } return(null); }