public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("Screen space shadow is disabled."); } #region Prepare effects screenSpaceShadowEffect.ShadowSceneMapParameter.SetValue(shadowSceneMap); screenSpaceShadowEffect.ShadowColorParameter.SetValue(Scene.SceneSettings.DirectionalLight0.ShadowColor); #endregion #region Draw GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(screenSpaceShadowEffect, source, destination.Bounds); } destination.End(); #endregion }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("VolumeFog disabled"); } int w = destination.Width; int h = destination.Height; volumeFogBlendEffect.ViewportSize = new Vector2(w, h); volumeFogBlendEffect.SceneMap = source; volumeFogBlendEffect.FogMap = fogMapBackBuffer.GetRenderTarget(); destination.Begin(); { GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; GraphicsDevice.BlendState = BlendState.NonPremultiplied; foreach (var pass in volumeFogBlendEffect.CurrentTechnique.Passes) { pass.Apply(); quadVertexBuffer.Draw(); } GraphicsDevice.DepthStencilState = DepthStencilState.Default; } destination.End(); }
public override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); #region Effect の初期化 effectManager = new EffectManager(GraphicsDevice, Content); normalMapEffect = effectManager.Load<FluidSurfaceNormalMapEffect>(); normalMapEffect.SampleOffset = new Vector2(1.0f / (float) TextureSize, 1.0f / (float) TextureSize); #endregion #region 内部で使用する RenderTarget の初期化 backBufferManager = new BackBufferManager(GraphicsDevice); prevWaveMapBackBuffer = backBufferManager.Load("FluidSurfacePrevWaveMap"); prevWaveMapBackBuffer.Width = TextureSize; prevWaveMapBackBuffer.Height = TextureSize; prevWaveMapBackBuffer.MipMap = true; prevWaveMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2; prevWaveMapBackBuffer.DepthFormat = DepthFormat.None; prevWaveMapBackBuffer.MultiSampleCount = 0; prevWaveMapBackBuffer.Enabled = true; waveMapBackBuffer = backBufferManager.Load("FluidSurfaceWaveMap"); waveMapBackBuffer.Width = TextureSize; waveMapBackBuffer.Height = TextureSize; waveMapBackBuffer.MipMap = true; waveMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2; waveMapBackBuffer.DepthFormat = DepthFormat.None; waveMapBackBuffer.MultiSampleCount = 0; waveMapBackBuffer.Enabled = true; normalMapBackBuffer = backBufferManager.Load("FluidSurfaceNormalMap"); normalMapBackBuffer.Width = TextureSize; normalMapBackBuffer.Height = TextureSize; normalMapBackBuffer.MipMap = true; normalMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2; normalMapBackBuffer.DepthFormat = DepthFormat.None; normalMapBackBuffer.MultiSampleCount = 0; normalMapBackBuffer.Enabled = true; prevWaveMapBackBuffer.Begin(); { GraphicsDevice.Clear(Color.Black); } prevWaveMapBackBuffer.End(); #endregion base.LoadContent(); }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("ColorOverlap disabled."); } var color = new Color(Settings.Color) * Settings.Alpha; destination.Begin(); { SpriteBatch.Begin(); SpriteBatch.Draw(source, destination.Bounds, Color.White); SpriteBatch.Draw(whiteTexture, destination.Bounds, color); SpriteBatch.End(); } destination.End(); }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("Monochrome is disabled"); } monochromeEffect.CbParameter.SetValue(Settings.CbCr.X); monochromeEffect.CrParameter.SetValue(Settings.CbCr.Y); GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(monochromeEffect, source, destination.Bounds); } destination.End(); }
public BackBuffer Load(string name, BackBuffer cloneSource) { var backBuffer = new BackBuffer(graphicsDevice, name); if (cloneSource != null) { backBuffer.Width = cloneSource.Width; backBuffer.Height = cloneSource.Height; backBuffer.MipMap = cloneSource.MipMap; backBuffer.SurfaceFormat = cloneSource.SurfaceFormat; backBuffer.DepthFormat = cloneSource.DepthFormat; backBuffer.MultiSampleCount = backBuffer.MultiSampleCount; backBuffer.RenderTargetUsage = backBuffer.RenderTargetUsage; backBuffer.RenderTargetCount = backBuffer.RenderTargetCount; } backBuffers.Add(backBuffer); return backBuffer; }
public void Filter(Texture2D source, BackBuffer destination) { AssertEnabled(); #region Prepare effects ssaoEffect.SetSsaoMap(ssaoMapBackBuffer.GetRenderTarget()); #endregion #region Draw GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(ssaoEffect, source, destination.Bounds); } destination.End(); #endregion }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("Depth of field disabled"); } #region Prepare effects var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * Settings.MapScale); var height = (int) (pp.BackBufferHeight * Settings.MapScale); edgeDetectionEffect.SetEdgeWidth(Settings.EdgeWidth); edgeDetectionEffect.SetMapSize(width, height); edgeDetectionEffect.SetNormalDepthMap(normalDepthMapBackBuffer.GetRenderTarget()); edgeDetectionEffect.SetEdgeIntensity(Settings.EdgeIntensity); edgeDetectionEffect.SetNormalThreshold(Settings.NormalThreshold); edgeDetectionEffect.SetDepthThreshold(Settings.DepthThreshold); edgeDetectionEffect.SetNormalSensitivity(Settings.NormalSensitivity); edgeDetectionEffect.SetDepthSensitivity(Settings.DepthSensitivity); edgeDetectionEffect.SetEdgeColor(ref Settings.EdgeColor); #endregion #region Draw GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(edgeDetectionEffect, source, destination.Bounds); } destination.End(); #endregion }
protected override void LoadContent() { if (ContentLoaded) { return; } basicShadowMapEffect = EffectManager.Load<ShadowMapEffect>(); vsmShadowMapEffect = EffectManager.Load<ShadowMapEffect>(RenderConstants.VsmShadowMapEffectAssetName); vsmShadowMapBlur = new GaussianBlur(RenderContext, ShadowSettings.Size, ShadowSettings.Size, ShadowSettings.Format); vsmShadowMapBlur.LoadContent(); vsmSceneEffect = EffectManager.Load<VsmSceneEffect>(); pcfSceneEffect = EffectManager.Load<PcfSceneEffect>(); classicShadowSceneEffect = EffectManager.Load<ClassicShadowSceneEffect>(); shadowMapBackBuffer = BackBufferManager.Load("ShadowMap"); shadowMapBackBuffer.Width = ShadowSettings.Size; shadowMapBackBuffer.Height = ShadowSettings.Size; shadowMapBackBuffer.MipMap = false; shadowMapBackBuffer.SurfaceFormat = ShadowSettings.Format; shadowMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; shadowMapBackBuffer.MultiSampleCount = 0; shadowMapBackBuffer.Enabled = false; base.LoadContent(); }
protected override void LoadContent() { var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * Settings.MapScale); var height = (int) (pp.BackBufferHeight * Settings.MapScale); #region Effects normalDepthMapEffect = EffectManager.Load<NormalDepthMapEffect>(); edgeDetectionEffect = EffectManager.Load<EdgeDetectionEffect>(); edgeDetectionEffect.SetEdgeWidth(Settings.EdgeWidth); edgeDetectionEffect.SetMapSize(width, height); #endregion #region Back buffers normalDepthMapBackBuffer = BackBufferManager.Load("NormalDepthMap"); normalDepthMapBackBuffer.Width = width; normalDepthMapBackBuffer.Height = height; normalDepthMapBackBuffer.MipMap = false; normalDepthMapBackBuffer.SurfaceFormat = normalDepthMapFormat; normalDepthMapBackBuffer.MultiSampleCount = 0; normalDepthMapBackBuffer.Enabled = Enabled; #endregion base.LoadContent(); }
protected override void LoadContent() { #region Effects depthMapEffect = EffectManager.Load<DepthMapEffect>(); depthOfFieldEffect = EffectManager.Load<DofEffect>(); #endregion #region Back buffers const int depthMapSampleQuality = 0; var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * Settings.MapScale); var height = (int) (pp.BackBufferHeight * Settings.MapScale); depthMapBackBuffer = BackBufferManager.Load("DepthMap"); depthMapBackBuffer.Width = width; depthMapBackBuffer.Height = height; depthMapBackBuffer.MipMap = false; depthMapBackBuffer.SurfaceFormat = depthMapFormat; depthMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; depthMapBackBuffer.MultiSampleCount = depthMapSampleQuality; depthMapBackBuffer.Enabled = Enabled; bluredSceneMapBackBuffer = BackBufferManager.Load("BluredSceneMap"); bluredSceneMapBackBuffer.Width = width; bluredSceneMapBackBuffer.Height = height; bluredSceneMapBackBuffer.MipMap = false; bluredSceneMapBackBuffer.SurfaceFormat = SurfaceFormat.Color; bluredSceneMapBackBuffer.MultiSampleCount = 0; bluredSceneMapBackBuffer.Enabled = Enabled; #endregion #region Gaussian blur gaussianBlur = new GaussianBlur(RenderContext, width, height, bluredSceneMapBackBuffer.SurfaceFormat); gaussianBlur.LoadContent(); gaussianBlur.Enabled = Enabled; #endregion base.LoadContent(); }
public void Filter(Texture2D source, BackBuffer destination) { if (!enabled) throw new InvalidOperationException("Gaussian blur filter is disabled."); if (!contentLoaded) throw new InvalidOperationException("Content is not loaded."); AdjustContent(destination.Width, destination.Height, destination.SurfaceFormat); FilterByHorizontalBlur(source); FilterByVirticalBlur(backBuffer.GetRenderTarget(), destination); }
protected override void LoadContent() { #region Effects normalDepthMapEffect = EffectManager.Load<NormalDepthMapEffect>(); ssaoMapEffect = EffectManager.Load<SsaoMapEffect>(); ssaoMapBlurEffect = EffectManager.Load<SsaoMapBlurEffect>(); ssaoEffect = EffectManager.Load<SsaoEffect>(); var randomNormalMap = Content.Load<Texture2D>("Textures/RandomNormal"); ssaoMapEffect.SetRandomNormalMap(randomNormalMap); #endregion #region Back buffers const int normalDepthMapSampleQuality = 0; var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * Settings.MapScale); var height = (int) (pp.BackBufferHeight * Settings.MapScale); normalDepthMapBackBuffer = BackBufferManager.Load("NormalDepthmap"); normalDepthMapBackBuffer.Width = width; normalDepthMapBackBuffer.Height = height; normalDepthMapBackBuffer.MipMap = false; normalDepthMapBackBuffer.SurfaceFormat = normalDepthMapFormat; normalDepthMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; normalDepthMapBackBuffer.MultiSampleCount = normalDepthMapSampleQuality; normalDepthMapBackBuffer.Enabled = Enabled; ssaoMapBackBuffer = BackBufferManager.Load("SsaoMap"); ssaoMapBackBuffer.Width = width; ssaoMapBackBuffer.Height = height; ssaoMapBackBuffer.MipMap = false; ssaoMapBackBuffer.SurfaceFormat = SurfaceFormat.Color; ssaoMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; ssaoMapBackBuffer.MultiSampleCount = 0; ssaoMapBackBuffer.Enabled = Enabled; ssaoMapBlurBackBuffer = BackBufferManager.Load("SsaoGaussianBlur"); ssaoMapBlurBackBuffer.Width = width; ssaoMapBlurBackBuffer.Height = height; ssaoMapBlurBackBuffer.MipMap = false; ssaoMapBlurBackBuffer.SurfaceFormat = SurfaceFormat.Color; ssaoMapBlurBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; ssaoMapBlurBackBuffer.MultiSampleCount = 0; ssaoMapBlurBackBuffer.Enabled = Enabled; #endregion base.LoadContent(); }
protected override void LoadContent() { #region Effects occlusionMapEffect = EffectManager.Load<GodRayOcclusionMapEffect>(); godRayEffect = EffectManager.Load<GodRayEffect>(); #endregion #region Back buffers var pp = GraphicsDevice.PresentationParameters; occlusionMapBackBuffer = BackBufferManager.Load("GodyRayOcclusionMap"); occlusionMapBackBuffer.Width = (int) (pp.BackBufferWidth * Settings.MapScale); occlusionMapBackBuffer.Height = (int) (pp.BackBufferHeight * Settings.MapScale); occlusionMapBackBuffer.MipMap = true; occlusionMapBackBuffer.SurfaceFormat = SurfaceFormat.Color; occlusionMapBackBuffer.MultiSampleCount = 0; occlusionMapBackBuffer.Enabled = Enabled; #endregion base.LoadContent(); }
protected override void LoadContent() { #region Effects bloomExtractEffect = EffectManager.Load<BloomExtractEffect>(); bloomEffect = EffectManager.Load<BloomEffect>(); #endregion #region Back buffers var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * Settings.MapScale); var height = (int) (pp.BackBufferHeight * Settings.MapScale); bloomExtractMapBackBuffer = BackBufferManager.Load("BloomExtractMap"); bloomExtractMapBackBuffer.Width = width; bloomExtractMapBackBuffer.Height = height; bloomExtractMapBackBuffer.MipMap = false; bloomExtractMapBackBuffer.SurfaceFormat = pp.BackBufferFormat; bloomExtractMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; bloomExtractMapBackBuffer.MultiSampleCount = 0; bloomExtractMapBackBuffer.Enabled = Enabled; #endregion #region Gaussian blur gaussianBlur = new GaussianBlur(RenderContext, width, height, bloomExtractMapBackBuffer.SurfaceFormat); gaussianBlur.LoadContent(); gaussianBlur.Enabled = Enabled; #endregion base.LoadContent(); }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) throw new InvalidOperationException("Bloom disabled."); #region Create bloom extract map #region Prepare effects bloomExtractEffect.SetThreshold(Settings.Threshold); #endregion #region Prepare back buffers var pp = GraphicsDevice.PresentationParameters; bloomExtractMapBackBuffer.Width = (int) (pp.BackBufferWidth * Settings.MapScale); bloomExtractMapBackBuffer.Height = (int) (pp.BackBufferHeight * Settings.MapScale); #endregion #region Draw GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; bloomExtractMapBackBuffer.Begin(); { SpriteBatch.Render(bloomExtractEffect, source, bloomExtractMapBackBuffer.Bounds); } bloomExtractMapBackBuffer.End(); #endregion #endregion #region Blur gaussianBlur.Radius = Settings.BlurRadius; gaussianBlur.Amount = Settings.BlurAmount; gaussianBlur.Filter( bloomExtractMapBackBuffer.GetRenderTarget(), bloomExtractMapBackBuffer); #endregion #region Notify intermediate maps if (DebugMap.Instance != null) { DebugMap.Instance.Maps.Add(bloomExtractMapBackBuffer.GetRenderTarget()); } #endregion #region Apply bloom to the destination bloomEffect.BloomExtractMapParameter.SetValue(bloomExtractMapBackBuffer.GetRenderTarget()); bloomEffect.SetBloomIntensity(Settings.BloomIntensity); bloomEffect.SetBaseIntensity(Settings.BaseIntensity); bloomEffect.SetBloomSaturation(Settings.BloomSaturation); bloomEffect.SetBaseSaturation(Settings.BaseSaturation); GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(bloomEffect, source, destination.Bounds); } destination.End(); #endregion }
public void LoadContent() { if (contentLoaded) return; effectManager = new EffectManager(renderContext.GraphicsDevice, renderContext.Content); effect = effectManager.Load<GaussianBlurEffect>(); effect.Configure(widthHint, heightHint, radius, amount); backBufferManager = new BackBufferManager(renderContext.GraphicsDevice); backBuffer = backBufferManager.Load("GaussianBlur"); backBuffer.MipMap = false; backBuffer.MultiSampleCount = 0; backBuffer.DepthFormat = DepthFormat.None; AdjustContent(widthHint, heightHint, formatHint); contentLoaded = true; }
public void Filter(Texture2D source, BackBuffer destination) { if (!Enabled) { throw new InvalidOperationException("Depth of field disabled"); } #region Adjust back buffer size if the destination is resized var pp = GraphicsDevice.PresentationParameters; bluredSceneMapBackBuffer.Width = (int) (pp.BackBufferWidth * Settings.MapScale); bluredSceneMapBackBuffer.Height = (int) (pp.BackBufferHeight * Settings.MapScale); #endregion #region Blur gaussianBlur.Radius = Settings.BlurRadius; gaussianBlur.Amount = Settings.BlurAmount; gaussianBlur.Filter(source, bluredSceneMapBackBuffer); #endregion #region Notify the intermadiate map if (DebugMap.Instance != null) { DebugMap.Instance.Maps.Add(bluredSceneMapBackBuffer.GetRenderTarget()); } #endregion #region Apply DoF to the destination var pov = Scene.ActiveCamera.Pov; depthOfFieldEffect.NearPlaneDistance = pov.NearPlaneDistance; depthOfFieldEffect.FarPlaneDistance = pov.FarPlaneDistance / (pov.FarPlaneDistance - pov.NearPlaneDistance); if (Settings.FocusOverrideEnabled) { depthOfFieldEffect.FocusRange = Settings.FocusRange; depthOfFieldEffect.FocusDistance = Settings.FocusDistance; } else { depthOfFieldEffect.FocusRange = pov.FocusRange; depthOfFieldEffect.FocusDistance = pov.FocusDistance; } depthOfFieldEffect.DepthMap = depthMapBackBuffer.GetRenderTarget(); depthOfFieldEffect.BluredSceneMap = bluredSceneMapBackBuffer.GetRenderTarget(); GraphicsDevice.DepthStencilState = DepthStencilState.None; GraphicsDevice.BlendState = BlendState.Opaque; destination.Begin(); { SpriteBatch.Render(depthOfFieldEffect, source, destination.Bounds); } destination.End(); #endregion }
void FilterByVirticalBlur(Texture2D source, BackBuffer destination) { renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.None; effect.CurrentTechnique = effect.VerticalBlurTechnique; destination.Begin(); { renderContext.SpriteBatch.Render( effect, backBuffer.GetRenderTarget(), new Rectangle(0, 0, destination.Width, destination.Height)); } destination.End(); }
protected override void LoadContent() { #region Effects screenSpaceShadowEffect = EffectManager.Load<ScreenSpaceShadowEffect>(); #endregion #region Back buffers var pp = GraphicsDevice.PresentationParameters; var mapScale = ShadowSettings.ScreenSpaceShadow.MapScale; var width = (int) (pp.BackBufferWidth * mapScale); var height = (int) (pp.BackBufferHeight * mapScale); var format = SurfaceFormat.Color; shadowSceneMapBackBuffer = BackBufferManager.Load("ShadowSceneMap"); shadowSceneMapBackBuffer.Width = width; shadowSceneMapBackBuffer.Height = height; shadowSceneMapBackBuffer.MipMap = false; shadowSceneMapBackBuffer.SurfaceFormat = format; shadowSceneMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; shadowSceneMapBackBuffer.MultiSampleCount = 0; shadowSceneMapBackBuffer.Enabled = false; #endregion #region Blur screenSpaceBlur = new GaussianBlur(RenderContext, width, height, format); screenSpaceBlur.LoadContent(); #endregion base.LoadContent(); }
protected override void LoadContent() { if (ContentLoaded) { return; } #region Effects volumeFogSceneDepthMapEffect = EffectManager.Load<VolumeFogSceneDepthMapEffect>(); volumeFogDepthMapEffect = EffectManager.Load<VolumeFogDepthMapEffect>(); volumeFogMapEffect = EffectManager.Load<VolumeFogMapEffect>(); volumeFogBlendEffect = EffectManager.Load<VolumeFogBlendEffect>(); #endregion #region Back buffers var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * MapScale); var height = (int) (pp.BackBufferHeight * MapScale); sceneDepthMapBackBuffer = BackBufferManager.Load( "VolumeFog.SceneDepthMap"); sceneDepthMapBackBuffer.Width = width; sceneDepthMapBackBuffer.Height = height; sceneDepthMapBackBuffer.MipMap = true; sceneDepthMapBackBuffer.SurfaceFormat = SurfaceFormat.Single; sceneDepthMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; sceneDepthMapBackBuffer.MultiSampleCount = pp.MultiSampleCount; sceneDepthMapBackBuffer.RenderTargetUsage = pp.RenderTargetUsage; fogDepthCWMapBackBuffer = BackBufferManager.Load( "VolumeFog.FogDepthCWMap"); fogDepthCWMapBackBuffer.Width = width; fogDepthCWMapBackBuffer.Height = height; fogDepthCWMapBackBuffer.MipMap = true; fogDepthCWMapBackBuffer.SurfaceFormat = SurfaceFormat.Single; fogDepthCWMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; fogDepthCWMapBackBuffer.MultiSampleCount = pp.MultiSampleCount; fogDepthCWMapBackBuffer.RenderTargetUsage = pp.RenderTargetUsage; fogDepthCCWMapBackBuffer = BackBufferManager.Load( "VolumeFog.FogDepthCCWMap", fogDepthCWMapBackBuffer); fogMapBackBuffer = BackBufferManager.Load( "VolumeFog.FogMap"); fogMapBackBuffer.Width = width; fogMapBackBuffer.Height = height; fogMapBackBuffer.MipMap = true; fogMapBackBuffer.SurfaceFormat = SurfaceFormat.Color; fogMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8; fogMapBackBuffer.MultiSampleCount = pp.MultiSampleCount; fogMapBackBuffer.RenderTargetUsage = pp.RenderTargetUsage; // // TODO // sceneDepthMapBackBuffer.Enabled = false; fogDepthCWMapBackBuffer.Enabled = false; fogDepthCCWMapBackBuffer.Enabled = false; fogMapBackBuffer.Enabled = false; #endregion quadVertexBuffer = new QuadVertexBuffer(GraphicsDevice); base.LoadContent(); }