Skip to content

Commit

Permalink
shader forgeted
Browse files Browse the repository at this point in the history
  • Loading branch information
OVOAOVO committed Sep 16, 2023
1 parent 08da43d commit d710339
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$input v_color0
#include "../common/common.sh"


void main()
{
gl_FragColor = float4(v_color0.rgb,1.0f);
}
10 changes: 10 additions & 0 deletions Engine/BuiltInShaders/shaders/vs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$input a_position, a_color0
$output v_color0

#include "../common/common.sh"

void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
v_color0 = a_color0;
}
5 changes: 4 additions & 1 deletion Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
engine::Entity entity = AddNamedEntity("ParticleEmitter");
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
// TODO : Some initialization here.

auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
transformComponent.SetTransform(cd::Transform::Identity());
transformComponent.Build();
engine::ParticleSystem particles;
particles.Init();
particleEmitterComponent.SetParticleSystem(particles);

}
}

Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ void Inspector::Update()
details::UpdateComponentWidget<engine::SkyComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::TerrainComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ShaderVariantCollectionsComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ParticleEmitterComponent>(pSceneWorld, selectedEntity);

#ifdef ENABLE_DDGI
details::UpdateComponentWidget<engine::DDGIComponent>(pSceneWorld, selectedEntity);
Expand Down
6 changes: 2 additions & 4 deletions Engine/Source/Runtime/ECWorld/ParticleEmitterComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ void engine::ParticleEmitterComponent::Build()
* indexBuffer
*/
size_t indexTypeSize = sizeof(uint16_t);
m_particleIndexBuffer.resize(3 * m_particleSystem.GetMaxCount() * indexTypeSize);
m_particleIndexBuffer.resize(m_particleSystem.GetMaxCount() * indexTypeSize);
currentDataSize = 0U;
currentDataPtr = m_particleIndexBuffer.data();

std::vector<uint16_t> indexes;
for (uint16_t i = 0; i < m_particleSystem.GetMaxCount(); i++)
{
uint16_t vertexIndex = static_cast<uint16_t>(i * 3);
uint16_t vertexIndex = static_cast<uint16_t>(i);
indexes.push_back(vertexIndex);
indexes.push_back(vertexIndex + 1);
indexes.push_back(vertexIndex + 2);
}

for (const auto& index : indexes)
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Runtime/ParticleSystem/ParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void engine::ParticleSystem::AllocateParticleIndex()
void engine::ParticleSystem::Reset(int index)
{
m_pos[index] = cd::Vec3f(0.0f, 0.0f, 0.0f);
m_velocity[index] = cd::Vec3f(rand() % 41, rand() % 7, rand() % 50);
m_velocity[index] = cd::Vec3f(rand()%64, rand() % 4, rand() % 80);
m_acceleration[index] = cd::Vec3f(0.0f, 0.0f, 0.0f);

m_color[index] = cd::Vec3f{rand() %30, rand() %45,0.0f};
m_color[index] = cd::Vec3f{1.0f, 0.0f,0.0f};

m_isActive[index] = false;
m_currentTime[index] = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Runtime/Rendering/AABBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void AABBRenderer::RenderAll(float deltaTime)
bgfx::setIndexBuffer(bgfx::IndexBufferHandle{ pCollisionMesh->GetIndexBuffer() });

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_LINES;
BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) | BGFX_STATE_PT_TRISTRIP;
bgfx::setState(state);

constexpr StringCrc AABBAllProgram("AABBProgram");
Expand Down
8 changes: 6 additions & 2 deletions Engine/Source/Runtime/Rendering/ParticleRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ void ParticleRenderer::Render(float deltaTime)
for (Entity entity : m_pCurrentSceneWorld->GetParticleEmitterEntities())
{
engine::ParticleEmitterComponent* pEmitterComponent = m_pCurrentSceneWorld->GetParticleEmitterComponent(entity);

for (int i = 0; i < pEmitterComponent->GetParticleSystem().GetMaxCount(); ++i)
{
pEmitterComponent->GetParticleSystem().AllocateParticleIndex();
pEmitterComponent->GetParticleSystem().UpdateActive(1 / deltaTime);
}
pEmitterComponent->GetParticleSystem().UpdateActive(deltaTime);

pEmitterComponent->Build();
bgfx::setVertexBuffer(0, bgfx::VertexBufferHandle{ pEmitterComponent->GetParticleVBH() });
bgfx::setIndexBuffer(bgfx::IndexBufferHandle{ pEmitterComponent->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_LINES;
BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) | BGFX_STATE_PT_TRISTRIP;
bgfx::setState(state);

constexpr StringCrc ParticleProgram("ParticleProgram");
Expand Down

0 comments on commit d710339

Please sign in to comment.