/// <summary> /// Function to build the layer that contains the sun. /// </summary> /// <param name="renderer">The 2D renderer for the application.</param> /// <param name="resources">The resources for the application.</param> /// <returns>The sprite layer that will contain the sun sprite.</returns> public static SpritesLayer GetSunLayer(Gorgon2D renderer, ResourceManagement resources) { GorgonSprite sunSprite = resources.Sprites["Star"]; var sunLayer = new SpritesLayer(renderer) { ParallaxLevel = 2980.0f, // The sun is pretty far away the last I checked. Sprites = { new SpriteEntity("Sun") { Sprite = sunSprite, LocalPosition = new DX.Vector2(1200, -650) } }, PostProcessGroup = "Final Pass", Lights = { new Light { Attenuation = float.MaxValue.Sqrt(), Color = GorgonColor.White, SpecularPower = 6.0f, LocalLightPosition = new DX.Vector3(1200, -650, -1.0f), Intensity = 13.07f } } }; sunLayer.LoadResources(); return(sunLayer); }
/// <summary>Initializes a new instance of the <see cref="PlanetLayer"/> class.</summary> /// <param name="graphics">The graphics interface for the application.</param> /// <param name="resources">The resources for the application.</param> public PlanetLayer(GorgonGraphics graphics, ResourceManagement resources) { _graphics = graphics; _resources = resources; _stateBuilder = new GorgonPipelineStateBuilder(graphics); _drawCallBuilder = new GorgonDrawIndexCallBuilder(); }
/// <summary> /// Function to build the background layer representing distant stars. /// </summary> /// <param name="renderer">The 2D renderer for the application.</param> /// <param name="resources">The resources for the application.</param> /// <returns>The background layer.</returns> public static BgStarLayer GetBackgroundLayer(Gorgon2D renderer, ResourceManagement resources) { var backgroundLayer = new BgStarLayer(renderer) { PostProcessGroup = "Final Pass", // These post process groups allow us to assign which sprite layers end up in post processing, and which are blitted immediately. StarsTexture = resources.Textures["StarsNoAlpha"] }; backgroundLayer.LoadResources(); return(backgroundLayer); }
/// <summary> /// Function to return the 3D layer that contains our planet. /// </summary> /// <param name="graphics">The graphics interface for the application.</param> /// <param name="resources">The resources for the application.</param> /// <returns>The 3D planet layer.</returns> public static PlanetLayer GetPlanetLayer(GorgonGraphics graphics, ResourceManagement resources) { // Create our planet. var planetLayer = new PlanetLayer(graphics, resources) { ParallaxLevel = 50, // Kinda far away. Planets = { new Planet(new PlanetaryLayer[] { new PlanetaryLayer(resources.Meshes["earthSphere"]) { Animation = resources.Animations["PlanetRotation"] }, new PlanetaryLayer(resources.Meshes["earthCloudSphere"]) { Animation = resources.Animations["CloudRotation"] }, }) { Position = new DX.Vector3(-30, -15, 4.0f) } } }; // Add an ambient light to the planet so we can see some details without a major light source. planetLayer.Lights.Add(new Light { Attenuation = float.MaxValue.Sqrt(), Color = GorgonColor.White, SpecularPower = 0.0f, Intensity = 0.3f, LocalLightPosition = new DX.Vector3(0, 0, -10000.0f), Layers = { planetLayer } }); planetLayer.LoadResources(); planetLayer.PostProcessGroup = "Final Pass"; return(planetLayer); }
/// <summary> /// Function to initialize the application. /// </summary> private static async Task InitializeAsync(FormMain window) { try { GorgonExample.ResourceBaseDirectory = new DirectoryInfo(Settings.Default.ResourceLocation); GorgonExample.PlugInLocationDirectory = new DirectoryInfo(Settings.Default.PlugInLocation); // Load our packed file system plug in. window.UpdateStatus("Loading plugins..."); IGorgonPlugInService plugIns = await Task.Run(() => { _assemblyCache = new GorgonMefPlugInCache(GorgonApplication.Log); _assemblyCache.LoadPlugInAssemblies(GorgonExample.GetPlugInPath().FullName, "Gorgon.FileSystem.GorPack.dll"); return(new GorgonMefPlugInService(_assemblyCache)); }); window.UpdateStatus("Initializing graphics..."); // Retrieve the list of video adapters. We can do this on a background thread because there's no interaction between other threads and the // underlying D3D backend yet. IReadOnlyList <IGorgonVideoAdapterInfo> videoDevices = await Task.Run(() => GorgonGraphics.EnumerateAdapters(log: GorgonApplication.Log)); if (videoDevices.Count == 0) { throw new GorgonException(GorgonResult.CannotCreate, "Gorgon requires at least a Direct3D 11.4 capable video device.\nThere is no suitable device installed on the system."); } // Find the best video device. _graphics = new GorgonGraphics(videoDevices.OrderByDescending(item => item.FeatureSet).First()); _screen = new GorgonSwapChain(_graphics, window, new GorgonSwapChainInfo("Gorgon2D Space Scene Example") { Width = Settings.Default.Resolution.Width, Height = Settings.Default.Resolution.Height, Format = BufferFormat.R8G8B8A8_UNorm }); // Create a secondary render target for our scene. We use 16 bit floating point for the effect fidelity. // We'll lock our resolution to 1920x1080 (pretty common resolution for most people). _mainRtv = GorgonRenderTarget2DView.CreateRenderTarget(_graphics, new GorgonTexture2DInfo("Main RTV") { Width = (int)_baseResolution.X, Height = (int)_baseResolution.Y, Format = BufferFormat.R16G16B16A16_Float, Binding = TextureBinding.ShaderResource }); _mainSrv = _mainRtv.GetShaderResourceView(); _mainRtvAspect = _mainRtv.Width < _mainRtv.Height ? new DX.Vector2(1, (float)_mainRtv.Height / _mainRtv.Width) : new DX.Vector2((float)_mainRtv.Width / _mainRtv.Height, 1); // Initialize the renderer so that we are able to draw stuff. _renderer = new Gorgon2D(_graphics); // Set up our raw input. _input = new GorgonRawInput(window, GorgonApplication.Log); _keyboard = new GorgonRawKeyboard(); _keyboard.KeyUp += Keyboard_KeyUp; _input.RegisterDevice(_keyboard); GorgonExample.LoadResources(_graphics); // Now for the fun stuff, load our asset resources. We can load this data by mounting a directory (which I did while developing), or use a packed file. // // The resource manager will hold all the data we need for the scene. Including 3D meshes, post processing effects, etc... _resources = new ResourceManagement(_renderer, plugIns); _resources.Load(Path.Combine(GorgonExample.GetResourcePath(@"FileSystems").FullName, "SpaceScene.gorPack")); window.UpdateStatus("Loading resources..."); await _resources.LoadResourcesAsync(); SetupScene(); // Build up a font to use for rendering any GUI text. _helpFont = GorgonExample.Fonts.GetFont(new GorgonFontInfo("Segoe UI", 10.0f, FontHeightMode.Points, "Segoe UI 10pt") { OutlineSize = 2, Characters = (Resources.Instructions + "S:1234567890x").Distinct().ToArray(), FontStyle = FontStyle.Bold, AntiAliasingMode = FontAntiAliasMode.AntiAlias, OutlineColor1 = GorgonColor.Black, OutlineColor2 = GorgonColor.Black }); _textSprite = new GorgonTextSprite(_helpFont) { Position = new DX.Vector2(0, 64), DrawMode = TextDrawMode.OutlinedGlyphs, Color = GorgonColor.YellowPure }; GorgonExample.ShowStatistics = true; // Set the idle here. We don't want to try and render until we're done loading. GorgonApplication.IdleMethod = Idle; } finally { GorgonExample.EndInit(); } }
/// <summary> /// Function to retrieve the layer with our ship on it. /// </summary> /// <param name="renderer">The 2D renderer for the application.</param> /// <param name="resources">The resources for the application.</param> /// <returns>The sprite layer containing our ship.</returns> public static SpritesLayer GetShipLayer(Gorgon2D renderer, ResourceManagement resources) { var ship = new SpritesLayer(renderer) { DeferredLighter = resources.Effects["deferredLighting"] as Gorgon2DDeferredLightingEffect, Sprites = { new SpriteEntity("BigShip") { Sprite = resources.Sprites["BigShip"], Color = GorgonColor.Gray20, // Make this a bit darker so that we can light it using per-pixel lighting. Rotation = -95.0f, IsLit = true, Visible = false }, new SpriteEntity("BigShip_Illum") { Sprite = resources.Sprites["BigShip_Illum"], Color = GorgonColor.YellowPure * 0.70f, Rotation = -95.0f, IsLit = false, Visible = false, BlendState = GorgonBlendState.Additive }, new SpriteEntity("EngineGlow") { Sprite = resources.Sprites["Fighter_Engine_F0"], Color = new GorgonColor(GorgonColor.CyanPure * 0.75f, 0), Rotation = -45.0f, Anchor = new DX.Vector2(0.5f, -1.5f), Animation = resources.Animations["EngineGlow"] }, new SpriteEntity("Fighter") { Sprite = resources.Sprites["Fighter"], Color = GorgonColor.Gray20, // Make this a bit darker so that we can light it using per-pixel lighting. Rotation = -45.0f, IsLit = true } }, Offset = DX.Vector2.Zero, PostProcessGroup = "Final Pass", Lights = { new Light { Intensity = 0.25f, LightType = LightType.Directional, LightDirection = new DX.Vector3(1.0f, 0.0f, 0.7071068f), SpecularEnabled = true, SpecularPower = 128, Color = GorgonColor.White, } } }; ship.Lights[0].Layers.Add(ship); ship.LoadResources(); return(ship); }