public void Begin(IEffect effect = null) { ThrowIfNotEnded(); if (effect != null) { _program = effect.Programs.First(); } else { _program = _defaultEffect.Programs.First(); } _program.Apply(); _gpu.PrepareRender(); _isRendering = true; }
public void Process(RenderTarget2D renderTarget) { // First step in all this is submitting our quad to the GPU. _gpu.SubmitVertices(_verts); _gpu.SubmitIndices(_indices); var rect = renderTarget.Bounds; if (EnableBloom && Settings.EnableBloom) { PerformBloom(renderTarget, rect); } else { NoEffect(renderTarget, rect); } if (Settings.EnableGlitch && _glitchIntensity > 0) { // update glitch settings. // _glitch.Parameters["Intensity"].SetValue(_glitchIntensity); // _glitch.Parameters["TextureSize"].SetValue(rect.Size.ToVector2()); // _glitch.Parameters["Skew"].SetValue(_glitchSkew); // copy intermediate to effect buffer 1. // using the glitch effect. // _gfx.SetRenderTarget(_effectBuffer1); // _batch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap); // _glitch.CurrentTechnique.Passes[0].Apply(); // _batch.Draw(_intermediate, rect, Color.White); // _batch.End(); // render effect buffer 1 to intermediate // _gfx.SetRenderTarget(_intermediate); // _batch.Begin(); // _batch.Draw(_effectBuffer1, rect, Color.White); // _batch.End(); } if (EnableShadowMask && Settings.EnableShadowMask) { SetShadowMaskParams(); // copy the intermediate RT to effect buffer 1 // with the shadowmask effect applied _gpu.SetRenderTarget(_effectBuffer1); // apply the shadowmask. _shadowmask.Apply(); // clear the effect buffer _gpu.Clear(Color.Black); // Bind the texture and prepare for a render _gpu.Textures[0] = _intermediate; _gpu.PrepareRender(); // Render _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); // End the render and bind the effect buffer after we switch to the immediate RT _gpu.EndRender(); _gpu.SetRenderTarget(null); _gpu.Textures[0] = _effectBuffer1; _gpu.SetRenderTarget(_intermediate); // Apply the default effect. _basicEffect.Programs.First().Apply(); // Start a render _gpu.PrepareRender(); // Render _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); // End. _gpu.EndRender(); _gpu.Textures[0] = null; _gpu.SetRenderTarget(null); } // Render the intermediate buffer to the screen. _basicEffect.Programs.First().Apply(); _gpu.SetRenderTarget(null); // Get the GPU ready for some rendering :P _gpu.PrepareRender(); _gpu.Textures[0] = _intermediate; _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); _gpu.EndRender(); _gpu.Textures[0] = null; }
private void PerformBloom(RenderTarget2D frame, Rectangle rect) { var hWidth = (float)rect.Width; var hHeight = (float)rect.Height; // change to the first effect buffer. _gpu.SetRenderTarget(_effectBuffer1); _gpu.Clear(Color.Black); // Apply the bloom threshold program. _brightnessThreshold.Parameters["threshold"].SetValue(_bloomThreshold); _brightnessThreshold.Apply(); // Prepare for a render. _gpu.PrepareRender(); _gpu.Textures[1] = frame; // Render the quad. _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); // End the render. _gpu.EndRender(); _gpu.Textures[1] = null; // Now we switch to Effect Buffer 2 so we can render the first blur pass. _gpu.SetRenderTarget(_effectBuffer2); _gpu.Clear(Color.Black); SetBlurOffsets(1.0f / hWidth, 0f); // Apply the blur shader. _gaussian.Apply(); // Prepare for a render. _gpu.PrepareRender(); _gpu.Textures[0] = _effectBuffer1; // Draw the quad. _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); // End the render. _gpu.EndRender(); _gpu.Textures[0] = null; // Switch to Effect Buffer 1 again and render the first blur pass with // an additional blur pass. _gpu.SetRenderTarget(_effectBuffer1); _gpu.Clear(Color.Black); SetBlurOffsets(0f, 1f / hHeight); // Start the render after setting Effect Buffer 2 as the texture to render. _gpu.Textures[0] = _effectBuffer2; _gpu.PrepareRender(); // Draw the quad. _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); // End the render. _gpu.EndRender(); _gpu.Textures[0] = null; _gpu.SetRenderTarget(null); // Now for the actual bloom effect. _gpu.SetRenderTarget(_effectBuffer2); _gpu.Clear(Color.Black); _gpu.Textures[0] = frame; _gpu.Textures[1] = _effectBuffer1; _bloom.Parameters["baseIntensity"].SetValue(_baseIntensity); _bloom.Parameters["baseSaturation"].SetValue(_baseSaturation); _bloom.Parameters["bloomIntensity"].SetValue(_bloomIntensity); _bloom.Parameters["bloomSaturation"].SetValue(_bloomSaturation); _bloom.Apply(); _gpu.PrepareRender(); _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); _gpu.EndRender(); _gpu.Textures[0] = null; _gpu.Textures[1] = null; // Render to our intermediate buffer. _gpu.SetRenderTarget(_intermediate); _gpu.Clear(Color.Black); _basicEffect.Programs.First().Apply(); _gpu.PrepareRender(BlendMode.Additive); _gpu.Textures[0] = _effectBuffer2; _gpu.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); _gpu.EndRender(); _gpu.Textures[0] = null; _gpu.SetRenderTarget(null); }