async Task <Uri> Fog() { using (var source = new StorageFileImageSource(imageStorageFile)) { var inf = await source.GetInfoAsync(); using (var sharpnessEffect = new FogEffect(source)) { LastEffect = sharpnessEffect; return(await SaveToImage()); } } }
private void SetupAbilities() { GameObject abilityScripts = new GameObject("Ability Scripts"); _rush = abilityScripts.AddComponent <RushAbility>(); _shield = abilityScripts.AddComponent <Shield>(); _hypersonic = FindObjectOfType <Hypersonic>(); _perch = abilityScripts.AddComponent <PerchComponent>(); _flap = new FlapComponent(this); Fog = FindObjectOfType <FogEffect>(); _rush.Setup(this, Lantern); _hypersonic.Setup(this, Lantern); _shield.Setup(this, Lantern); }
void Awake() { fogEffect = FindObjectOfType<FogEffect>(); renderProperties = FindObjectOfType<RenderProperties>(); var tmp = new Texture2D(4096, 4096); tmp.LoadImage(File.ReadAllBytes("C:\\Users\\nlight\\Desktop\\sky.png")); var pixels = tmp.GetPixels(); cubemap = new Cubemap(4096, TextureFormat.RGBA32, false); cubemap.SetPixels(pixels, CubemapFace.NegativeX); cubemap.SetPixels(pixels, CubemapFace.NegativeY); cubemap.SetPixels(pixels, CubemapFace.NegativeZ); cubemap.SetPixels(pixels, CubemapFace.PositiveX); cubemap.SetPixels(pixels, CubemapFace.PositiveY); cubemap.SetPixels(pixels, CubemapFace.PositiveZ); cubemap.Apply(); }
private void EnableScreenFog(bool isOn, bool bDisableFirst = true) { if (bDisableFirst) { this.DisableScreenEffect(); } if (isOn) { if (GameLevelManager.IsPostProcessReachQuality(300)) { if (CamerasMgr.MainCameraRoot == null) { return; } this.m_fogEffect = CamerasMgr.MainCameraRoot.get_gameObject().AddMissingComponent <FogEffect>(); this.m_fogEffect.Initialization(); this.m_fogEffect.set_enabled(true); } } else if (this.m_fogEffect != null) { this.m_fogEffect.set_enabled(false); } }
//Add tile to remove fog effect queue //Being called by AtmosSimulation public void RemoveFogEvent(FogEffect node) { removeFog.Enqueue(node); }
//Add tile to add fog effect queue //Being called by AtmosSimulation public void AddFogEvent(FogEffect node) { addFog.Enqueue(node); }
public DeferredRenderer(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; screenWidth = game.Form.Form.ClientSize.Width; screenHeight = game.Form.Form.ClientSize.Height; int width = screenWidth; int height = screenHeight; gBuffer = new GBuffer(game.Device, width, height); texturePool = new TexturePool(game); meshesRenderer = new DeferredMeshesRenderer(game, gBuffer, TexturePool); directionalLightRenderer = new DirectionalLightRenderer(game, GBuffer); spotLightRenderer = new SpotLightRenderer(game, GBuffer); pointLightRenderer = new PointLightRenderer(game, GBuffer); combineFinalRenderer = new CombineFinalRenderer(game, GBuffer); var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = screenWidth, Height = screenHeight, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1 }; hdrImage = new Texture2D(device, desc); hdrImageRtv = new RenderTargetView(device, hdrImage); hdrImageRV = new ShaderResourceView(device, hdrImage); calculater = new AverageLuminanceCalculater(game, hdrImageRV); toneMap = new ToneMapRenderer(game); var tempDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, Format = Format.R32_Float, Height = 1, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Staging, Width = 1 }; tempTex = new Texture2D(device, tempDesc); ssao = new HorizonSSAORenderer(game, screenWidth, screenHeight); Vector3 radius = new Vector3(500, 1000, 500); frustumCuller = new FrustumCuller(new BoundingBox(-radius, radius), 1); gbufferView = frustumCuller.CreateView(); meshesRenderer.Culler = frustumCuller; Texture2D skyColorTexture;// = Texture2D.FromFile(game.Device, TWDir.GameData.CreateSubdirectory("Core") + "\\skyColor.bmp"); var strm = new DataStream(16 * 4, true, true); var multiplier = 2; strm.Write(new Half4(new Half(135f / 255f * multiplier), new Half(206f / 255f * multiplier), new Half(235 / 255f * multiplier), new Half(1))); strm.Position = 0; var dataRectangle = new DataRectangle(16 * 4, strm); skyColorTexture = new Texture2D(game.Device, new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R16G16B16A16_Float, Height = 1, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, Width = 1 }, dataRectangle); skyColorRV = new ShaderResourceView(game.Device, skyColorTexture); postProcessRT1 = CreateBackbufferLikeRT(); postProcessRT2 = CreateBackbufferLikeRT(); fogRenderer = new FogEffect(game); backgroundDepthStencilState = DepthStencilState.FromDescription(game.Device, new DepthStencilStateDescription() { IsDepthEnabled = true, DepthComparison = Comparison.LessEqual, DepthWriteMask = DepthWriteMask.Zero, }); lineManager = new LineManager3D(game.Device); updateRasterizerState(); }
protected override void DrawCore(RenderDrawContext context) { var input = GetInput(0); var output = GetOutput(0); if (input == null || output == null) { return; } var inputDepthTexture = GetInput(1); // Depth // Update the parameters for this post effect if (!Enabled) { if (input != output) { Scaler.SetInput(input); Scaler.SetOutput(output); Scaler.Draw(context); } return; } // If input == output, than copy the input to a temporary texture if (input == output) { var newInput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); context.CommandList.Copy(input, newInput); input = newInput; } var currentInput = input; var fxaa = Antialiasing as FXAAEffect; bool aaFirst = Bloom != null && Bloom.StableConvolution; bool needAA = Antialiasing != null && Antialiasing.Enabled; if (OutlineEffect.Enabled && inputDepthTexture != null) { // Outline var outlineOutput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); OutlineEffect.SetColorDepthInput(currentInput, inputDepthTexture, context.RenderContext.RenderView.NearClipPlane, context.RenderContext.RenderView.FarClipPlane); OutlineEffect.SetOutput(outlineOutput); OutlineEffect.Draw(context); currentInput = outlineOutput; } // do AA here, first. (hybrid method from Karis2013) if (aaFirst && needAA) { // do AA: if (fxaa != null) { fxaa.InputLuminanceInAlpha = true; } Antialiasing.SetInput(1, inputDepthTexture); bool requiresVelocityBuffer = Antialiasing.RequiresVelocityBuffer; if (requiresVelocityBuffer) { Antialiasing.SetInput(2, GetInput(6)); } var aaSurface = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); if (Antialiasing.NeedRangeDecompress) { // explanation: // The Karis method (Unreal Engine 4.1x), uses a hybrid pipeline to execute AA. // The AA is usually done at the end of the pipeline, but we don't benefit from // AA for the posteffects, which is a shame. // The Karis method, executes AA at the beginning, but for AA to be correct, it must work post tonemapping, // and even more in fact, in gamma space too. Plus, it waits for the alpha=luma to be a "perceptive luma" so also gamma space. // in our case, working in gamma space created monstruous outlining artefacts around eggageratedely strong constrasted objects (way in hdr range). // so AA works in linear space, but still with gamma luma, as a light tradeoff to supress artefacts. // create a 16 bits target for FXAA: // render range compression & perceptual luma to alpha channel: rangeCompress.SetInput(currentInput); rangeCompress.SetOutput(aaSurface); rangeCompress.Draw(context); Antialiasing.SetInput(0, aaSurface); Antialiasing.SetOutput(currentInput); Antialiasing.Draw(context); // reverse tone LDR to HDR: rangeDecompress.SetInput(currentInput); rangeDecompress.SetOutput(aaSurface); rangeDecompress.Draw(context); } else { Antialiasing.SetInput(0, currentInput); Antialiasing.SetOutput(aaSurface); Antialiasing.Draw(context); } currentInput = aaSurface; } if (AmbientOcclusion.Enabled && inputDepthTexture != null) { // Ambient Occlusion var aoOutput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); AmbientOcclusion.SetColorDepthInput(currentInput, inputDepthTexture); AmbientOcclusion.SetOutput(aoOutput); AmbientOcclusion.Draw(context); currentInput = aoOutput; } if (LocalReflections.Enabled && inputDepthTexture != null) { var normalsBuffer = GetInput(2); var specularRoughnessBuffer = GetInput(3); if (normalsBuffer != null && specularRoughnessBuffer != null) { // Local reflections var rlrOutput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); LocalReflections.SetInputSurfaces(currentInput, inputDepthTexture, normalsBuffer, specularRoughnessBuffer); LocalReflections.SetOutput(rlrOutput); LocalReflections.Draw(context); currentInput = rlrOutput; } } if (DepthOfField.Enabled && inputDepthTexture != null) { // DoF var dofOutput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); DepthOfField.SetColorDepthInput(currentInput, inputDepthTexture); DepthOfField.SetOutput(dofOutput); DepthOfField.Draw(context); currentInput = dofOutput; } if (FogEffect.Enabled && inputDepthTexture != null) { // Fog var fogOutput = NewScopedRenderTarget2D(input.Width, input.Height, input.Format); FogEffect.SetColorDepthInput(currentInput, inputDepthTexture, context.RenderContext.RenderView.NearClipPlane, context.RenderContext.RenderView.FarClipPlane); FogEffect.SetOutput(fogOutput); FogEffect.Draw(context); currentInput = fogOutput; } // Luminance pass (only if tone mapping is enabled) // TODO: This is not super pluggable to have this kind of dependencies. Check how to improve this var toneMap = colorTransformsGroup.Transforms.Get <ToneMap>(); if (colorTransformsGroup.Enabled && toneMap != null && toneMap.Enabled) { Texture luminanceTexture = null; if (toneMap.UseLocalLuminance) { const int localLuminanceDownScale = 3; // The luminance chain uses power-of-two intermediate targets, so it expects to output to one as well var lumWidth = Math.Min(MathUtil.NextPowerOfTwo(currentInput.Size.Width), MathUtil.NextPowerOfTwo(currentInput.Size.Height)); lumWidth = Math.Max(1, lumWidth / 2); var lumSize = new Size3(lumWidth, lumWidth, 1).Down2(localLuminanceDownScale); luminanceTexture = NewScopedRenderTarget2D(lumSize.Width, lumSize.Height, PixelFormat.R16_Float, 1); luminanceEffect.SetOutput(luminanceTexture); } luminanceEffect.EnableLocalLuminanceCalculation = toneMap.UseLocalLuminance; luminanceEffect.SetInput(currentInput); luminanceEffect.Draw(context); // Set this parameter that will be used by the tone mapping colorTransformsGroup.Parameters.Set(LuminanceEffect.LuminanceResult, new LuminanceResult(luminanceEffect.AverageLuminance, luminanceTexture)); } if (BrightFilter.Enabled && (Bloom.Enabled || LightStreak.Enabled || LensFlare.Enabled)) { Texture brightTexture = NewScopedRenderTarget2D(currentInput.Width, currentInput.Height, currentInput.Format, 1); // Bright filter pass BrightFilter.SetInput(currentInput); BrightFilter.SetOutput(brightTexture); BrightFilter.Draw(context); // Bloom pass if (Bloom.Enabled) { Bloom.SetInput(brightTexture); Bloom.SetOutput(currentInput); Bloom.Draw(context); } // Light streak pass if (LightStreak.Enabled) { LightStreak.SetInput(brightTexture); LightStreak.SetOutput(currentInput); LightStreak.Draw(context); } // Lens flare pass if (LensFlare.Enabled) { LensFlare.SetInput(brightTexture); LensFlare.SetOutput(currentInput); LensFlare.Draw(context); } } bool aaLast = needAA && !aaFirst; var toneOutput = aaLast ? NewScopedRenderTarget2D(input.Width, input.Height, input.Format) : output; // When FXAA is enabled we need to detect whether the ColorTransformGroup should output the Luminance into the alpha or not var luminanceToChannelTransform = colorTransformsGroup.PostTransforms.Get <LuminanceToChannelTransform>(); if (fxaa != null) { if (luminanceToChannelTransform == null) { luminanceToChannelTransform = new LuminanceToChannelTransform { ColorChannel = ColorChannel.A }; colorTransformsGroup.PostTransforms.Add(luminanceToChannelTransform); } // Only enabled when FXAA is enabled and InputLuminanceInAlpha is true luminanceToChannelTransform.Enabled = fxaa.Enabled && fxaa.InputLuminanceInAlpha; } else if (luminanceToChannelTransform != null) { luminanceToChannelTransform.Enabled = false; } // Color transform group pass (tonemap, color grading) var lastEffect = colorTransformsGroup.Enabled ? (ImageEffect)colorTransformsGroup : Scaler; lastEffect.SetInput(currentInput); lastEffect.SetOutput(toneOutput); lastEffect.Draw(context); // do AA here, last, if not already done. if (aaLast) { Antialiasing.SetInput(toneOutput); Antialiasing.SetOutput(output); Antialiasing.Draw(context); } }
public BaseDeferredRenderGame() : base() { graphics = new GraphicsDeviceManager(this); graphics.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings); Content.RootDirectory = "Content"; inputHandler = new InputHandlerService(this); assetManager = new AssetManager(this); renderer = new DeferredRender(this); rnd = new Random(DateTime.Now.Millisecond); //ggr = new GeographicGridRegistrationSystem(this, new Vector3(10, 5, 20), new BoundingBox(-Vector3.One * 2f, Vector3.One * 2f)); ppManager = new PostProcessingManager(this); test = new TesterEffect(this); test.Enabled = false; ppManager.AddEffect(test); SSAO = new SSAOEffect(this, .1f, 1f, .5f, 1f); SSAO.Enabled = false; ppManager.AddEffect(SSAO); //stHPe = new STHardPointEffect(this, 25, 30, new Color(48, 89, 122)); stHPe = new STHardPointEffect(this, 25, 30, new Color(41, 77, 107), new Color(.125f, .125f, .125f, 1.0f)); stHPe.Enabled = false; ppManager.AddEffect(stHPe); sun = new SunEffect(this, SunPosition); sun.Enabled = false; ppManager.AddEffect(sun); water = new WaterEffect(this); water.waterHeight = -25f; water.Enabled = false; ppManager.AddEffect(water); dof = new DepthOfFieldEffect(this, 5, 30); dof.Enabled = false; ppManager.AddEffect(dof); bloom = new BloomEffect(this, 1.25f, 1f, 1f, 1f, .25f, 4f); bloom.Enabled = false; ppManager.AddEffect(bloom); haze = new HeatHazeEffect(this, "Textures/bumpmap", false); haze.Enabled = false; ppManager.AddEffect(haze); radialBlur = new RadialBlurEffect(this, 0.009f); radialBlur.Enabled = false; ppManager.AddEffect(radialBlur); ripple = new RippleEffect(this); ripple.Enabled = false; ppManager.AddEffect(ripple); fog = new FogEffect(this, 50, 100, Color.DarkSlateGray); fog.Enabled = false; ppManager.AddEffect(fog); godRays = new CrepuscularRays(this, SunPosition, "Textures/flare", 1500, 1f, .99f, 1f, .15f, .25f); //godRays = new CrepuscularRays(this, SunPosition, "Textures/flare", 1500, 1f, .99f, .1f, 0.12f, .25f); godRays.Enabled = false; ppManager.AddEffect(godRays); }
public void TestFog() { var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = 800, Height = 600, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1, OptionFlags = ResourceOptionFlags.GenerateMipMaps }; var hdrImage = new Texture2D(device, desc); var hdrImageRTV = new RenderTargetView(device, hdrImage); var hdrImageRV = new ShaderResourceView(device, hdrImage); var desc2 = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R8G8B8A8_UNorm, Width = 800, Height = 600, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1, OptionFlags = ResourceOptionFlags.GenerateMipMaps }; var toneMappedImage = new Texture2D(device, desc2); var toneMappedImageRTV = new RenderTargetView(device, toneMappedImage); var toneMappedImageRV = new ShaderResourceView(device, toneMappedImage); var foggedImage = new Texture2D(device, desc2); var foggedImageRTV = new RenderTargetView(device, foggedImage); var foggedImageRV = new ShaderResourceView(device, foggedImage); var calculater = new AverageLuminanceCalculater(game, hdrImageRV); var toneMap = new ToneMapRenderer(game); var combineFinal = new TestCombineFinalClass(game); var fogRenderer = new FogEffect(game); game.GameLoopEvent += delegate { combineFinal.DrawUpdatedDeferredRendering(); if (game.Keyboard.IsKeyDown(Key.I)) { return; } context.Rasterizer.SetViewports(new Viewport(0, 0, 800, 600)); context.OutputMerger.SetTargets(hdrImageRTV); combineFinal.DrawCombined(); calculater.DrawUpdatedLogLuminance(); calculater.DrawUpdatedAdaptedLogLuminance(); context.ClearState(); game.SetBackbuffer(); context.OutputMerger.SetTargets(toneMappedImageRTV); if (game.Keyboard.IsKeyDown(Key.K)) { game.TextureRenderer.Draw(calculater.AverageLuminanceRV, new Vector2(10, 10), new Vector2(300, 300)); game.TextureRenderer.Draw(hdrImageRV, new Vector2(320, 10), new Vector2(300, 300)); game.TextureRenderer.Draw(calculater.CurrAverageLumRV, new Vector2(10, 320), new Vector2(270, 270)); } else { toneMap.DrawTonemapped(hdrImageRV, calculater.CurrAverageLumRV); } context.ClearState(); game.SetBackbuffer(); fogRenderer.PostProcessFog(toneMappedImageRV, combineFinal.FilledGBuffer.GBuffer, foggedImageRTV); context.ClearState(); game.SetBackbuffer(); //context.ClearRenderTargetView(foggedImageRTV, new Color4(1, 1, 0)); game.TextureRenderer.Draw(foggedImageRV, new Vector2(0, 0), new Vector2(800, 600)); }; game.Run(); }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; IsMouseVisible = true; kbm = new KeyboardStateManager(this); camera = new Base3DCamera(this, .5f, 20000); camera.Position = new Vector3(0, 0, 0); Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); skyBox = new BaseSkyBox(this, "Textures/SkyBox/NebulaBlue"); Components.Add(skyBox); bunny = new Base3DObject(this, "Models/bunny", "Shaders/RenderObjectNotTangentsOrTexCoords"); bunny.Position = new Vector3(2, -1.5f, -20); bunny.LightPosition = LightPosition; Components.Add(bunny); cube = new Base3DObject(this, "Models/cube"); cube.Position = new Vector3(0, 0, -10); cube.ColorAsset = "Textures/h2mcpCube"; cube.BumpAsset = "Textures/h2mcpCubeNormal"; cube.LightPosition = LightPosition; Components.Add(cube); bunnies = new Base3DObject[10]; for (int s = 0; s < 10; s++) { bunnies[s] = new Base3DObject(this, "Models/Bunny"); bunnies[s].Position = new Vector3(20 + (s * 12), -1.5f, -10 - (s * 12)); bunnies[s].ColorAsset = "Textures/WindmillTopColor"; bunnies[s].BumpAsset = "Textures/WindmillTopNormal"; bunnies[s].LightPosition = LightPosition; Components.Add(bunnies[s]); } landShark = new Base3DObject(this, "Models/landShark"); landShark.Position = new Vector3(-20, 0, -10); landShark.ColorAsset = "Textures/Speeder_diff"; landShark.BumpAsset = "Textures/Speeder_bump"; landShark.LightPosition = LightPosition; Components.Add(landShark); earth = new Base3DObject(this, "Models/sphere"); earth.Position = new Vector3(0, 0, -200); earth.ColorAsset = "Textures/Earth_Diffuse"; earth.BumpAsset = "Textures/Earth_NormalMap"; earth.LightPosition = LightPosition; Components.Add(earth); ppManager = new PostProcessingManager(this); fog = new FogEffect(this, 50, 100, Color.DarkSlateGray); fog.Enabled = false; ppManager.AddEffect(fog); GodRays = new CrepuscularRays(this, LightPosition, "Textures/flare", 1500, .99f, .99f, .5f, .12f, .25f); GodRays.Enabled = false; ppManager.AddEffect(GodRays); sun = new SunEffect(this, LightPosition); sun.Enabled = false; ppManager.AddEffect(sun); bloom = new BloomEffect(this, 1.25f, 1f, 1f, 1f, .25f, 4f); bloom.Enabled = false; ppManager.AddEffect(bloom); dof = new DepthOfFieldEffect(this, 5, 30); dof.Enabled = false; ppManager.AddEffect(dof); haze = new HeatHazeEffect(this, "Textures/bumpmap", false); haze.Enabled = false; ppManager.AddEffect(haze); radialBlur = new RadialBlurEffect(this, 0.009f); radialBlur.Enabled = false; ppManager.AddEffect(radialBlur); ripple = new RippleEffect(this); ripple.Enabled = false; ppManager.AddEffect(ripple); sepia = new SepiaEffect(this); sepia.Enabled = false; ppManager.AddEffect(sepia); greyScale = new GreyScaleEffect(this); greyScale.Enabled = false; ppManager.AddEffect(greyScale); invert = new InvertColorEffect(this); invert.Enabled = false; ppManager.AddEffect(invert); colorFilter = new ColorFilterEffect(this, Color.White, .5f, .5f, .5f); colorFilter.Enabled = false; ppManager.AddEffect(colorFilter); bleach = new BleachEffect(this, 1); bleach.Enabled = false; ppManager.AddEffect(bleach); scanLines = new ScanLinesEffect(this, .001f, .001f, 128); scanLines.Enabled = false; ppManager.AddEffect(scanLines); deRezed = new DeRezedEffect(this, 128); deRezed.Enabled = false; ppManager.AddEffect(deRezed); }