diff --git a/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp b/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp index fd711c44..a0fad067 100644 --- a/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp +++ b/Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp @@ -38,10 +38,10 @@ void engine::ParticleSystem::Reset(int index) { m_pos[index] = cd::Vec3f(0.0f, 0.0f, 0.0f); - m_velocity[index] = cd::Vec3f(1.0f, 1.0f, 1.0f); - m_acceleration[index] = cd::Vec3f(1.0f, 0.0f, 0.0f); + m_velocity[index] = cd::Vec3f(rand()%3, rand()%3, 0.0f); + m_acceleration[index] = cd::Vec3f(0.0f, 0.0f, 0.0f); - m_color[index] = cd::Vec3f{0.0f, 0.0f,1.0f}; + m_color[index] = cd::Vec3f{1.0f, 1.0f,1.0f}; m_isActive[index] = false; m_currentTime[index] = 0.0f; @@ -61,29 +61,29 @@ void engine::ParticleSystem::Update(float deltaTime, int index) { m_pos[index].x() = m_pos[index].x() + m_velocity[index].x() * 0.15f + 0.5f * m_acceleration[index].x() * 0.15f * 0.15f; m_pos[index].y() = m_pos[index].y() + m_velocity[index].y() * 0.15f + 0.5f * m_acceleration[index].y() * 0.15f * 0.15f; - m_texture_u[index] = 0.0f; - m_texture_v[index] = 0.0f; + m_texture_u[index] = 1.0f; + m_texture_v[index] = 1.0f; } else if (index % 4 == 1) { - m_pos[index].x() = m_pos[index-1].x()+ 1 + m_velocity[index].x() * 0.15f + 0.5f * m_acceleration[index].x() * 0.15f * 0.15f; - m_pos[index].y() = m_pos[index-1].y() + m_velocity[index].y() * 0.15f + 0.5f * m_acceleration[index].y() * 0.15f * 0.15f; - m_texture_u[index] = 1.0f; - m_texture_v[index] = 0.0f; + m_pos[index].x() = m_pos[index-1].x()+ 1 ; + m_pos[index].y() = m_pos[index-1].y() ; + m_texture_u[index] = 0.0f; + m_texture_v[index] = 1.0f; } else if (index % 4 == 2) { - m_pos[index].x() = m_pos[index-2].x() + 1+ m_velocity[index].x() * 0.15f + 0.5f * m_acceleration[index].x() * 0.15f * 0.15f; - m_pos[index].y() = m_pos[index-2].y() + 1 + m_velocity[index].y() * 0.15f + 0.5f * m_acceleration[index].y() * 0.15f * 0.15f; - m_texture_u[index] = 1.0f; - m_texture_v[index] = 1.0f; + m_pos[index].x() = m_pos[index-2].x() + 1; + m_pos[index].y() = m_pos[index-2].y() + 1; + m_texture_u[index] = 0.0f; + m_texture_v[index] = 0.0f; } else if (index % 4 == 3) { - m_pos[index].x() = m_pos[index-3].x() + m_velocity[index].x() * 0.15f + 0.5f * m_acceleration[index].x() * 0.15f * 0.15f; - m_pos[index].y() = m_pos[index-3].y() + 1 + m_velocity[index].y() * 0.15f + 0.5f * m_acceleration[index].y() * 0.15f * 0.15f; - m_texture_u[index] = 0.0f; - m_texture_v[index] = 1.0f; + m_pos[index].x() = m_pos[index-3].x(); + m_pos[index].y() = m_pos[index-3].y() + 1 ; + m_texture_u[index] = 1.0f; + m_texture_v[index] = 0.0f; } for (int i = index; i < m_particleMaxCount; ++i) diff --git a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp index 49a1a3a5..c5b6aaff 100644 --- a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp @@ -49,58 +49,6 @@ void ParticleRenderer::Render(float deltaTime) constexpr StringCrc ParticleProgram("ParticleProgram"); bgfx::submit(GetViewID(), GetRenderContext()->GetProgram(ParticleProgram)); } - // engine::ParticleEmitterComponent* pEmitterComponent = m_pCurrentSceneWorld->GetParticleEmitterComponent(entity); - // const cd::Transform& transform = m_pCurrentSceneWorld->GetTransformComponent(entity)->GetTransform(); - // pEmitterComponent->init(); - // int particleindex = pEmitterComponent->allocateParticleIndex(); - // ParticleComponent& particle = pEmitterComponent->getParticle(particleindex); - // if (pEmitterComponent->allocateParticleIndex() != -1) - // { - // particle.setPos(transform.GetTranslation()); - // particle.setVelocity(cd::Vec3f(-0.02f + rand() % 4100, 0.0f, 0.0f)); - // particle.setAcceleration(cd::Vec3f(0.0f, 0.0f, 0.0f)); - // particle.setColor(cd::Vec3f(1.0f, 0.0f, 0.0f)); - // particle.setLifeTime(1.0f + rand() % 7); - // } - - // pEmitterComponent->update(1.0f / deltaTime); - - // cd::VertexFormat vertexFormat; - // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Position, cd::AttributeValueType::Float, 3); - // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Color, cd::AttributeValueType::Float, 3); - - // bgfx::VertexLayout vertexLayout; - // VertexLayoutUtility::CreateVertexLayout(vertexLayout, vertexFormat.GetVertexLayout()); - - // //vertex - // pEmitterComponent->GetVertexBuffer().resize(2*sizeof(cd::Vec3f)); - - - // std::memcpy(pEmitterComponent->GetVertexBuffer().data(), &particle.getPos(), sizeof(cd::Vec3f)); - // std::memcpy(pEmitterComponent->GetVertexBuffer().data()+sizeof(cd::Vec3f), &particle.getColor(), sizeof(cd::Vec3f)); - - - // //index - ///* std::vector indices = { 0, 1 }; - // emitter->GetIndexBuffer().resize(2*sizeof(uint16_t)); - // std::memcpy(emitter->GetIndexBuffer().data(), indices.data(), sizeof(indices));*/ - - - // pEmitterComponent->setParticleVBH(bgfx::createVertexBuffer(bgfx::makeRef(pEmitterComponent->GetVertexBuffer().data(), static_cast(pEmitterComponent->GetVertexBuffer().size())), vertexLayout).idx); - // //emitter->setParticleIBH( bgfx::createIndexBuffer(bgfx::makeRef(emitter->GetIndexBuffer().data(), static_cast(emitter->GetIndexBuffer().size())),0U).idx); - - // bgfx::setVertexBuffer(0, bgfx::VertexBufferHandle{ pEmitterComponent->getParticleVBH() }); - //// bgfx::setIndexBuffer(bgfx::IndexBufferHandle{ emitter->getParticleIBH() }); - - // constexpr uint64_t state = BGFX_STATE_WRITE_MASK | BGFX_STATE_MSAA | BGFX_STATE_DEPTH_TEST_LESS | - // BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) | BGFX_STATE_PT_POINTS; - - // bgfx::setState(state); - - // constexpr StringCrc ParticleProgram("ParticleProgram"); - // bgfx::submit(GetViewID(), GetRenderContext()->GetProgram(ParticleProgram)); - // - //const cd::Transform& cameraTransform = m_pCurrentSceneWorld->GetTransformComponent(m_pCurrentSceneWorld->GetMainCameraEntity())->GetTransform(); } } \ No newline at end of file