Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }