public void Draw(RenderTarget2D rt, Texture2D spriteTexture, Vector2 MousePosition, int Scale, float Spring, float Dampening) { InitializeParameters(); if (!_effectLoaded) { return; } if (_scale != Scale) { _scale = Scale; CreateParticles(Scale); } SpringConstant = Spring; DampeningConstant = Dampening; _graphicsDevice.BlendState = BlendState.Opaque; _mousePositionParameter.SetValue(MousePosition); Sprite = spriteTexture; //Physics _graphicsDevice.SetRenderTarget(offframe ? _textureBufferB : _textureBufferA); _texBufferParameter.SetValue(offframe ? _textureBufferA : _textureBufferB); _physicsPass.Apply(); _fsqRenderer.RenderFullscreenQuad(_graphicsDevice); //Vector4[] v4 = new Vector4[1]; //_textureBufferA.GetData(v4); //DebugScreen.AddString(v4[0].ToString()); _graphicsDevice.SetRenderTarget(rt); //1280 800 _graphicsDevice.Clear(Color.Black); _graphicsDevice.BlendState = BlendState.Additive; _texBufferParameter.SetValue(offframe ? _textureBufferB : _textureBufferA); _graphicsDevice.SetVertexBuffer(_vertexBuffer); _graphicsDevice.Indices = _indexBuffer; _defaultPass.Apply(); _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _primitiveCount); offframe = !offframe; }
public void Draw(GraphicsDevice graphics, int width, int height, List <AiShip> ships, PlayerShip playerShip) { if (_renderTarget0 == null || _renderTarget0.Width != width || _renderTarget0.Height != height) { _renderTarget0?.Dispose(); _renderTarget1?.Dispose(); _renderTarget0 = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); _renderTarget1 = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); //Clear graphics.SetRenderTarget(_renderTarget0); graphics.Clear(Color.Black); graphics.SetRenderTarget(_renderTarget1); graphics.Clear(Color.Black); } _offframe = !_offframe; graphics.SetRenderTarget(_offframe ? _renderTarget1 : _renderTarget0); //Initialize if (_positions == null) { _positions = new Vector2[ships.Count + 1]; _lastPositions = new Vector2[ships.Count + 1]; _colors = new Vector3[ships.Count + 1]; //Ai ships for (var index = 0; index < ships.Count; index++) { AiShip ship = ships[index]; _colors[index] = ship.ColorV3; _lastPositions[index] = ship.Position; _positions[index] = ship.Position; } //Player ship _colors[ships.Count] = Vector3.One; _lastPositions[ships.Count] = playerShip.Position; _positions[ships.Count] = playerShip.Position; } for (var index = 0; index < ships.Count; index++) { AiShip ship = ships[index]; if (Vector2.DistanceSquared(ship.Position, _lastPositions[index]) > 49) { _lastPositions[index] = _positions[index]; _positions[index] = ship.Position; } } if (Vector2.DistanceSquared(playerShip.Position, _lastPositions[ships.Count]) > 49) { _lastPositions[ships.Count] = _positions[ships.Count]; _positions[ships.Count] = playerShip.Position; } //Colors[0] = Vector3.One; //Positions[0] = Mouse.GetState().Position.ToVector2(); _positionsParam.SetValue(_positions); _lastPositionsParam.SetValue(_lastPositions); _colorsParam.SetValue(_colors); _texParam.SetValue(_offframe ? _renderTarget0 : _renderTarget1); graphics.BlendState = BlendState.Opaque; _trailPass.Apply(); _fsq.RenderFullscreenQuad(graphics); }