Skip to content

Commit

Permalink
Add Ribbon Particle
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed May 22, 2024
2 parents 67d1abd + c9db3b3 commit c1ffb47
Show file tree
Hide file tree
Showing 21 changed files with 486 additions and 260 deletions.
1 change: 1 addition & 0 deletions Engine/BuiltInShaders/UniformDefines/U_Particle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define PT_RIBBON_VERTEX_STAGE 1
32 changes: 32 additions & 0 deletions Engine/BuiltInShaders/shaders/cs_particleRibbon.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "../common/bgfx_compute.sh"
#include "../UniformDefines/U_Particle.sh"

BUFFER_RW(AllRibbonParticleVertex, vec4, PT_RIBBON_VERTEX_STAGE);

uniform vec4 u_ribbonCount;
// x : allRibbonVertexCount
// y : particleActiveCount

uniform vec4 u_ribbonMaxPos[300];
//here have max particle count (max limit of inspector)

NUM_THREADS(1u, 1u, 1u)
void main()
{
for(uint i = 0,index= 0; i <u_ribbonCount.x; i += 2,index++)
{
AllRibbonParticleVertex[i] = vec4(
u_ribbonMaxPos[index].x,
u_ribbonMaxPos[index].y + 1.0f,
u_ribbonMaxPos[index].z,
0.0f
);

AllRibbonParticleVertex[i+1] = vec4(
u_ribbonMaxPos[index].x,
u_ribbonMaxPos[index].y - 1.0f,
u_ribbonMaxPos[index].z,
0.0f
);
}
}
13 changes: 13 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_particleRibbon.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$input v_color0, v_texcoord0
#include "../common/common.sh"

SAMPLER2D(r_texColor, 1);

void main()
{
vec4 rgba = texture2D(r_texColor, v_texcoord0.xy);

rgba.xyz = rgba.xyz * v_color0.xyz;
rgba.w = rgba.w * v_color0.w;
gl_FragColor = rgba;
}
13 changes: 13 additions & 0 deletions Engine/BuiltInShaders/shaders/vs_particleRibbon.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$input a_position, a_color0, a_texcoord0

$output v_color0, v_texcoord0

#include "../common/common.sh"
uniform vec4 u_particleColor;

