/// <summary> /// Drawing /// </summary> /// <param name="context">Context</param> public void Draw(DrawContext context) { var drawerMode = context.DrawerMode; if ((drawerMode.HasFlag(DrawerModes.OpaqueOnly) && !this.parameters.Transparent) || (drawerMode.HasFlag(DrawerModes.TransparentOnly) && this.parameters.Transparent)) { var effect = DrawerPool.EffectDefaultGPUParticles; #region Per frame update var state = new EffectParticleState { TotalTime = this.Emitter.TotalTime, ElapsedTime = this.Emitter.ElapsedTime, EmissionRate = this.Emitter.EmissionRate, VelocitySensitivity = this.parameters.EmitterVelocitySensitivity, HorizontalVelocity = this.parameters.HorizontalVelocity, VerticalVelocity = this.parameters.VerticalVelocity, RandomValues = Helper.RandomGenerator.NextVector4(Vector4.Zero, Vector4.One), MaxDuration = this.parameters.MaxDuration, MaxDurationRandomness = this.parameters.MaxDurationRandomness, EndVelocity = this.parameters.EndVelocity, Gravity = this.parameters.Gravity, StartSize = this.parameters.StartSize, EndSize = this.parameters.EndSize, MinColor = this.parameters.MinColor, MaxColor = this.parameters.MaxColor, RotateSpeed = this.parameters.RotateSpeed, }; effect.UpdatePerFrame( context.ViewProjection, context.EyePosition, state, this.TextureCount, this.Texture); #endregion this.StreamOut(effect); this.ToggleBuffers(); this.Draw(effect, context.DrawerMode); } }
/// <summary> /// Draw particles /// </summary> /// <param name="context">Context</param> public void Draw(DrawContext context) { if (this.ActiveParticles <= 0) { return; } var mode = context.DrawerMode; var draw = (mode.HasFlag(DrawerModes.ShadowMap)) || (mode.HasFlag(DrawerModes.OpaqueOnly) && !this.parameters.Transparent) || (mode.HasFlag(DrawerModes.TransparentOnly) && this.parameters.Transparent); if (!draw) { return; } var rot = this.parameters.RotateSpeed != Vector2.Zero; var effect = DrawerPool.EffectDefaultCPUParticles; var technique = rot ? effect.RotationDraw : effect.NonRotationDraw; if (!mode.HasFlag(DrawerModes.ShadowMap)) { Counters.InstancesPerFrame++; Counters.PrimitivesPerFrame += this.ActiveParticles; } var graphics = this.Game.Graphics; graphics.IASetVertexBuffers(BufferSlot, this.buffer.VertexBufferBinding); graphics.IAInputLayout = rot ? this.buffer.InputLayouts[0] : this.buffer.InputLayouts[1]; graphics.IAPrimitiveTopology = PrimitiveTopology.PointList; graphics.SetDepthStencilRDZEnabled(); if (this.parameters.Additive) { graphics.SetBlendAdditive(); } else if (this.parameters.Transparent) { graphics.SetBlendDefaultAlpha(); } else { graphics.SetBlendDefault(); } var state = new EffectParticleState { TotalTime = this.Emitter.TotalTime, MaxDuration = this.parameters.MaxDuration, MaxDurationRandomness = this.parameters.MaxDurationRandomness, EndVelocity = this.parameters.EndVelocity, Gravity = this.parameters.Gravity, StartSize = this.parameters.StartSize, EndSize = this.parameters.EndSize, MinColor = this.parameters.MinColor, MaxColor = this.parameters.MaxColor, RotateSpeed = this.parameters.RotateSpeed, }; effect.UpdatePerFrame( context.ViewProjection, context.EyePosition, state, this.TextureCount, this.Texture); for (int p = 0; p < technique.PassCount; p++) { graphics.EffectPassApply(technique, p, 0); graphics.Draw(this.ActiveParticles, 0); } }