public override void ComputeProperties(ParticlePool pool, ParticleBufferAccessor bufferAccessor) { foreach (var i in pool.AliveParticles) { var size = bufferAccessor.Size; float fade = Interpolation.ValueAt(pool.Particles[i].Phase, Start, End, 0.0f, 1.0f, Easing); size *= fade; bufferAccessor.Size = size; bufferAccessor.Index++; } }
protected override void ApplyDrawNode(DrawNode3D node) { base.ApplyDrawNode(node); var n = (ParticleSystemDrawNode)node; n.Shader = shader; n.Texture = Texture; n.Pool = pool; n.InverseViewMatrix = Scene.Camera.InverseViewMatrix; if (gpuBuffer == null) { gpuBuffer = new BufferTextureGL(); } n.Buffer = gpuBuffer; // Create data as matrices // TODO: Reuse array n.BufferData = new float[ParticleBufferAccessor.ParticleStride * pool.AliveParticles.Count]; using (ParticleBufferAccessor bufferAccessor = new ParticleBufferAccessor(n.BufferData)) { // Write base properties // TODO: Detect which properties have computed variant and skip those here bufferAccessor.Index = 0; foreach (var i in pool.AliveParticles) { bufferAccessor.Position = pool.Particles[i].Position; bufferAccessor.Rotation = pool.Particles[i].Rotation; bufferAccessor.Colour = pool.Particles[i].Colour; bufferAccessor.Size = pool.Particles[i].Size; bufferAccessor.Index++; } // Write custom properties foreach (var property in ComputedProperties) { bufferAccessor.Index = 0; property.ComputeProperties(pool, bufferAccessor); } } n.InstanceCount = pool.AliveParticles.Count; UpdateParticles(); }
/// <summary> /// Compute particle properties based on their phase /// </summary> /// <param name="pool">Pool of particles to process</param> /// <param name="bufferAccessor">RenderData that receives the properties, the accessor will be reset to 0</param> public abstract void ComputeProperties(ParticlePool pool, ParticleBufferAccessor bufferAccessor);