Skip to content
Permalink
Browse files

[Render] Decouple RenderParticleEmitter from ECS

  • Loading branch information
xen2 committed Feb 7, 2019
1 parent 805453e commit abfb0060a4405fe5712bcb57e657e2f3715436a5
@@ -31,13 +31,7 @@ public sealed class ParticleSystemComponent : ActivableEntityComponent
/// </userdoc>
[DataMember(10)]
[Display("Source")]
public ParticleSystem ParticleSystem
{
get
{
return particleSystem;
}
}
public ParticleSystem ParticleSystem => particleSystem;

~ParticleSystemComponent()
{
@@ -163,7 +163,7 @@ public override unsafe void Prepare(RenderDrawContext context)

// TODO: ParticleMaterial should set this up
var materialInfo = (ParticleMaterialInfo)renderParticleEmitter.ParticleMaterialInfo;
var colorShade = renderParticleEmitter.RenderParticleSystem.ParticleSystemComponent.Color.ToColorSpace(context.GraphicsDevice.ColorSpace);
var colorShade = renderParticleEmitter.Color.ToColorSpace(context.GraphicsDevice.ColorSpace);
materialInfo?.Material.Parameters.Set(ParticleBaseKeys.ColorScale, colorShade);
}

@@ -30,10 +30,10 @@ private void CheckEmitters(RenderParticleSystem renderParticleSystem)
if (renderParticleSystem == null)
return;

var emitters = renderParticleSystem.ParticleSystemComponent.ParticleSystem.Emitters;
var emitters = renderParticleSystem.ParticleSystem.Emitters;

var emitterCount = 0;
if (renderParticleSystem.ParticleSystemComponent.ParticleSystem.Enabled)
if (renderParticleSystem.ParticleSystem.Enabled)
{
foreach (var particleEmitter in emitters)
{
@@ -86,20 +86,21 @@ public override void Draw(RenderContext context)
{
foreach (var componentData in ComponentDatas)
{
var particleSystemComponent = componentData.Key;
var renderSystem = componentData.Value;

CheckEmitters(renderSystem);


// Update render objects
foreach (var emitter in renderSystem.Emitters)
{
if ((emitter.Enabled = renderSystem.ParticleSystemComponent.Enabled) == true)
if ((emitter.Enabled = particleSystemComponent.Enabled) == true)
{
var aabb = emitter.RenderParticleSystem.ParticleSystemComponent.ParticleSystem.GetAABB();
var aabb = emitter.RenderParticleSystem.ParticleSystem.GetAABB();
emitter.BoundingBox = new BoundingBoxExt(aabb.Minimum, aabb.Maximum);
emitter.StateSortKey = ((uint) emitter.ParticleEmitter.DrawPriority) << 16; // Maybe include the RenderStage precision as well
emitter.RenderGroup = renderSystem.ParticleSystemComponent.RenderGroup;
emitter.Color = particleSystemComponent.Color;
emitter.RenderGroup = particleSystemComponent.RenderGroup;
}
}
}
@@ -139,16 +140,13 @@ protected override RenderParticleSystem GenerateComponentData(Entity entity, Par
{
return new RenderParticleSystem
{
ParticleSystemComponent = particleSystemComponent,
TransformComponent = entity.Transform,
ParticleSystem = particleSystemComponent.ParticleSystem,
};
}

protected override bool IsAssociatedDataValid(Entity entity, ParticleSystemComponent spriteComponent, RenderParticleSystem associatedData)
{
return
spriteComponent == associatedData.ParticleSystemComponent &&
entity.Transform == associatedData.TransformComponent;
return true;
}
}
}
@@ -1,6 +1,7 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Xenko.Core.Mathematics;
using Xenko.Graphics;
using Xenko.Rendering;

@@ -16,6 +17,8 @@ public class RenderParticleEmitter : RenderObject
public ParticleEmitter ParticleEmitter;
internal ParticleEmitterRenderFeature.ParticleMaterialInfo ParticleMaterialInfo;

public Color4 Color;

public bool HasVertexBufferChanged;
public int VertexSize;
public int VertexCount;
@@ -11,9 +11,7 @@ namespace Xenko.Particles.Rendering
/// </summary>
public class RenderParticleSystem
{
public ParticleSystemComponent ParticleSystemComponent;

public TransformComponent TransformComponent;
public ParticleSystem ParticleSystem;

public RenderParticleEmitter[] Emitters;
}

0 comments on commit abfb006

Please sign in to comment.
You can’t perform that action at this time.