private void ReconstructDepth()
        {
            if (_viewProjectionHasChanged)
            {
                Shaders.ReconstructDepthParameter_Projection.SetValue(_projection);
            }

            _graphicsDevice.DepthStencilState = DepthStencilState.Default;
            Shaders.ReconstructDepth.CurrentTechnique.Passes[0].Apply();
            _fullScreenTriangle.Draw(_graphicsDevice);
        }
Ejemplo n.º 2
0
        public RenderTargetCube DrawGaussianBlur(RenderTargetCube renderTargetOutput, CubeMapFace cubeFace, FullScreenTriangle triangle)
        {
            //select rendertarget
            RenderTarget2D renderTargetBlur = null;

            if (renderTargetOutput.Format != SurfaceFormat.Vector2)
            {
                throw new NotImplementedException("Unsupported Format for blurring");
            }

            //Only square expected
            int size = renderTargetOutput.Size;

            switch (size)
            {
            case 256:
                renderTargetBlur = _rt2562;
                break;

            case 512:
                renderTargetBlur = _rt5122;
                break;

            case 1024:
                renderTargetBlur = _rt10242;
                break;

            case 2048:
                renderTargetBlur = _rt20482;
                break;
            }

            if (renderTargetBlur == null)
            {
                throw new NotImplementedException("Unsupported Size for blurring");
            }

            _graphicsDevice.SetRenderTarget(renderTargetBlur);

            Vector2 invRes = new Vector2(1.0f / size, 1.0f / size);

            Shaders.GaussianBlurEffectParameter_InverseResolution.SetValue(invRes);
            Shaders.GaussianBlurEffectParameter_TargetMap.SetValue(renderTargetOutput);

            _horizontalPass.Apply();
            triangle.Draw(_graphicsDevice);

            _graphicsDevice.SetRenderTarget(renderTargetOutput, cubeFace);
            Shaders.GaussianBlurEffectParameter_TargetMap.SetValue(renderTargetBlur);
            _verticalPass.Apply();
            triangle.Draw(_graphicsDevice);

            return(renderTargetOutput);
        }
        public RenderTarget2D CreateSDFTexture(GraphicsDevice graphics, Texture2D triangleData, int xsteps, int ysteps, int zsteps, SignedDistanceField sdf, FullScreenTriangle fullScreenTriangle, int trianglesLength)
        {
            RenderTarget2D output = new RenderTarget2D(graphics, xsteps * zsteps, ysteps, false, SurfaceFormat.Single, DepthFormat.None);

            graphics.SetRenderTarget(output);

            //Offset isntead of position!
            _volumeTexResolutionArray[0] = new Vector4(xsteps, ysteps, zsteps, 0);
            _volumeTexSizeArray[0]       = sdf.VolumeSize;

            _volumeTexSizeParam.SetValue(_volumeTexSizeArray);
            _volumeTexResolutionParam.SetValue(_volumeTexResolutionArray);

            MeshOffset = sdf.Offset;
            VolumeTex  = triangleData;

            _triangleTexResolution.SetValue(new Vector2(triangleData.Width, triangleData.Height));
            _triangleAmount.SetValue((float)trianglesLength);

            _generateSDFPass.Apply();
            fullScreenTriangle.Draw(graphics);

            _signedDistanceFieldDefinitionsCount = -1;

            return(output);
        }
