Beispiel #1
0
        /// <summary>
        /// Construct a new copy of our renderer
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <param name="contentManager"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Renderer(GraphicsDevice graphicsDevice, ContentManager contentManager, int width, int height)
        {
            _width          = width;
            _height         = height;
            _graphicsDevice = graphicsDevice;
            _contentManager = contentManager;
            _quadRenderer   = new QuadRenderer();
            _sphereRenderer = new MeshRenderer(contentManager.Load <Model>("meshes/sphere"));
            _spotRenderer   = new MeshRenderer(contentManager.Load <Model>("meshes/cone"));

            _cwDepthState = new DepthStencilState();
            _cwDepthState.DepthBufferWriteEnable = false;
            _cwDepthState.DepthBufferFunction    = CompareFunction.LessEqual;

            _ccwDepthState = new DepthStencilState();
            _ccwDepthState.DepthBufferWriteEnable = false;
            _ccwDepthState.DepthBufferFunction    = CompareFunction.GreaterEqual;

            _depthStateDrawLights = new DepthStencilState();

            //we draw our volumes with front-face culling, so we have to use GreaterEqual here
            _depthStateDrawLights.DepthBufferFunction = CompareFunction.GreaterEqual;
            //with our z-buffer reconstructed we only need to read it
            _depthStateDrawLights.DepthBufferWriteEnable = false;

            _shadowRenderer = new ShadowRenderer(this);

            _depthStateReconstructZ = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                DepthBufferFunction    = CompareFunction.Always
            };

            _lightAddBlendState = new BlendState()
            {
                AlphaSourceBlend      = Blend.One,
                ColorSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One,
            };

            //create render queues
            for (int index = 0; index < _visibleMeshes.Length; index++)
            {
                _visibleMeshes[index] = new List <Mesh.SubMesh>();
            }


            CreateGBuffer();
            LoadShaders();

            _downsampleDepth = new DownsampleDepthEffect();
            _downsampleDepth.Init(contentManager, this);
        }
Beispiel #2
0
        /// <summary>
        /// Construct a new copy of our renderer
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <param name="contentManager"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Renderer(GraphicsDevice graphicsDevice, ContentManager contentManager, int width, int height)
        {
            _width = width;
            _height = height;
            _graphicsDevice = graphicsDevice;
            _contentManager = contentManager;
            _quadRenderer = new QuadRenderer();
            _sphereRenderer = new MeshRenderer(contentManager.Load<Model>("meshes/sphere"));
            _spotRenderer = new MeshRenderer(contentManager.Load<Model>("meshes/cone"));

            _cwDepthState = new DepthStencilState();
            _cwDepthState.DepthBufferWriteEnable = false;
            _cwDepthState.DepthBufferFunction = CompareFunction.LessEqual;

            _ccwDepthState = new DepthStencilState();
            _ccwDepthState.DepthBufferWriteEnable = false;
            _ccwDepthState.DepthBufferFunction = CompareFunction.GreaterEqual;

            _depthStateDrawLights = new DepthStencilState();

            //we draw our volumes with front-face culling, so we have to use GreaterEqual here
            _depthStateDrawLights.DepthBufferFunction = CompareFunction.GreaterEqual;
            //with our z-buffer reconstructed we only need to read it
            _depthStateDrawLights.DepthBufferWriteEnable = false;

            _shadowRenderer = new ShadowRenderer(this);

            _depthStateReconstructZ = new DepthStencilState
            {
                DepthBufferEnable = true,
                DepthBufferWriteEnable = true,
                DepthBufferFunction = CompareFunction.Always
            };

            _lightAddBlendState = new BlendState()
            {
                AlphaSourceBlend = Blend.One,
                ColorSourceBlend = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One,
            };

            //create render queues
            for (int index = 0; index < _visibleMeshes.Length; index++)
            {
                _visibleMeshes[index] = new List<Mesh.SubMesh>();
            }


            CreateGBuffer();
            LoadShaders();

            _downsampleDepth = new DownsampleDepthEffect();
            _downsampleDepth.Init(contentManager, this);
        }