예제 #1
0
        protected override void Draw(GameTime gameTime)
        {
            // render the scene in black
            RenderScene(
                _RenderTargetMask,
                _EffectBlack,
                _WorldView,
                _WorldProjection);
            // render the scene with material and lighting
            RenderScene(
                _RenderTargetColor,
                _ModelMaterial,
                _WorldView,
                _WorldProjection);

            // _saveRTasPNG(_RenderTargetColor, "RenderTargetColor.png");

            // additively render the mask over the background
            GraphicsDevice.SetRenderTarget(_RenderTargetTemp);
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, basicEffect, Matrix.CreateScale(1f / (float)texFactor));
            spriteBatch.Draw(_BackgroundTexture, new Rectangle((int)((2 * LightMapPosition.X + LightMapOffset.X) * GraphicsDevice.Viewport.Width - _BackgroundTexture.Width / texFactor / 2), (int)((2 * LightMapPosition.Y + LightMapOffset.Y) * GraphicsDevice.Viewport.Height - _BackgroundTexture.Height / texFactor / 2), (int)(_BackgroundTexture.Width / texFactor), (int)(_BackgroundTexture.Height / texFactor)), Color.White);
            spriteBatch.Draw(_RenderTargetMask, Vector2.Zero, Color.Black);
            spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            // _saveRTasPNG(_RenderTargetTemp, "blend.png");

            // create mipmap levels of the resulting target
            RenderTarget2D[] MipLevels =
                _PostScreenFilters.CreateMipMapLevels(
                    _RenderTargetTemp);

            //for (int i = 0; i < MipLevels.Length; ++i)
            //_saveRTasPNG(MipLevels[ i ], "mipLevel_" + i + ".png");


            // perform the light shafts on half of the resolution
            _PostScreenFilters.LightShafts(
                MipLevels[0],
                _RenderTargetShaftsHalf,
                LightMapPosition,
                LightShaftDensity,
                LightShaftDecay,
                LightShaftWeight,
                LightShaftExposure);

            // _saveRTasPNG(_RenderTargetShaftsHalf, "RenderTargetShaftsHalf.png");

            // up-scale the effect
            _PostScreenFilters.HalfToFullscreen(
                _RenderTargetShaftsHalf,
                _RenderTargetShaftsFull);

            // _saveRTasPNG(_RenderTargetShaftsFull, "RenderTargetShaftsFull.png");

            ///////////////////////////////////////////////////////////
            ////Doesn't work...maybe he forgot or whatever...////
            // extract luminance values above threshold
            //_PostScreenFilters.ExtractHighLuminance(
            //    _RenderTargetShaftsFull,
            //    _RenderTargetLuminance,
            //    LuminanceThreshold,
            //    LuminanceScaleFactor);

            // create mipmap levels of extracted values and
            // additively blend them
            //RenderTarget2D RT = _PostScreenFilters.AdditiveBlend(
            //    _RenderTargetLuminance);

            // _saveRTasPNG(RT, "AdditiveBlend.png");

            //////////////////////////////////////////////////////

            // combine all the targets
            GraphicsDevice.SetRenderTarget(_RenderTargetFinal);
            GraphicsDevice.Clear(ClearOptions.Target, Vector4.Zero, 1, 0);
            spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.Additive);
            spriteBatch.Draw(_RenderTargetShaftsFull, Vector2.Zero, Color.White);
            spriteBatch.Draw(_RenderTargetColor, Vector2.Zero, Color.White);
////            spriteBatch.Draw(RT, Vector2.Zero, Color.White);
            spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);


            // draw them on the screen
            spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.Opaque);
            spriteBatch.Draw(
                _RenderTargetFinal,
                Vector2.Zero,
                Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
예제 #2
0
        protected override void Draw(GameTime gameTime)
        {
            //  render the scene in black
            RenderScene(
                _RenderTargetMask,
                _EffectBlack,
                _WorldView,
                _WorldProjection);
            // render the scene with material and lighting
            RenderScene(
                _RenderTargetColor,
                _ModelMaterial,
                _WorldView,
                _WorldProjection);

            // _saveRTasPNG(_RenderTargetColor, "RenderTargetColor.png");

            // additively render the mask over the background
            GraphicsDevice.SetRenderTarget(_RenderTargetMaskedBackground);
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.AlphaBlend,
                null,
                null,
                null,
                basicEffect,
                Matrix.CreateScale(1f / (float)texFactor));
            spriteBatch.Draw(
                _BackgroundTexture,
                new Rectangle(
                    (int)((2 * LightMapPosition.X + LightMapOffset.X) * GraphicsDevice.Viewport.Width - _BackgroundTexture.Width / texFactor / 2),
                    (int)((2 * LightMapPosition.Y + LightMapOffset.Y) * GraphicsDevice.Viewport.Height - _BackgroundTexture.Height / texFactor / 2),
                    (int)(_BackgroundTexture.Width / texFactor),
                    (int)(_BackgroundTexture.Height / texFactor)),
                Color.White);
            spriteBatch.Draw(
                _RenderTargetMask,
                Vector2.Zero,
                Color.Black);
            spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            //_saveRTasPNG(_RenderTargetMaskedBackground, "MaskedBackground.png");

            // applying the 'linearFilter' effect to the masked background
            // on half of the resolution
            _PostScreenFilters.linearFilter(
                _RenderTargetMaskedBackground,
                _RenderTargetLinearFilter);

            // perform the light shafts on the masked background
            // on half of the resolution
            _PostScreenFilters.LightShafts(
                _RenderTargetLinearFilter,
                _RenderTargetShaftsHalf,
                LightMapPosition,
                LightShaftDensity,
                LightShaftDecay,
                LightShaftWeight,
                LightShaftExposure);

            // _saveRTasPNG(_RenderTargetShaftsHalf, "RenderTargetShaftsHalf.png");

            // up-scale the effect
            _PostScreenFilters.HalfToFullscreen(
                _RenderTargetShaftsHalf,
                _RenderTargetShaftsFull);

            // _saveRTasPNG(_RenderTargetShaftsFull, "RenderTargetShaftsFull.png");


            // combine all the targets
            GraphicsDevice.SetRenderTarget(_RenderTargetFinal);
            GraphicsDevice.Clear(ClearOptions.Target, Vector4.Zero, 1, 0);
            spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.Additive);
            spriteBatch.Draw(
                _RenderTargetShaftsFull,
                Vector2.Zero,
                Color.White);
            spriteBatch.Draw(
                _RenderTargetColor,
                Vector2.Zero,
                Color.White);
            spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);


            // draw them on the screen
            spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.Opaque);
            spriteBatch.Draw(
                _RenderTargetFinal,
                Vector2.Zero,
                Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }