public void SimulateParticles(ParticleEmitterComponent component, ForcesComponent forces, TransformComponent transform) { if (component.IsEnabled) { this.SimulationEffect.Velocity = component.Velocity.ReadTarget; this.SimulationEffect.Position = component.Position.ReadTarget; this.SimulationEffect.InitialVelocity = component.InitialVelocity.ReadTarget; this.SimulationEffect.LengthScale = component.LengthScale; this.SimulationEffect.FieldSpeed = component.FieldSpeed; this.SimulationEffect.NoiseStrength = component.NoiseStrength; this.SimulationEffect.ProgressionRate = component.ProgressionRate; this.SimulationEffect.SpherePosition = component.SpherePosition; this.SimulationEffect.SphereRadius = component.SphereRadius; this.SimulationEffect.EmitterSize = component.Size; this.SimulationEffect.MaxLifeTime = component.MaxLifeTime; this.SimulationEffect.Elapsed = this.FrameService.Elapsed; this.SimulationEffect.Time = this.FrameService.Time; this.SimulationEffect.ParentVelocity = forces.Velocity; this.SimulationEffect.ObjectToWorld = transform.Matrix; this.SimulationEffect.WorldToObject = Matrix.Invert(transform.Matrix); this.SimulationEffect.ApplyParticleVelocitySimulationTechnique(); this.Device.SetRenderTarget(component.Velocity.WriteTarget); this.PostProcessTriangle.Render(this.Device); this.SimulationEffect.ApplyParticlePositionSimulationTechnique(); this.Device.SetRenderTargets(component.Position.WriteTarget, component.InitialVelocity.WriteTarget); this.PostProcessTriangle.Render(this.Device); component.Swap(); } }
private void ApplyShadowMapEffect(Matrix viewProjection, ParticleEmitterComponent emitter) { this.ShadowMapEffect.WorldViewProjection = viewProjection; this.ShadowMapEffect.Data = emitter.Position.ReadTarget; this.ShadowMapEffect.Apply(); }
public (ParticleEmitterComponent, TransformComponent, BoundingSphereComponent, ForcesComponent) Create(int paticleCount) { var entity = this.Entities.Create(); var particleEmitter = new ParticleEmitterComponent(entity, this.Device, paticleCount); var transform = new TransformComponent(entity); var bounds = new BoundingSphereComponent(entity, 1.0f); // Automatically adjusted by particle system var forces = new ForcesComponent(entity); this.Components.Add(particleEmitter, transform, bounds, forces); return(particleEmitter, transform, bounds, forces); }
private void ApplyGBufferEffect(PerspectiveCamera camera, ParticleEmitterComponent emitter) { this.GBufferEffect.View = camera.View; this.GBufferEffect.WorldViewProjection = camera.ViewProjection; this.GBufferEffect.Metalicness = emitter.Metalicness; this.GBufferEffect.Roughness = emitter.Roughness; this.GBufferEffect.Position = emitter.Position.ReadTarget; this.GBufferEffect.Velocity = emitter.Velocity.ReadTarget; this.GBufferEffect.SlowColor = emitter.SlowColor.ToVector3(); this.GBufferEffect.FastColor = emitter.FastColor.ToVector3(); this.GBufferEffect.ColorVelocityModifier = emitter.ColorVelocityModifier; this.GBufferEffect.Apply(); }
private static float ComputeBounds(ParticleEmitterComponent component) => Math.Max(component.Size, component.FieldSpeed * 2 * component.MaxLifeTime);
public void UpdateBounds(ParticleEmitterComponent component, BoundingSphereComponent bounds) { bounds.Radius = ComputeBounds(component); bounds.ChangeState.Change(); }