public override void process(RenderTarget2D source, RenderTarget2D destination) { if (_blurEnabled) { // aquire a temporary rendertarget for the processing. It can be scaled via renderTargetScale in order to minimize fillrate costs. Reducing // the resolution in this way doesn't hurt quality, because we are going to be blurring the images in any case. var sceneRenderTargetSize = scene.sceneRenderTargetSize; var tempRenderTarget = RenderTarget.getTemporary( (int)(sceneRenderTargetSize.X * _blurRenderTargetScale), (int)(sceneRenderTargetSize.Y * _blurRenderTargetScale), DepthFormat.None); // Pass 1: draw from _lightsRenderTexture into tempRenderTarget, applying a horizontal gaussian blur filter _blurEffect.prepareForHorizontalBlur(); drawFullscreenQuad(_lightsRenderTexture, tempRenderTarget, _blurEffect); // Pass 2: draw from tempRenderTarget back into _lightsRenderTexture, applying a vertical gaussian blur filter _blurEffect.prepareForVerticalBlur(); drawFullscreenQuad(tempRenderTarget, _lightsRenderTexture, _blurEffect); RenderTarget.releaseTemporary(tempRenderTarget); } Core.graphicsDevice.setRenderTarget(destination); Graphics.instance.batcher.begin(effect); Graphics.instance.batcher.draw( source, new Rectangle(0, 0, destination.Width, destination.Height), Color.White); Graphics.instance.batcher.end(); }
public override void process(RenderTarget2D source, RenderTarget2D destination) { // aquire two rendertargets for the bloom processing. These can be scaled via renderTargetScale in order to minimize fillrate costs. Reducing // the resolution in this way doesn't hurt quality, because we are going to be blurring the bloom images in any case. var sceneRenderTargetSize = scene.sceneRenderTargetSize; var renderTarget1 = RenderTarget.getTemporary( (int)(sceneRenderTargetSize.X * renderTargetScale), (int)(sceneRenderTargetSize.Y * renderTargetScale), DepthFormat.None); var renderTarget2 = RenderTarget.getTemporary( (int)(sceneRenderTargetSize.X * renderTargetScale), (int)(sceneRenderTargetSize.Y * renderTargetScale), DepthFormat.None); // Pass 1: draw the scene into rendertarget 1, using a shader that extracts only the brightest parts of the image. drawFullscreenQuad(source, renderTarget1, _bloomExtractEffect); // Pass 2: draw from rendertarget 1 into rendertarget 2, using a shader to apply a horizontal gaussian blur filter. _gaussianBlurEffect.prepareForHorizontalBlur(); drawFullscreenQuad(renderTarget1, renderTarget2, _gaussianBlurEffect); // Pass 3: draw from rendertarget 2 back into rendertarget 1, using a shader to apply a vertical gaussian blur filter. _gaussianBlurEffect.prepareForVerticalBlur(); drawFullscreenQuad(renderTarget2, renderTarget1, _gaussianBlurEffect); // Pass 4: draw both rendertarget 1 and the original scene image back into the main backbuffer, using a shader that // combines them to produce the final bloomed result. Core.graphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; _bloomBaseMapParm.SetValue(source); drawFullscreenQuad(renderTarget1, destination, _bloomCombineEffect); RenderTarget.releaseTemporary(renderTarget1); RenderTarget.releaseTemporary(renderTarget2); }