Example #1
0
        //---------------------------------------------------------------------------

        public RenderTarget2D Render(SpriteBatch batch, float deltaTime)
        {
            TransformComponent transform = GetComponent <TransformComponent>();

            if (transform != null)
            {
                CameraData data = new CameraData(transform.Location.To2D(), m_ComponentsTarget.Width, m_ComponentsTarget.Height);

                Device.SetRenderTarget(m_ComponentsTarget);
                Device.Clear(Color.Black);

                if (m_ComponentsTarget != null)
                {
                    if (BackgroundTexture != null)
                    {
                        Vector2 location = transform.Location.To2D();
                        batch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
                        batch.Draw(
                            BackgroundTexture,
                            Vector2.Zero,
                            new Rectangle((int)(location.X % BackgroundTexture.Width), (int)(location.Y % BackgroundTexture.Height), m_ComponentsTarget.Width, m_ComponentsTarget.Height),
                            Color.White,
                            0,
                            Vector2.Zero,
                            1f,
                            SpriteEffects.None,
                            0);
                        batch.End();
                    }
                    batch.Begin(SpriteSortMode.FrontToBack, null, SamplerState.PointClamp);
                    DrawStage(batch, data);
                    ComponentManager.Get().DrawComponents(batch, data, deltaTime);
                    batch.End();

                    if (IsLightingEnabled && m_LightingTarget != null && LightingEffect != null)
                    {
                        BlurEffect.Parameters["blurSizeHorizontal"].SetValue(1.0f / m_MainTarget.Width);
                        BlurEffect.Parameters["blurSizeVertical"].SetValue(1.0f / m_MainTarget.Height);

                        LightingEffect.Parameters["horizontalOffset"].SetValue(transform.Location.X + m_Time * 100.0f);
                        LightingEffect.Parameters["verticalOffset"].SetValue(transform.Location.Y + m_Time * 100.0f);
                        LightingEffect.Parameters["time"].SetValue(m_Time / 5.0f);

                        DrawLightMask(batch, data, deltaTime);

                        if (m_MainTarget != null)
                        {
                            LightingEffect.Parameters["lightMask"].SetValue(m_LightingTarget);
                            m_EffectWrapper.ApplyEffects(batch, m_ComponentsTarget, m_MainTarget, m_PostEffects);
                            m_EffectWrapper.ApplyEffects(batch, m_MainTarget, m_ShadowTarget, new List <Effect>()
                            {
                                BloomExtractEffect, BlurEffect
                            });

                            BloomCombineEffect.Parameters["bloom"].SetValue(m_ShadowTarget);
                            m_EffectWrapper.ApplyEffects(batch, m_MainTarget, m_ComponentsTarget, new List <Effect>()
                            {
                                BloomCombineEffect
                            });

                            return(m_MainTarget);
                        }
                        return(m_LightingTarget);
                    }
                }
            }
            return(m_ComponentsTarget);
        }