void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position,1.0));
v_color0 = a_color0 * u_particleColor;
v_texcoord0 = a_texcoord0;
}
5 changes: 3 additions & 2 deletions Engine/Source/Editor/ECWorld/ECWorldConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ void ECWorldConsumer::AddParticleEmitter(engine::Entity entity, const cd::Mesh&
engine::NameComponent& nameComponent = pWorld->CreateComponent<engine::NameComponent>(entity);
nameComponent.SetName(emitter.GetName());
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
auto& particleMaterialComponent = pWorld->CreateComponent<engine::MaterialComponent>(entity);
// TODO : Some initialization here.
auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
cd::Vec3f pos = emitter.GetPosition();
Expand Down Expand Up @@ -465,8 +466,8 @@ void ECWorldConsumer::AddParticleEmitter(engine::Entity entity, const cd::Mesh&
particleEmitterComponent.SetEmitterVelocity(emitter.GetVelocity());
particleEmitterComponent.SetEmitterAcceleration(emitter.GetAccelerate());
particleEmitterComponent.SetMeshData(&mesh);
particleEmitterComponent.SetMaterialType(pMaterialType);
particleEmitterComponent.ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
particleMaterialComponent.SetMaterialType(pMaterialType);
//particleMaterialComponent.ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
particleEmitterComponent.Build();
}

Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void EditorApp::InitMaterialType()
m_pRenderContext->RegisterShaderProgram("WorldProgram", "vs_PBR", "fs_PBR");
m_pRenderContext->RegisterShaderProgram("AnimationProgram", "vs_animation", "fs_animation");
m_pRenderContext->RegisterShaderProgram("TerrainProgram", "vs_terrain", "fs_terrain");
m_pRenderContext->RegisterShaderProgram("ParticleProgram", "vs_particle", "fs_particle");
m_pRenderContext->RegisterShaderProgram("ParticleProgram", "vs_particleSprite", "fs_particleSprite");
m_pRenderContext->RegisterShaderProgram("CelluloidProgram", "vs_celluloid", "fs_celluloid");

m_pSceneWorld = std::make_unique<engine::SceneWorld>();
Expand Down
10 changes: 6 additions & 4 deletions Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,18 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
{
engine::Entity entity = AddNamedEntity("ParticleEmitter");
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
auto& particleRibbonComponent = pWorld->CreateComponent<engine::ParticleRibbonComponent>(entity);
auto& particleMaterialComponent = pWorld->CreateComponent<engine::MaterialComponent>(entity);
// TODO : Some initialization here.
auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
transformComponent.SetTransform(cd::Transform::Identity());
transformComponent.Build();
particleEmitterComponent.SetRequiredVertexFormat(&pParticleMaterialType->GetRequiredVertexFormat());//to do : modify vertexFormat
particleEmitterComponent.SetMaterialType(pParticleMaterialType);
particleEmitterComponent.ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
particleMaterialComponent.Init();
particleMaterialComponent.SetMaterialType(pParticleMaterialType);
//particleMaterialComponent.ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
particleEmitterComponent.Build();
//auto& particleForceFieldComponent = pWorld->CreateComponent<engine::ParticleForceFieldComponent>(entity);
//particleForceFieldComponent.Build();
particleRibbonComponent.Build();
}
else if (ImGui::MenuItem("Add Particle ForceField"))
{
Expand Down
18 changes: 9 additions & 9 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ template<>
void UpdateComponentWidget<engine::ParticleEmitterComponent>(engine::SceneWorld* pSceneWorld, engine::Entity entity)
{
auto* pParticleEmitterComponent = pSceneWorld->GetParticleEmitterComponent(entity);
auto* pParticleMaterialComponent = pSceneWorld->GetMaterialComponent(entity);
if (!pParticleEmitterComponent)
{
return;
Expand All @@ -664,25 +665,24 @@ void UpdateComponentWidget<engine::ParticleEmitterComponent>(engine::SceneWorld*

if (isOpen)
{
ImGuiUtils::ImGuiEnumProperty("Render Mode", pParticleEmitterComponent->GetRenderMode());
ImGuiUtils::ImGuiEnumProperty("Render Mode(Work Type Sprite)", pParticleEmitterComponent->GetRenderMode());
ImGuiUtils::ImGuiEnumProperty("Particle Type", pParticleEmitterComponent->GetEmitterParticleType());
//ImGuiUtils::ImGuiEnumProperty("Emitter Shape", pParticleEmitterComponent->GetEmitterShape());
ImGuiUtils::ImGuiVectorProperty("Emitter Range", pParticleEmitterComponent->GetEmitterShapeRange());
ImGuiUtils::ImGuiBoolProperty("Random Emit Pos", pParticleEmitterComponent->GetRandomPosState());
ImGuiUtils::ImGuiIntProperty("Max Count", pParticleEmitterComponent->GetSpawnCount(), cd::Unit::None, 1, 300);
ImGuiUtils::ImGuiVectorProperty("Velocity", pParticleEmitterComponent->GetEmitterVelocity());
ImGuiUtils::ImGuiVectorProperty("Random Velocity", pParticleEmitterComponent->GetRandomVelocity());
ImGuiUtils::ImGuiBoolProperty("RandomVelocity", pParticleEmitterComponent->GetRandomVelocityState());
ImGuiUtils::ImGuiBoolProperty("RandomVelocity State", pParticleEmitterComponent->GetRandomVelocityState());
ImGuiUtils::ImGuiVectorProperty("Acceleration", pParticleEmitterComponent->GetEmitterAcceleration());
ImGuiUtils::ColorPickerProperty("Color", pParticleEmitterComponent->GetEmitterColor());
ImGuiUtils::ImGuiFloatProperty("LifeTime", pParticleEmitterComponent->GetLifeTime());
if (ImGuiUtils::ImGuiBoolProperty("Instance State", pParticleEmitterComponent->GetInstanceState()))
ImGuiUtils::ImGuiFloatProperty("LifeTime", pParticleEmitterComponent->GetLifeTime(),cd::Unit::None, 0, 6);
bool featureChanged = ImGuiUtils::ImGuiBoolProperty("Instance State(Work Type Sprite)", pParticleEmitterComponent->GetInstanceState());
if (featureChanged)
{
pParticleEmitterComponent->ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
}
else
{
pParticleEmitterComponent->DeactivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
pParticleEmitterComponent->GetInstanceState() ?
pParticleMaterialComponent->ActivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE) :
pParticleMaterialComponent->DeactivateShaderFeature(engine::ShaderFeature::PARTICLE_INSTANCE);
}
}

Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Runtime/ECWorld/AllComponentsHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
#include "ECWorld/TerrainComponent.h"
#include "ECWorld/TransformComponent.h"
#include "ECWorld/ParticleEmitterComponent.h"
#include "ECWorld/ParticleRibbonComponent.h"
#include "ECWorld/ParticleForceFieldComponent.h"
Loading

0 comments on commit c1ffb47

Please sign in to comment.