Ejemplo n.º 4
0
        public void DrawSky(GraphicsDevice graphicsDevice, FullScreenTriangle quadRenderer)
        {
            graphicsDevice.DepthStencilState = DepthStencilState.None;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;

            _passSky.Apply();
            quadRenderer.Draw(graphicsDevice);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// returns a modified image with color grading applied.
        /// </summary>
        /// <param name="graphics"> GraphicsDevice</param>
        /// <param name="input"> The basic texture or rendertarget you want to modify</param>
        /// <param name="lookupTable"> The specific lookup table used</param>
        /// <returns></returns>
        public RenderTarget2D Draw(GraphicsDevice graphics, Texture2D input, Texture2D lookupTable)
        {
            //Set up rendertarget
            if (_renderTarget == null || _renderTarget.Width != input.Width || _renderTarget.Height != input.Height)
            {
                _renderTarget?.Dispose();
                _renderTarget = new RenderTarget2D(graphics, input.Width, input.Height, false, SurfaceFormat.Color, DepthFormat.None);
            }

            InputTexture = input;
            LookUpTable  = lookupTable;
            Size         = (lookupTable.Width == 64) ? 16 : 32;

            graphics.SetRenderTarget(_renderTarget);
            graphics.BlendState = BlendState.Opaque;

            _applyLUTPass.Apply();
            _fullScreenTriangle.Draw(graphics);
            return(_renderTarget);
        }
        public void Draw(GraphicsDevice _graphicsDevice, bool useTonemap, RenderTarget2D currentFrame, RenderTarget2D previousFrames, RenderTarget2D output, Matrix currentViewToPreviousViewProjection, FullScreenTriangle fullScreenTriangle)
        {
            UseTonemap = useTonemap;

            _graphicsDevice.SetRenderTarget(output);
            _graphicsDevice.BlendState = BlendState.Opaque;

            _paramAccumulationMap.SetValue(previousFrames);
            _paramUpdateMap.SetValue(currentFrame);
            _paramCurrentToPrevious.SetValue(currentViewToPreviousViewProjection);

            _taaPass.Apply();
            fullScreenTriangle.Draw(_graphicsDevice);

            if (useTonemap)
            {
                _graphicsDevice.SetRenderTarget(currentFrame);
                _paramUpdateMap.SetValue(output);
                _invTonemapPass.Apply();
                fullScreenTriangle.Draw(_graphicsDevice);
            }
        }
Ejemplo n.º 7
0
        public void Draw(GraphicsDevice graphicsDevice, Camera camera, VolumeTextureEntity volumeTextureEntity, FullScreenTriangle fullScreenTriangle)
        {
            CameraPosition = camera.Position;

            VolumeTex           = volumeTextureEntity.Texture;
            VolumeTexPosition   = volumeTextureEntity.Position;
            VolumeTexResolution = volumeTextureEntity.Resolution;
            VolumeTexSize       = volumeTextureEntity.Size;

            _basicPass.Apply();
            fullScreenTriangle.Draw(graphicsDevice);
            //quadRenderer.RenderFullscreenQuad(graphicsDevice);
        }
Ejemplo n.º 8
0
        public void DrawEnvironmentMap(GraphicsDevice graphicsDevice, Matrix view, FullScreenTriangle fullScreenTriangle, EnvironmentSample envSample, bool fireflyReduction, float ffThreshold)
        {
            FireflyReduction = fireflyReduction;
            FireflyThreshold = ffThreshold;

            SpecularStrength = envSample.SpecularStrength;
            DiffuseStrength  = envSample.DiffuseStrength;

            graphicsDevice.DepthStencilState = DepthStencilState.None;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            _paramTransposeView.SetValue(Matrix.Transpose(view));

            _passBasic.Apply();
            fullScreenTriangle.Draw(graphicsDevice);
        }
        public void Draw(GraphicsDevice graphicsDevice, Camera camera, FullScreenTriangle fullScreenTriangle)
        {
            CameraPosition = camera.Position;

            //CheckUpdate
            CheckForShaderChanges();

            if (GameSettings.sdf_drawvolume)
            {
                _volumePass.Apply();
            }
            else
            {
                _distancePass.Apply();
            }
            fullScreenTriangle.Draw(graphicsDevice);
            //quadRenderer.RenderFullscreenQuad(graphicsDevice);
        }
        public void DrawEnvironmentMap(GraphicsDevice graphicsDevice, Camera camera, Matrix view, FullScreenTriangle fullScreenTriangle, EnvironmentSample envSample, GameTime gameTime, bool fireflyReduction, float ffThreshold)
        {
            FireflyReduction = fireflyReduction;
            FireflyThreshold = ffThreshold;

            SpecularStrength = envSample.SpecularStrength;
            DiffuseStrength  = envSample.DiffuseStrength;
            CameraPositionWS = camera.Position;

            Time = (float)gameTime.TotalGameTime.TotalSeconds % 1000;

            graphicsDevice.DepthStencilState = DepthStencilState.None;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            UseSDFAO = envSample.UseSDFAO;
            _paramTransposeView.SetValue(Matrix.Transpose(view));
            _passBasic.Apply();
            fullScreenTriangle.Draw(graphicsDevice);
        }
Ejemplo n.º 11
0
        public void Draw(GraphicsDevice _graphicsDevice, RenderTargetBinding[] _renderTargetBinding, MeshMaterialLibrary meshMaterialLibrary, Matrix _viewProjection, Matrix _view)
        {
            _graphicsDevice.SetRenderTargets(_renderTargetBinding);

            //Clear the GBuffer
            if (GameSettings.g_ClearGBuffer)
            {
                _graphicsDevice.RasterizerState   = RasterizerState.CullNone;
                _graphicsDevice.BlendState        = BlendState.Opaque;
                _graphicsDevice.DepthStencilState = DepthStencilState.Default;

                _clearGBufferPass.Apply();
                _fullScreenTriangle.Draw(_graphicsDevice);
            }

            //Draw the Gbuffer!

            meshMaterialLibrary.Draw(renderType: MeshMaterialLibrary.RenderType.Opaque, viewProjection: _viewProjection, lightViewPointChanged: true, view: _view, renderModule: this);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Main draw function
        /// </summary>
        /// <param name="inputTexture">the image from which we want to extract bright parts and blur these</param>
        /// <param name="width">width of our target. If different to the input.Texture width our final texture will be smaller/larger.
        /// For example we can use half resolution. Input: 1280px wide -> width = 640px
        /// The smaller this value the better performance and the worse our final image quality</param>
        /// <param name="height">see: width</param>
        /// <returns></returns>
        public Texture2D Draw(Texture2D inputTexture, int width, int height)
        {
            //Check if we are initialized
            if (_graphicsDevice == null)
            {
                throw new Exception("Module not yet Loaded / Initialized. Use Load() first");
            }

            ApplyGameSettings();

            //Change renderTarget resolution if different from what we expected. If lower than the inputTexture we gain performance.
            if (width != _width || height != _height)
            {
                UpdateResolution(width, height);

                //Adjust the blur so it looks consistent across diferrent scalings
                _radiusMultiplier = (float)width / inputTexture.Width;

                //Update our variables with the multiplier
                SetBloomPreset(BloomPreset);
            }

            _graphicsDevice.RasterizerState = RasterizerState.CullNone;
            _graphicsDevice.BlendState      = BlendState.Opaque;

            //EXTRACT  //Note: Is setRenderTargets(binding better?)
            //We extract the bright values which are above the Threshold and save them to Mip0
            _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip0);

            BloomScreenTexture     = inputTexture;
            BloomInverseResolution = new Vector2(1.0f / _width, 1.0f / _height);

            if (BloomUseLuminance)
            {
                _bloomPassExtractLuminance.Apply();
            }
            else
            {
                _bloomPassExtract.Apply();
            }
            _fullScreenTriangle.Draw(_graphicsDevice);

            //Now downsample to the next lower mip texture
            if (BloomDownsamplePasses > 0)
            {
                BloomInverseResolution *= 2;
                //DOWNSAMPLE TO MIP1
                _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip1);

                BloomScreenTexture = _bloomRenderTarget2DMip0;
                //Pass
                _bloomPassDownsample.Apply();
                _fullScreenTriangle.Draw(_graphicsDevice);

                if (BloomDownsamplePasses > 1)
                {
                    //Our input resolution is halfed, so our inverse 1/res. must be doubled
                    BloomInverseResolution *= 2;

                    //DOWNSAMPLE TO MIP2
                    _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip2);

                    BloomScreenTexture = _bloomRenderTarget2DMip1;
                    //Pass
                    _bloomPassDownsample.Apply();
                    _fullScreenTriangle.Draw(_graphicsDevice);

                    if (BloomDownsamplePasses > 2)
                    {
                        BloomInverseResolution *= 2;

                        //DOWNSAMPLE TO MIP3
                        _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip3);

                        BloomScreenTexture = _bloomRenderTarget2DMip2;
                        //Pass
                        _bloomPassDownsample.Apply();
                        _fullScreenTriangle.Draw(_graphicsDevice);

                        if (BloomDownsamplePasses > 3)
                        {
                            BloomInverseResolution *= 2;

                            //DOWNSAMPLE TO MIP4
                            _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip4);

                            BloomScreenTexture = _bloomRenderTarget2DMip3;
                            //Pass
                            _bloomPassDownsample.Apply();
                            _fullScreenTriangle.Draw(_graphicsDevice);

                            if (BloomDownsamplePasses > 4)
                            {
                                BloomInverseResolution *= 2;

                                //DOWNSAMPLE TO MIP5
                                _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip5);

                                BloomScreenTexture = _bloomRenderTarget2DMip4;
                                //Pass
                                _bloomPassDownsample.Apply();
                                _fullScreenTriangle.Draw(_graphicsDevice);

                                ChangeBlendState();

                                //UPSAMPLE TO MIP4
                                _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip4);
                                BloomScreenTexture = _bloomRenderTarget2DMip5;

                                BloomStrength = _bloomStrength5;
                                BloomRadius   = _bloomRadius5;
                                _bloomPassUpsample.Apply();
                                _fullScreenTriangle.Draw(_graphicsDevice);

                                BloomInverseResolution /= 2;
                            }

                            ChangeBlendState();

                            //UPSAMPLE TO MIP3
                            _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip3);
                            BloomScreenTexture = _bloomRenderTarget2DMip4;

                            BloomStrength = _bloomStrength4;
                            BloomRadius   = _bloomRadius4;
                            _bloomPassUpsample.Apply();
                            _fullScreenTriangle.Draw(_graphicsDevice);

                            BloomInverseResolution /= 2;
                        }

                        ChangeBlendState();

                        //UPSAMPLE TO MIP2
                        _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip2);
                        BloomScreenTexture = _bloomRenderTarget2DMip3;

                        BloomStrength = _bloomStrength3;
                        BloomRadius   = _bloomRadius3;
                        _bloomPassUpsample.Apply();
                        _fullScreenTriangle.Draw(_graphicsDevice);

                        BloomInverseResolution /= 2;
                    }

                    ChangeBlendState();

                    //UPSAMPLE TO MIP1
                    _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip1);
                    BloomScreenTexture = _bloomRenderTarget2DMip2;

                    BloomStrength = _bloomStrength2;
                    BloomRadius   = _bloomRadius2;
                    _bloomPassUpsample.Apply();
                    _fullScreenTriangle.Draw(_graphicsDevice);

                    BloomInverseResolution /= 2;
                }

                ChangeBlendState();

                //UPSAMPLE TO MIP0
                _graphicsDevice.SetRenderTarget(_bloomRenderTarget2DMip0);
                BloomScreenTexture = _bloomRenderTarget2DMip1;

                BloomStrength = _bloomStrength1;
                BloomRadius   = _bloomRadius1;

                _bloomPassUpsample.Apply();
                _fullScreenTriangle.Draw(_graphicsDevice);
            }

            //Note the final step could be done as a blend to the final texture.

            return(_bloomRenderTarget2DMip0);
        }