/// <summary> /// Function to build up our post process compositor list. /// </summary> private void BuildPostProcessCompositors() { var chromatic = new Gorgon2DChromaticAberrationEffect(_renderer) { Intensity = 0.125f }; var bloom = new Gorgon2DBloomEffect(_renderer) { BloomIntensity = 7.0f, BlurAmount = 10.0f, Color = new GorgonColor(191 / 255.0f, 80 / 255.0f, 21 / 255.0f, 1), ColorIntensity = 4, Threshold = 1.02f, DirtTexture = Textures["LensDirt_2"], DirtIntensity = 192 }; bloom.Precache(); var finalPostProcess = new Gorgon2DCompositor(_renderer); finalPostProcess .Clear() .InitialClearColor(GorgonColor.BlackTransparent) .FinalClearColor(GorgonColor.BlackTransparent) .EffectPass("Chromatic Aberration", chromatic) .EffectPass("Bloom", bloom); _postProcess["Final Pass"] = finalPostProcess; var deferredLighting = new Gorgon2DDeferredLightingEffect(_renderer); _effects[nameof(bloom)] = bloom; _effects[nameof(chromatic)] = chromatic; _effects[nameof(deferredLighting)] = deferredLighting; }
/// <summary> /// Function to initialize the application. /// </summary> /// <returns>The main window for the application.</returns> private static FormMain Initialize() { GorgonExample.ResourceBaseDirectory = new DirectoryInfo(Settings.Default.ResourceLocation); FormMain window = GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Lights"); try { IReadOnlyList <IGorgonVideoAdapterInfo> videoDevices = 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 Effects Example Swap Chain") { Width = Settings.Default.Resolution.Width, Height = Settings.Default.Resolution.Height, Format = BufferFormat.R8G8B8A8_UNorm }); _screen.BeforeSwapChainResized += Screen_BeforeSwapChainResized; _screen.AfterSwapChainResized += Screen_AfterSwapChainResized; // Tell the graphics API that we want to render to the "screen" swap chain. _graphics.SetRenderTarget(_screen.RenderTargetView); // Load in our texture for our logo background. _backgroundLogoTexture = GorgonTexture2DView.FromFile(_graphics, Path.Combine(GorgonExample.GetResourcePath(@"Textures\Lights\").FullName, "lights.dds"), new GorgonCodecDds(), new GorgonTexture2DLoadOptions { Usage = ResourceUsage.Immutable, Binding = TextureBinding.ShaderResource, Name = "Logo" }); _torchTexture = GorgonTexture2DView.FromFile(_graphics, Path.Combine(GorgonExample.GetResourcePath(@"Textures\Lights\").FullName, "Torch.png"), new GorgonCodecPng(), new GorgonTexture2DLoadOptions { Usage = ResourceUsage.Immutable, Binding = TextureBinding.ShaderResource, Name = "Torch" }); UpdateRenderTarget(); // Initialize the renderer so that we are able to draw stuff. _renderer = new Gorgon2D(_graphics); _logoSprite = new GorgonSprite { Texture = _backgroundLogoTexture, Bounds = new DX.RectangleF(0, 0, _backgroundLogoTexture.Width, _backgroundLogoTexture.Height), TextureRegion = new DX.RectangleF(0, 0, 1, 1), Anchor = new DX.Vector2(0.5f, 0.5f) }; _torchSprite = new GorgonSprite { Texture = _torchTexture, Bounds = new DX.RectangleF(0, 0, 55, _torchTexture.Height), TextureRegion = _torchTexture.Texture.ToTexel(new DX.Rectangle(0, 0, 55, _torchTexture.Height)), }; // Create the effect that will light up our sprite(s). _lightEffect = new Gorgon2DDeferredLightingEffect(_renderer) { FlipYNormal = true // Need this to be true because CrazyBump exported the normal map with Y inverted. }; _lightEffect.Lights.Add(new Gorgon2DLight { Color = new GorgonColor(0.25f, 0.25f, 0.25f), Attenuation = 75, LightType = LightType.Point, SpecularEnabled = true, SpecularPower = 6.0f, Position = new DX.Vector3((_screen.Width / 2.0f) - 150.0f, (_screen.Height / 2.0f) - 150.0f, -50) }); _lightEffect.Lights.Add(new Gorgon2DLight { Color = GorgonColor.White, Intensity = 0.075f, LightType = LightType.Directional, SpecularEnabled = false, Position = new DX.Vector3(0, 0, -200), LightDirection = new DX.Vector3(0, 0, 1) }); GorgonExample.LoadResources(_graphics); window.MouseMove += Window_MouseMove; window.KeyDown += Window_KeyDown; _torchFrameTime = new GorgonTimerQpc(); return(window); } finally { GorgonExample.EndInit(); } }