コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="camera"></param>
        /// <param name="scene"></param>
        public void Render(RenderTarget target, Camera camera, Scene scene)
        {
            // Flat rendering: http://community.monogame.net/t/flat-shading-low-poly/8668
            if (scene.mLights.Count <= 0)
            {
                throw new EngineInvalidParameterException("Scene doesn't contain any light sources");
            }
            else
            {
                mGraphicsDevice.BlendState      = BlendState.Opaque;
                mGraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

                mGraphicsDevice.SetRenderTarget(target.mMainRenderTarget);

                mGraphicsDevice.Clear(new Color(41, 122, 255));

                mForwardRenderer.Render(target, camera, scene);

                mGraphicsDevice.SetRenderTarget(null);

                mGraphicsDevice.SetVertexBuffer(mQuad.mBuffer);

                mPostProcessRenderer.Render(target, camera, scene);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewport"></param>
        /// <param name="target"></param>
        /// <param name="camera"></param>
        /// <param name="scene"></param>
        public void Render(Viewport viewport, RenderTarget target, Camera camera, Scene scene)
        {
            // Flat rendering: http://community.monogame.net/t/flat-shading-low-poly/8668
            if (scene.mLights.Count <= 0)
            {
                throw new EngineInvalidParameterException("Scene doesn't contain any light sources");
            }
            else
            {
                mGraphicsDevice.BlendState      = BlendState.Opaque;
                mGraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

                var globaLight = scene.mLights[0];

                if (globaLight.mShadow.mActivated)
                {
                    mGraphicsDevice.SetRenderTarget(target.mShadowRenderTarget);

                    mGraphicsDevice.Clear(Color.White);

                    mShadowRenderer.Render(target, camera, scene);
                }

                mGraphicsDevice.SetRenderTarget(target.mMainRenderTarget);

                mGraphicsDevice.Clear(new Color(41, 122, 255));

                mForwardRenderer.Render(target, camera, scene);

                // Check which framebuffer we need to use.
                // If we want to have Anti-Aliasing we need to bind the post-process render target
                if (scene.mPostProcessing.mFxaa.mActivated)
                {
                    mGraphicsDevice.SetRenderTarget(target.mPostProcessRenderTarget);
                }
                else
                {
                    mGraphicsDevice.SetRenderTarget(null);
                }

                mGraphicsDevice.SetVertexBuffer(mQuad.mBuffer);

                var defaultViewport = mGraphicsDevice.Viewport;
                mGraphicsDevice.Viewport = viewport;

                mPostProcessRenderer.Render(target, camera, scene);

                if (scene.mPostProcessing.mFxaa.mActivated)
                {
                    mGraphicsDevice.SetRenderTarget(null);

                    mFxaaRenderer.Render(target, camera, scene);
                }

                mGraphicsDevice.Viewport = defaultViewport;
            }
        }
コード例 #3
0
        /// <summary>
        /// Renders the scene.
        /// </summary>
        /// <param name="viewport">The viewport in which the scene should be rendered</param>
        /// <param name="target">The target which can be used to be rendered on</param>
        /// <param name="camera">The camera from which perspective the scene will be rendered</param>
        /// <param name="scene">The scene to be rendered</param>
        public void Render(Viewport viewport, RenderTarget target, Camera camera, Scene scene)
        {
            var defaultViewport = mGraphicsDevice.Viewport;

            mGraphicsDevice.Viewport = target.mRenderViewport;
            var defaultRenderTarget = mGraphicsDevice.GetRenderTargets();

            mGraphicsDevice.BlendState      = BlendState.Opaque;
            mGraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            var light = scene.mSky.Light;

            if (light.mShadow.mActivated)
            {
                mGraphicsDevice.SetRenderTarget(target.mShadowRenderTarget);

                mGraphicsDevice.Clear(Color.White);

                mShadowRenderer.Render(target, camera, scene);
            }

            mGraphicsDevice.SetRenderTarget(target.mMainRenderTarget);

            if (mPrePass)
            {
                mPrePassRenderer.Render(target, camera, scene);
            }

            mForwardRenderer.Render(target, camera, scene);

            mGraphicsDevice.RasterizerState = RasterizerState.CullNone;

            if (scene.mTerrain != null && scene.mTerrain.mGrass.mActivated)
            {
                mGrassRenderer.Render(target, camera, scene);
            }

            if (DebugMode)
            {
                mBoundingRectRenderer.Render(target, camera, scene);
                mVisibilityGraphRenderer.Render(target, camera, scene);
            }

            mGraphicsDevice.RasterizerState = RasterizerState.CullClockwise;

            mSkyRenderer.Render(target, camera, scene);

            mGraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            mGraphicsDevice.SetVertexBuffer(mQuad.mBuffer);

            if (scene.mPostProcessing.mBloom.Activated)
            {
                mBloomRenderer.Render(target, camera, scene);
            }

            // Check which framebuffer we need to use.
            // If we want to have Anti-Aliasing we need to bind the post-process render target
            if (scene.mPostProcessing.mFxaa.Activated)
            {
                mGraphicsDevice.SetRenderTarget(target.mPostProcessRenderTarget);
            }
            else
            {
                mGraphicsDevice.SetRenderTargets(defaultRenderTarget);

                mGraphicsDevice.Viewport = viewport;
            }

            mPostProcessRenderer.Render(target, camera, scene);

            if (scene.mPostProcessing.mFxaa.Activated)
            {
                mGraphicsDevice.SetRenderTargets(defaultRenderTarget);
                mGraphicsDevice.Viewport = viewport;

                mFxaaRenderer.Render(target, camera, scene);
            }

            mGraphicsDevice.Viewport = defaultViewport;
        }