diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp index 2e03860da..a08be5951 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp @@ -409,13 +409,11 @@ void ParticleEmitterGraphCPUExecutor::Draw(ParticleEmitter* emitter, ParticleEff const float radius = (float)GetValue(module->GetBox(1), 3); const float fallOffExponent = (float)GetValue(module->GetBox(2), 4); - lightData.Position = *(Float3*)positionPtr; lightData.Color = Float3(color) * color.W; lightData.Radius = radius; lightData.FallOffExponent = fallOffExponent; - if (emitter->SimulationSpace == ParticlesSimulationSpace::Local) - Float3::Transform(lightData.Position, transform, lightData.Position); + Float3::Transform(*(Float3*)positionPtr, transform, lightData.Position); renderContext.List->PointLights.Add(lightData); diff --git a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp index d86acab5d..a5e9948f5 100644 --- a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp +++ b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp @@ -231,7 +231,11 @@ void GPUParticles::Execute(GPUContext* context, ParticleEmitter* emitter, Partic else { Matrix worldMatrix; - effect->GetWorld(&worldMatrix); + const Transform transform = effect->GetTransform(); + if (viewTask) + viewTask->View.GetWorldMatrix(transform, worldMatrix); + else + transform.GetWorld(worldMatrix); Matrix::Transpose(worldMatrix, cbData->WorldMatrix); worldMatrix.Invert(); Matrix::Transpose(worldMatrix, cbData->InvWorldMatrix); diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 7b6f6ff93..4c5347ca6 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -14,8 +14,8 @@ ParticleEffect::ParticleEffect(const SpawnParams& params) , _lastUpdateFrame(0) , _lastMinDstSqr(MAX_Real) { - _world = Matrix::Identity; - UpdateBounds(); + _box = BoundingBox(_transform.Translation); + BoundingSphere::FromBox(_box, _sphere); ParticleSystem.Changed.Bind(this); ParticleSystem.Loaded.Bind(this); @@ -295,7 +295,7 @@ void ParticleEffect::UpdateBounds() if (emitter->SimulationSpace == ParticlesSimulationSpace::Local) { - BoundingBox::Transform(emitterBounds, _world, emitterBounds); + BoundingBox::Transform(emitterBounds, _transform, emitterBounds); } BoundingBox::Merge(emitterBounds, bounds, bounds); @@ -737,6 +737,5 @@ void ParticleEffect::OnTransformChanged() // Base Actor::OnTransformChanged(); - _transform.GetWorld(_world); UpdateBounds(); } diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index aea57360c..c71775ff7 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -179,7 +179,6 @@ public: private: uint64 _lastUpdateFrame; Real _lastMinDstSqr; - Matrix _world; int32 _sceneRenderingKey = -1; uint32 _parametersVersion = 0; // Version number for _parameters to be in sync with Instance.ParametersVersion Array _parameters; // Cached for scripting API @@ -246,15 +245,6 @@ public: API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), EditorOrder(75), DefaultValue(DrawPass.Default)") DrawPass DrawModes = DrawPass::Default; - /// - /// Gets the actor world matrix transform. - /// - /// Result world matrix - FORCE_INLINE void GetWorld(Matrix* world) const - { - *world = _world; - } - public: /// /// Gets the effect parameters collection. Those parameters are instanced from the that contains a linear list of emitters and every emitter has a list of own parameters. diff --git a/Source/Engine/Particles/ParticleSystem.cpp b/Source/Engine/Particles/ParticleSystem.cpp index 745bca545..39f72abb5 100644 --- a/Source/Engine/Particles/ParticleSystem.cpp +++ b/Source/Engine/Particles/ParticleSystem.cpp @@ -362,7 +362,7 @@ Asset::LoadResult ParticleSystem::load() continue; #endif - EmittersParametersOverrides.Add(key, Variant(value)); + EmittersParametersOverrides[key] = Variant(value); } } @@ -441,7 +441,7 @@ Asset::LoadResult ParticleSystem::load() continue; #endif - EmittersParametersOverrides.Add(key, value); + EmittersParametersOverrides[key] = value; } } diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index 306adee02..042eaa7d8 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -877,8 +877,9 @@ void Particles::DrawParticles(RenderContext& renderContext, ParticleEffect* effe const auto drawModes = static_cast(view.Pass & effect->DrawModes); if (drawModes == DrawPass::None || SpriteRenderer.Init()) return; - Matrix world; - effect->GetWorld(&world); + Matrix worlds[2]; + Matrix::Translation(-renderContext.View.Origin, worlds[0]); // World + renderContext.View.GetWorldMatrix(effect->GetTransform(), worlds[1]); // Local const auto staticFlags = effect->GetStaticFlags(); // Draw lights @@ -888,14 +889,15 @@ void Particles::DrawParticles(RenderContext& renderContext, ParticleEffect* effe const auto buffer = emitterData.Buffer; if (!buffer || (buffer->Mode == ParticlesSimulationMode::CPU && buffer->CPU.Count == 0)) continue; + auto emitter = buffer->Emitter; - buffer->Emitter->GraphExecutorCPU.Draw(buffer->Emitter, effect, emitterData, renderContext, world); + buffer->Emitter->GraphExecutorCPU.Draw(buffer->Emitter, effect, emitterData, renderContext, worlds[(int32)emitter->SimulationSpace]); } // Setup a draw call common data DrawCall drawCall; drawCall.PerInstanceRandom = effect->GetPerInstanceRandom(); - drawCall.ObjectPosition = world.GetTranslation(); + drawCall.ObjectPosition = effect->GetPosition(); // Draw all emitters for (int32 emitterIndex = 0; emitterIndex < effect->Instance.Emitters.Count(); emitterIndex++) @@ -906,7 +908,7 @@ void Particles::DrawParticles(RenderContext& renderContext, ParticleEffect* effe continue; auto emitter = buffer->Emitter; - drawCall.World = emitter->SimulationSpace == ParticlesSimulationSpace::World ? Matrix::Identity : world; + drawCall.World = worlds[(int32)emitter->SimulationSpace]; drawCall.WorldDeterminantSign = Math::FloatSelect(drawCall.World.RotDeterminant(), 1, -1); drawCall.Particle.Particles = buffer;