/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.HDR: { MyMinerGame.SetRenderTarget(availableRenderTarget, null); MyEffectContrast effectContrast = MyRender.GetEffect(MyEffects.Contrast) as MyEffectContrast; effectContrast.SetDiffuseTexture(source); effectContrast.SetHalfPixel(MyUtils.GetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height)); effectContrast.SetContrast(Contrast); effectContrast.SetHue(Hue); effectContrast.SetSaturation(Saturation); MyGuiManager.GetFullscreenQuad().Draw(effectContrast); return availableRenderTarget; } break; } return source; }
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); RasterizerState.CullCounterClockwise.Apply(); MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectChromaticAberration effectChromaAberr = MyRender.GetEffect(MyEffects.ChromaticAberration) as MyEffectChromaticAberration; effectChromaAberr.SetInputTexture(source); effectChromaAberr.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); effectChromaAberr.SetAspectRatio((float)source.GetLevelDescription(0).Width / (float)source.GetLevelDescription(0).Height); effectChromaAberr.SetDistortionLens(DistortionLens); effectChromaAberr.SetDistortionCubic(DistortionCubic); effectChromaAberr.SetDistortionWeights(ref DistortionWeights); effectChromaAberr.Enable(); MyRender.GetFullscreenQuad().Draw(effectChromaAberr); return(availableRenderTarget); } } return(source); }
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { //BlendState.Opaque.Apply(); //DepthStencilState.None.Apply(); //RasterizerState.CullCounterClockwise.Apply(); //MyRender.SetRenderTarget(availableRenderTarget, null); //MyEffectVignetting effectVignetting = MyRender.GetEffect(MyEffects.Vignetting) as MyEffectVignetting; //effectVignetting.SetInputTexture(source); //effectVignetting.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); //effectVignetting.SetVignettingPower(VignettingPower); //effectVignetting.EnableVignetting(); //MyRender.GetFullscreenQuad().Draw(effectVignetting); return(availableRenderTarget); } } return(source); }
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { //BlendState.Opaque.Apply(); //DepthStencilState.None.Apply(); //RasterizerState.CullCounterClockwise.Apply(); //MyRender.SetRenderTarget(availableRenderTarget, null); //MyEffectVignetting effectVignetting = MyRender.GetEffect(MyEffects.Vignetting) as MyEffectVignetting; //effectVignetting.SetInputTexture(source); //effectVignetting.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); //effectVignetting.SetVignettingPower(VignettingPower); //effectVignetting.EnableVignetting(); //MyRender.GetFullscreenQuad().Draw(effectVignetting); return availableRenderTarget; } } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); RasterizerState.CullCounterClockwise.Apply(); MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectAntiAlias effectAntiAlias = MyRender.GetEffect(MyEffects.AntiAlias) as MyEffectAntiAlias; effectAntiAlias.SetDiffuseTexture(source); effectAntiAlias.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); if (MyRenderConstants.RenderQualityProfile.EnableFXAA) { effectAntiAlias.ApplyFxaa(); } else { return(source); // Nothing to do, return source } MyRender.GetFullscreenQuad().Draw(effectAntiAlias); return(availableRenderTarget); } break; } return(source); }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); RasterizerState.CullCounterClockwise.Apply(); MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectAntiAlias effectAntiAlias = MyRender.GetEffect(MyEffects.AntiAlias) as MyEffectAntiAlias; effectAntiAlias.SetDiffuseTexture(source); effectAntiAlias.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); if (MyRenderConstants.RenderQualityProfile.EnableFXAA) effectAntiAlias.ApplyFxaa(); else return source; // Nothing to do, return source MyRender.GetFullscreenQuad().Draw(effectAntiAlias); return availableRenderTarget; } break; } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.HDR: { MyMinerGame.SetRenderTarget(availableRenderTarget, null); MyEffectContrast effectContrast = MyRender.GetEffect(MyEffects.Contrast) as MyEffectContrast; effectContrast.SetDiffuseTexture(source); effectContrast.SetHalfPixel(MyUtils.GetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height)); effectContrast.SetContrast(Contrast); effectContrast.SetHue(Hue); effectContrast.SetSaturation(Saturation); MyGuiManager.GetFullscreenQuad().Draw(effectContrast); return(availableRenderTarget); } break; } return(source); }
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); RasterizerState.CullCounterClockwise.Apply(); MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectChromaticAberration effectChromaAberr = MyRender.GetEffect(MyEffects.ChromaticAberration) as MyEffectChromaticAberration; effectChromaAberr.SetInputTexture(source); effectChromaAberr.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); effectChromaAberr.SetAspectRatio((float)source.GetLevelDescription(0).Width / (float)source.GetLevelDescription(0).Height); effectChromaAberr.SetDistortionLens(DistortionLens); effectChromaAberr.SetDistortionCubic(DistortionCubic); effectChromaAberr.SetDistortionWeights(ref DistortionWeights); effectChromaAberr.Enable(); MyRender.GetFullscreenQuad().Draw(effectChromaAberr); return availableRenderTarget; } } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.PostLighting: { if (MySector.FogProperties.FogMultiplier <= 0.0f) { return(source); } //MyMinerGame.Static.GraphicsDevice.SetRenderTarget(availableRenderTarget); //MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.NonPremultiplied; MyStateObjects.VolumetricFogBlend.Apply(); // MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog; int width = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width; int height = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height; volumetricFog.SetSourceRT(source); volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricFog.SetHalfPixel(width, height); volumetricFog.SetViewProjectionMatrix(MyCamera.ViewProjectionMatrix); volumetricFog.SetCameraPosition(MyCamera.Position); volumetricFog.SetCameraMatrix(Matrix.Invert(MyCamera.ViewMatrix)); volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); MyCamera.SetupBaseEffect(volumetricFog); //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position)); if (MyFakes.MWBUILDER) { volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground); } else { volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default); } MyGuiManager.GetFullscreenQuad().Draw(volumetricFog); // MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; // MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.AlphaBlend; } break; } return(source); }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.PostLighting: { if (MySector.FogProperties.FogMultiplier <= 0.0f) return source; //MyMinerGame.Static.GraphicsDevice.SetRenderTarget(availableRenderTarget); //MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.NonPremultiplied; MyStateObjects.VolumetricFogBlend.Apply(); // MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog; int width = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width; int height = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height; volumetricFog.SetSourceRT(source); volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricFog.SetHalfPixel(width, height); volumetricFog.SetViewProjectionMatrix(MyCamera.ViewProjectionMatrix); volumetricFog.SetCameraPosition(MyCamera.Position); volumetricFog.SetCameraMatrix(Matrix.Invert(MyCamera.ViewMatrix)); volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); MyCamera.SetupBaseEffect(volumetricFog); //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position)); if (MyFakes.MWBUILDER) volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground); else volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default); MyGuiManager.GetFullscreenQuad().Draw(volumetricFog); // MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; // MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.AlphaBlend; } break; } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.PostLighting: { //todo fog //if (MySector.FogProperties.FogMultiplier <= 0.0f) // return source; MyStateObjects.VolumetricFogBlend.Apply(); MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog; int width = MyRenderCamera.Viewport.Width; int height = MyRenderCamera.Viewport.Height; var scale = MyRender.GetScaleForViewport(source); volumetricFog.SetSourceRT(source); volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricFog.SetHalfPixel(width, height); volumetricFog.SetViewProjectionMatrix((Matrix)MyRenderCamera.ViewProjectionMatrix); volumetricFog.SetCameraPosition((Vector3)MyRenderCamera.Position); volumetricFog.SetCameraMatrix((Matrix)MatrixD.Invert(MyRenderCamera.ViewMatrix)); volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); volumetricFog.SetScale(scale); MyRenderCamera.SetupBaseEffect(volumetricFog, MyLodTypeEnum.LOD0); //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position)); //todo //if (MyFakes.MWBUILDER) // volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground); //else volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default); MyRender.GetFullscreenQuad().Draw(volumetricFog); } break; } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.PostLighting: { //todo fog //if (MySector.FogProperties.FogMultiplier <= 0.0f) // return source; MyStateObjects.VolumetricFogBlend.Apply(); MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog; int width = MyRenderCamera.Viewport.Width; int height = MyRenderCamera.Viewport.Height; var scale = MyRender.GetScaleForViewport(source); volumetricFog.SetSourceRT(source); volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricFog.SetHalfPixel(width, height); volumetricFog.SetViewProjectionMatrix((Matrix)MyRenderCamera.ViewProjectionMatrix); volumetricFog.SetCameraPosition((Vector3)MyRenderCamera.Position); volumetricFog.SetCameraMatrix((Matrix)MatrixD.Invert(MyRenderCamera.ViewMatrix)); volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); volumetricFog.SetScale(scale); MyRenderCamera.SetupBaseEffect(volumetricFog, MyLodTypeEnum.LOD0); //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position)); //todo //if (MyFakes.MWBUILDER) // volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground); //else volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default); MyRender.GetFullscreenQuad().Draw(volumetricFog); } break; } return(source); }
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); RasterizerState.CullCounterClockwise.Apply(); MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectColorMapping effect = MyRender.GetEffect(MyEffects.ColorMapping) as MyEffectColorMapping; effect.SetInputTexture(source); effect.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height); effect.Enable(); MyRender.GetFullscreenQuad().Draw(effect); return(availableRenderTarget); } } return(source); }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { var halfRT = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0); MyRender.SetRenderTarget(halfRT, null); BlendState.Opaque.Apply(); RasterizerState.CullNone.Apply(); DepthStencilState.None.Apply(); MyEffectGodRays effectGodRays = MyRender.GetEffect(MyEffects.GodRays) as MyEffectGodRays; effectGodRays.SetDiffuseTexture(source); effectGodRays.SetDepthTexture(MyRender.GetRenderTarget(MyRenderTargets.Depth)); effectGodRays.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); effectGodRays.SetView((Matrix)MyRenderCamera.ViewMatrix); effectGodRays.SetWorldViewProjection((Matrix)MyRenderCamera.ViewProjectionMatrix); effectGodRays.SetDensity(Density); effectGodRays.SetDecay(Decay); effectGodRays.SetWeight(Weight * (1 - MyRender.FogProperties.FogMultiplier)); effectGodRays.SetExposition(Exposition); effectGodRays.SetLightPosition(15000f * -MyRender.Sun.Direction); effectGodRays.SetLightDirection(MyRender.Sun.Direction); effectGodRays.SetCameraPos((Vector3)MyRenderCamera.Position); MyRender.GetFullscreenQuad().Draw(effectGodRays); if (ApplyBlur) { var auxTarget = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102); var blurEffect = MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur; blurEffect.SetHalfPixel(halfRT.GetLevelDescription(0).Width, halfRT.GetLevelDescription(0).Height); // Apply vertical gaussian blur MyRender.SetRenderTarget(auxTarget, null); blurEffect.BlurAmount = 1; blurEffect.SetSourceTexture(halfRT); blurEffect.SetHeightForVerticalPass(halfRT.GetLevelDescription(0).Height); MyRender.GetFullscreenQuad().Draw(blurEffect); // Apply horizontal gaussian blur MyRender.SetRenderTarget(halfRT, null); blurEffect.BlurAmount = 1; blurEffect.SetSourceTexture(auxTarget); blurEffect.SetWidthForHorisontalPass(auxTarget.GetLevelDescription(0).Width); MyRender.GetFullscreenQuad().Draw(blurEffect); } // Additive MyRender.SetRenderTarget(availableRenderTarget, null); //MySandboxGame.Static.GraphicsDevice.Clear(ClearFlags.All, new SharpDX.ColorBGRA(0), 1, 0); BlendState.Opaque.Apply(); MyRender.Blit(source, true); var upscaleEffect = MyRender.GetEffect(MyEffects.Scale) as MyEffectScale; upscaleEffect.SetScale(new Vector2(2)); upscaleEffect.SetTechnique(MyEffectScale.Technique.HWScale); MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply(); upscaleEffect.SetSourceTextureMod(halfRT); MyRender.GetFullscreenQuad().Draw(upscaleEffect); return(availableRenderTarget); } } return(source); }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.LODBlend: { MyEffectVolumetricSSAO2 volumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2; int width = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width; int height = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height; int halfWidth = width / 2; int halfHeight = height / 2; //Render SSAO MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAO), null); MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0), 1, 0); DepthStencilState.None.Apply(); BlendState.Opaque.Apply(); Vector4 ssaoParams = new Vector4(MinRadius, MaxRadius, RadiusGrowZScale, CameraZFar); Vector4 ssaoParams2 = new Vector4(Bias, Falloff, NormValue, 0); volumetricSsao.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricSsao.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricSsao.SetHalfPixel(width, height); volumetricSsao.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); volumetricSsao.SetViewMatrix(MyCamera.ViewMatrixAtZero); volumetricSsao.SetParams1(ssaoParams); volumetricSsao.SetParams2(ssaoParams2); volumetricSsao.SetProjectionMatrix(MyCamera.ProjectionMatrix); volumetricSsao.SetContrast(Contrast); MyGuiManager.GetFullscreenQuad().Draw(volumetricSsao); if (volumetricSsao.UseBlur) { //SSAO Blur MyMinerGame.SetRenderTarget(availableRenderTarget, null); MyEffectSSAOBlur2 effectSsaoBlur = MyRender.GetEffect(MyEffects.SSAOBlur) as MyEffectSSAOBlur2; effectSsaoBlur.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); //effectSsaoBlur.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals)); effectSsaoBlur.SetHalfPixel(width, height); effectSsaoBlur.SetSSAOHalfPixel(halfWidth, halfHeight); effectSsaoBlur.SetSsaoRT(MyRender.GetRenderTarget(MyRenderTargets.SSAO)); effectSsaoBlur.SetBlurDirection(new Vector2(0, 1f / (float)halfHeight)); //effectSsaoBlur.SetBlurDirection(new Vector2(1 / (float)halfWidth, 1f / (float)halfHeight)); MyGuiManager.GetFullscreenQuad().Draw(effectSsaoBlur); MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), null); effectSsaoBlur.SetSsaoRT(availableRenderTarget); effectSsaoBlur.SetBlurDirection(new Vector2(1f / (float)halfWidth, 0)); MyGuiManager.GetFullscreenQuad().Draw(effectSsaoBlur); } //Bake it into diffuse /* * MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot; * MyMinerGame.SetRenderTarget(availableRenderTarget, null); * ssEffect.SetSourceTexture(MyRender.GetRenderTarget(MyRenderTargets.Diffuse)); * ssEffect.SetScale(Vector2.One); * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); * * MyGuiManager.GetFullscreenQuad().Draw(ssEffect); * */ MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.Diffuse), null); /* * ssEffect.SetSourceTexture(availableRenderTarget); * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); * ssEffect.SetScale(Vector2.One); * MyGuiManager.GetFullscreenQuad().Draw(ssEffect); */ MyEffectVolumetricSSAO2 effectVolumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2; //Blend with SSAO together DepthStencilState.None.Apply(); if (!effectVolumetricSsao.ShowOnlySSAO) { MyStateObjects.SSAO_BlendState.Apply(); } else { MyRender.CurrentRenderSetup.EnableLights = false; MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(1.0f), 1, 0); MyStateObjects.SSAO_BlendState.Apply(); } if (effectVolumetricSsao.UseBlur) { MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), 0, 0, MyCamera.Viewport.Width, MyCamera.Viewport.Height, Color.White); } else { MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.SSAO), 0, 0, MyCamera.Viewport.Width, MyCamera.Viewport.Height, Color.White); } } break; } return(source); }
private void PostProcessPass(ITexture colorTexture, ITexture depthTexture, ref Point actualScreenRezolution) { PostProcessStage.ExecutePostProcessPass(colorTexture, depthTexture, ref actualScreenRezolution); }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param> /// <param name="source">Render target where is current scene.</param> /// <param name="availableRenderTarget">Render target for use in shader, can be used as output or not.</param> /// <returns>Returns render target with output, must be source or availableRenderTarget</returns> public abstract Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget);
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param> /// <param name="source">Render target where is current scene.</param> /// <param name="availableRenderTarget">Render target for use in shader, can be used as output or not.</param> /// <returns>Returns render target with output, must be source or availableRenderTarget</returns> public abstract Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget);
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.LODBlend: { //if (RenderHDRThisFrame()) //{ // (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).CopyEmissivityTechnique = MyEffectBlendLights.Technique.CopyEmissivityHDR; // (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).DefaultTechnique = MyEffectBlendLights.Technique.HDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultTechnique = MyEffectDirectionalLight.Technique.DefaultHDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultWithoutShadowsTechnique = MyEffectDirectionalLight.Technique.WithoutShadowsHDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultNoLightingTechnique = MyEffectDirectionalLight.Technique.NoLightingHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultReflectorTechnique = MyEffectPointLight.MyEffectPointLightTechnique.ReflectorHDR; // unused, dont have instancing // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotShadowTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotShadowsHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.PointHDR_Instanced; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.HemisphereHDR_Instanced; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR_Instanced; //} break; } case PostProcessStage.HDR: { // if HDR is disabled or some debug rendering display // is enabled then skip HDR post process if (!RenderHDRThisFrame()) return source; BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); // RasterizerState.CullNone.Apply(MyMinerGameDX.Static.GraphicsDevice); m_thresholdTargets[0] = MyRender.GetRenderTarget(MyRenderTargets.Normals); m_thresholdTargets[1] = availableRenderTarget; // 1. threshold GenerateThreshold( source, MyRender.GetRenderTarget(MyRenderTargets.Diffuse), m_thresholdTargets, MyRender.GetEffect(MyEffects.Threshold) as MyEffectThreshold, Threshold, BloomIntensity, BloomIntensityBackground, Exposure); /* MyMinerGame.SetRenderTarget(null, null, SetDepthTargetEnum.RestoreDefault); MyMinerGame.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault); MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot; ssEffect.SetSourceTexture(m_thresholdTargets[0]); ssEffect.SetScale(MinerWarsMath.Vector2.One); ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); MyGuiManager.GetFullscreenQuad().Draw(ssEffect); return availableRenderTarget; */ // 2. downscale HDR1 -> Downscaled8 // !! IMPORTANT !! you cannot just switch the function call if you want different downscale // Also changing the RTs is necessary (they have fixed dimensions). GenerateDownscale4( MyRender.GetRenderTarget(MyRenderTargets.Normals), MyRender.GetRenderTarget(MyRenderTargets.Depth), MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetEffect(MyEffects.Scale) as MyEffectScale); /* // 3?. avg luminance float dt = (MyMinerGame.TotalGamePlayTimeInMilliseconds - lastTime) / 1000.0f; lastTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; CalculateAverageLuminance( MyRender.GetRenderTarget(MyRenderTargets.Downscaled8), MyRender.GetRenderTarget(MyRenderTargets.Downscaled8Threshold), MyRender.GetEffect(MyEffects.Luminance) as MyEffectLuminance, MyRender.GetEffect(MyEffects.Scale) as MyEffectScale, dt, 0.5f); */ // 4. blur Blur(MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetRenderTarget(MyRenderTargets.HDR4), MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur, VerticalBlurAmount, HorizontalBlurAmount); // 5. scale blurred to halfsize Upscale4To2( MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102), MyRender.GetEffect(MyEffects.Scale) as MyEffectScale); MyMinerGame.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault); // 6. tonemap + apply bloom HDR( source, MyRender.GetRenderTarget(MyRenderTargets.Diffuse), MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102), MyRender.GetEffect(MyEffects.HDR) as MyEffectHDR, 0.6f, Exposure); return availableRenderTarget; //RenderTarget2D temp = currentFrameAdaptedLuminance; //currentFrameAdaptedLuminance = lastFrameAdaptedLuminance; //lastFrameAdaptedLuminance = temp; } } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.LODBlend: { //if (RenderHDRThisFrame()) //{ // (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).CopyEmissivityTechnique = MyEffectBlendLights.Technique.CopyEmissivityHDR; // (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).DefaultTechnique = MyEffectBlendLights.Technique.HDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultTechnique = MyEffectDirectionalLight.Technique.DefaultHDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultWithoutShadowsTechnique = MyEffectDirectionalLight.Technique.WithoutShadowsHDR; // (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultNoLightingTechnique = MyEffectDirectionalLight.Technique.NoLightingHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultReflectorTechnique = MyEffectPointLight.MyEffectPointLightTechnique.ReflectorHDR; // unused, dont have instancing // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotShadowTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotShadowsHDR; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.PointHDR_Instanced; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.HemisphereHDR_Instanced; // (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR_Instanced; //} break; } case PostProcessStage.HDR: { // if HDR is disabled or some debug rendering display // is enabled then skip HDR post process if (!RenderHDRThisFrame()) { return(source); } BlendState.Opaque.Apply(); DepthStencilState.None.Apply(); // RasterizerState.CullNone.Apply(MySandboxGameDX.Static.GraphicsDevice); m_thresholdTargets[0] = MyRender.GetRenderTarget(MyRenderTargets.HDRAux); m_thresholdTargets[1] = availableRenderTarget; // 1. threshold GenerateThreshold( source, MyRender.GetRenderTarget(MyRenderTargets.Diffuse), m_thresholdTargets, MyRender.GetEffect(MyEffects.Threshold) as MyEffectThreshold, Threshold, BloomIntensity, BloomIntensityBackground, Exposure); /* * MySandboxGame.SetRenderTarget(null, null, SetDepthTargetEnum.RestoreDefault); * MySandboxGame.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault); * MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot; * ssEffect.SetSourceTexture(m_thresholdTargets[0]); * ssEffect.SetScale(VRageMath.Vector2.One); * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); * MyGuiManager.GetFullscreenQuad().Draw(ssEffect); * return availableRenderTarget; */ // 2. downscale HDR1 -> Downscaled8 // !! IMPORTANT !! you cannot just switch the function call if you want different downscale // Also changing the RTs is necessary (they have fixed dimensions). GenerateDownscale4( MyRender.GetRenderTarget(MyRenderTargets.HDRAux), // Requires mip mapped RT with mip autogeneration MyRender.GetRenderTarget(MyRenderTargets.Depth), MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetEffect(MyEffects.Scale) as MyEffectScale); /* * // 3?. avg luminance * float dt = (MySandboxGame.TotalGamePlayTimeInMilliseconds - lastTime) / 1000.0f; * lastTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; * CalculateAverageLuminance( * MyRender.GetRenderTarget(MyRenderTargets.Downscaled8), * MyRender.GetRenderTarget(MyRenderTargets.Downscaled8Threshold), * MyRender.GetEffect(MyEffects.Luminance) as MyEffectLuminance, * MyRender.GetEffect(MyEffects.Scale) as MyEffectScale, * dt, 0.5f); */ // 4. blur Blur(MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetRenderTarget(MyRenderTargets.HDR4), MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur, VerticalBlurAmount, HorizontalBlurAmount); // 5. scale blurred to halfsize Upscale4To2( MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold), MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102), MyRender.GetEffect(MyEffects.Scale) as MyEffectScale); MyRender.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault); // 6. tonemap + apply bloom HDR( source, MyRender.GetRenderTarget(MyRenderTargets.Diffuse), MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102), MyRender.GetEffect(MyEffects.HDR) as MyEffectHDR, 0.6f, Exposure); return(availableRenderTarget); //RenderTarget2D temp = currentFrameAdaptedLuminance; //currentFrameAdaptedLuminance = lastFrameAdaptedLuminance; //lastFrameAdaptedLuminance = temp; } } return(source); }
internal static void RenderPostProcesses(PostProcessStage postProcessStage, Texture source, Texture[] target, Texture availableRT, bool copyToTarget = true, bool scaleToTarget = false) { Texture lastSurface = source; GetRenderProfiler().StartProfilingBlock("Render Post process: " + postProcessStage.ToString()); { if (Settings.EnableLightsRuntime) { (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).DefaultTechnique = MyEffectBlendLights.Technique.LightsEnabled; (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).CopyEmissivityTechnique = MyEffectBlendLights.Technique.CopyEmissivity; MyEffectDirectionalLight directionalLight = MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight; directionalLight.DefaultTechnique = MyEffectDirectionalLight.Technique.Default; directionalLight.DefaultWithoutShadowsTechnique = MyEffectDirectionalLight.Technique.WithoutShadows; directionalLight.DefaultNoLightingTechnique = MyEffectDirectionalLight.Technique.NoLighting; MyEffectPointLight pointLight = MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight; pointLight.PointTechnique = MyEffectPointLight.MyEffectPointLightTechnique.Point; pointLight.PointWithShadowsTechnique = MyEffectPointLight.MyEffectPointLightTechnique.PointShadows; pointLight.HemisphereTechnique = MyEffectPointLight.MyEffectPointLightTechnique.Point; pointLight.SpotTechnique = MyEffectPointLight.MyEffectPointLightTechnique.Spot; pointLight.SpotShadowTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotShadows; } } foreach (MyPostProcessBase postProcess in m_postProcesses) { if (postProcess.Enabled && (MyRender.CurrentRenderSetup.EnabledPostprocesses == null || MyRender.CurrentRenderSetup.EnabledPostprocesses.Contains(postProcess.Name))) { var currSurface = postProcess.Render(postProcessStage, lastSurface, availableRT); // Effect used availableRT as target, so lastSurface is available now if (currSurface != lastSurface && lastSurface != null) { availableRT = lastSurface; } lastSurface = currSurface; } } GetRenderProfiler().EndProfilingBlock(); if (lastSurface != null && copyToTarget) { MyRender.SetRenderTargets(target, null); if (scaleToTarget) SetCorrectViewportSize(); BlendState.Opaque.Apply(); Blit(lastSurface, scaleToTarget); } }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.LODBlend: { MyEffectVolumetricSSAO2 volumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2; int width = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width; int height = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height; int screenSizeX = width; int screenSizeY = height; //Render SSAO MyRender.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAO), null); MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0), 1, 0); DepthStencilState.None.Apply(); BlendState.Opaque.Apply(); Vector4 ssaoParams = new Vector4(MinRadius, MaxRadius, RadiusGrowZScale, CameraZFar); Vector4 ssaoParams2 = new Vector4(Bias, Falloff, NormValue, 0); volumetricSsao.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); volumetricSsao.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals)); volumetricSsao.SetHalfPixel(screenSizeX, screenSizeY); volumetricSsao.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); volumetricSsao.SetViewMatrix(MyRenderCamera.ViewMatrixAtZero); volumetricSsao.SetParams1(ssaoParams); volumetricSsao.SetParams2(ssaoParams2); volumetricSsao.SetProjectionMatrix(MyRenderCamera.ProjectionMatrix); volumetricSsao.SetContrast(Contrast); MyRender.GetFullscreenQuad().Draw(volumetricSsao); if (UseBlur) { //SSAO Blur MyRender.SetRenderTarget(availableRenderTarget, null); MyEffectSSAOBlur2 effectSsaoBlur = MyRender.GetEffect(MyEffects.SSAOBlur) as MyEffectSSAOBlur2; effectSsaoBlur.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth)); //effectSsaoBlur.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals)); effectSsaoBlur.SetHalfPixel(width, height); effectSsaoBlur.SetSSAOHalfPixel(screenSizeX, screenSizeY); effectSsaoBlur.SetSsaoRT(MyRender.GetRenderTarget(MyRenderTargets.SSAO)); effectSsaoBlur.SetBlurDirection(new Vector2(0, 1f / (float)screenSizeY)); //effectSsaoBlur.SetBlurDirection(new Vector2(1 / (float)halfWidth, 1f / (float)halfHeight)); MyRender.GetFullscreenQuad().Draw(effectSsaoBlur); MyRender.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), null); effectSsaoBlur.SetSsaoRT(availableRenderTarget); effectSsaoBlur.SetBlurDirection(new Vector2(1f / (float)screenSizeX, 0)); MyRender.GetFullscreenQuad().Draw(effectSsaoBlur); } //Bake it into diffuse /* MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot; MySandboxGame.SetRenderTarget(availableRenderTarget, null); ssEffect.SetSourceTexture(MyRender.GetRenderTarget(MyRenderTargets.Diffuse)); ssEffect.SetScale(Vector2.One); ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); MyGuiManager.GetFullscreenQuad().Draw(ssEffect); */ MyRender.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.Diffuse), null); /* ssEffect.SetSourceTexture(availableRenderTarget); ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default); ssEffect.SetScale(Vector2.One); MyGuiManager.GetFullscreenQuad().Draw(ssEffect); */ MyEffectVolumetricSSAO2 effectVolumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2; //Blend with SSAO together DepthStencilState.None.Apply(); if (!ShowOnlySSAO) { MyRender.BeginSpriteBatch(MyStateObjects.SSAO_BlendState); } else { MyRender.CurrentRenderSetup.EnableLights = false; MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(1.0f), 1, 0); MyRender.BeginSpriteBatch(MyStateObjects.SSAO_BlendState); } if (UseBlur) MyRender.DrawSprite(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), new Rectangle(0, 0, MyRenderCamera.Viewport.Width, MyRenderCamera.Viewport.Height), Color.White); else MyRender.DrawSprite(MyRender.GetRenderTarget(MyRenderTargets.SSAO), new Rectangle(0, 0, MyRenderCamera.Viewport.Width, MyRenderCamera.Viewport.Height), Color.White); MyRender.EndSpriteBatch(); } break; } return source; }
/// <summary> /// Render method is called directly by renderer. Depending on stage, post process can do various things /// </summary> /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights() public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget) { switch (postProcessStage) { case PostProcessStage.AlphaBlended: { var halfRT = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0); MyRender.SetRenderTarget(halfRT, null); BlendState.Opaque.Apply(); RasterizerState.CullNone.Apply(); DepthStencilState.None.Apply(); MyEffectGodRays effectGodRays = MyRender.GetEffect(MyEffects.GodRays) as MyEffectGodRays; effectGodRays.SetDiffuseTexture(source); effectGodRays.SetDepthTexture(MyRender.GetRenderTarget(MyRenderTargets.Depth)); effectGodRays.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners()); effectGodRays.SetView((Matrix)MyRenderCamera.ViewMatrix); effectGodRays.SetWorldViewProjection((Matrix)MyRenderCamera.ViewProjectionMatrix); effectGodRays.SetDensity(Density); effectGodRays.SetDecay(Decay); effectGodRays.SetWeight(Weight * (1 - MyRender.FogProperties.FogMultiplier)); effectGodRays.SetExposition(Exposition); effectGodRays.SetLightPosition(15000f * -MyRender.Sun.Direction); effectGodRays.SetLightDirection(MyRender.Sun.Direction); effectGodRays.SetCameraPos((Vector3)MyRenderCamera.Position); MyRender.GetFullscreenQuad().Draw(effectGodRays); if (ApplyBlur) { var auxTarget = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102); var blurEffect = MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur; blurEffect.SetHalfPixel(halfRT.GetLevelDescription(0).Width, halfRT.GetLevelDescription(0).Height); // Apply vertical gaussian blur MyRender.SetRenderTarget(auxTarget, null); blurEffect.BlurAmount = 1; blurEffect.SetSourceTexture(halfRT); blurEffect.SetHeightForVerticalPass(halfRT.GetLevelDescription(0).Height); MyRender.GetFullscreenQuad().Draw(blurEffect); // Apply horizontal gaussian blur MyRender.SetRenderTarget(halfRT, null); blurEffect.BlurAmount = 1; blurEffect.SetSourceTexture(auxTarget); blurEffect.SetWidthForHorisontalPass(auxTarget.GetLevelDescription(0).Width); MyRender.GetFullscreenQuad().Draw(blurEffect); } // Additive MyRender.SetRenderTarget(availableRenderTarget, null); //MySandboxGame.Static.GraphicsDevice.Clear(ClearFlags.All, new SharpDX.ColorBGRA(0), 1, 0); BlendState.Opaque.Apply(); MyRender.Blit(source, true); var upscaleEffect = MyRender.GetEffect(MyEffects.Scale) as MyEffectScale; upscaleEffect.SetScale(new Vector2(2)); upscaleEffect.SetTechnique(MyEffectScale.Technique.HWScale); MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply(); upscaleEffect.SetSourceTextureMod(halfRT); MyRender.GetFullscreenQuad().Draw(upscaleEffect); return availableRenderTarget; } } return source; }