Skip to content

Commit

Permalink
#102 Update particle sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 9, 2020
1 parent d6fc518 commit 1a0491e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureLinearRGBFS.d.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ out vec4 FragColor;

void main(void)
{
vec4 result = texture(uTexDiffuse, varTexCoord0.xy);
FragColor = vec4(linearRGB(result.rgb) * varColor.rgb, result.a * varColor.a);
vec4 texColor = texture(uTexDiffuse, varTexCoord0.xy);
FragColor = vec4(linearRGB(texColor.rgb) * varColor.rgb, texColor.a * varColor.a);
}
4 changes: 2 additions & 2 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureLinearRGBFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ vec3 linearRGB(vec3 color)
}
void main(void)
{
vec4 result = texture(uTexDiffuse, varTexCoord0.xy);
FragColor = vec4(linearRGB(result.rgb) * varColor.rgb, result.a * varColor.a);
vec4 texColor = texture(uTexDiffuse, varTexCoord0.xy);
FragColor = vec4(linearRGB(texColor.rgb) * varColor.rgb, texColor.a * varColor.a);
}
4 changes: 2 additions & 2 deletions Assets/BuiltIn/Shader/Basic/HLSL/TextureLinearRGBFS.d.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ struct PS_INPUT

float4 main(PS_INPUT input) : SV_TARGET
{
float4 result = uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0);
return float4(input.color.rgb * linearRGB(result.rgb), result.a * input.color.a);
float4 texColor = uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0);
return float4(input.color.rgb * linearRGB(texColor.rgb), texColor.a * input.color.a);
}
4 changes: 2 additions & 2 deletions Assets/BuiltIn/Shader/Basic/HLSL/TextureLinearRGBFS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ float3 linearRGB(float3 color)
}
float4 main(PS_INPUT input) : SV_TARGET
{
float4 result = uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0);
return float4(input.color.rgb * linearRGB(result.rgb), result.a * input.color.a);
float4 texColor = uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0);
return float4(input.color.rgb * linearRGB(texColor.rgb), texColor.a * input.color.a);
}
8 changes: 4 additions & 4 deletions Samples/Particles/Source/SampleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void SampleParticles::onGUIZoneNode(int currentZone)
ImGui::SliderFloat("Radius", &r, minSize, maxSize, "r = %.3f");
ImGui::SliderFloat("Length", &l, minSize, maxSize, "l = %.3f");

core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction", "%.3f");
core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction rotate", "%.3f");

if (!core::equals(lastRadius, r) ||
!core::equals(lastLength, l) ||
Expand Down Expand Up @@ -714,7 +714,7 @@ void SampleParticles::onGUIEmitterNode(int currentEmitter)
static float rx = 0.0f;
static float ry = 0.0f;
static float rz = 0.0f;
core::vector3df direction = imguiDirection(-CTransform::s_oy, rx, ry, rz, "Direction", "%.3f");
core::vector3df direction = imguiDirection(-CTransform::s_oy, rx, ry, rz, "Direction rotate", "%.3f");

group->Gravity = direction * gravityValue;

Expand Down Expand Up @@ -747,7 +747,7 @@ void SampleParticles::onGUIEmitterNode(int currentEmitter)
static float rx = 0.0f;
static float ry = 0.0f;
static float rz = 0.0f;
core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction", "%.3f");
core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction rotate", "%.3f");
e->setDirection(direction);

ImGui::TreePop();
Expand All @@ -763,7 +763,7 @@ void SampleParticles::onGUIEmitterNode(int currentEmitter)
static float rx = 0.0f;
static float ry = 0.0f;
static float rz = 0.0f;
core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction", "%.3f");
core::vector3df direction = imguiDirection(CTransform::s_oy, rx, ry, rz, "Direction rotate", "%.3f");
e->setDirection(direction);

float angleMin = core::radToDeg(e->getAngleA());
Expand Down
49 changes: 48 additions & 1 deletion Samples/ParticlesExplosion/Source/SampleParticlesExplosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ void installApplication(const std::vector<std::string>& argv)
}

SampleParticlesExplosion::SampleParticlesExplosion() :
m_scene(NULL)
m_scene(NULL),
m_forwardRP(NULL),
m_postProcessorRP(NULL)
{
CImguiManager::createGetInstance();

Expand All @@ -27,6 +29,9 @@ SampleParticlesExplosion::~SampleParticlesExplosion()

delete m_scene;
CImguiManager::releaseInstance();

delete m_forwardRP;
delete m_postProcessorRP;
}

void SampleParticlesExplosion::onInitApp()
Expand Down Expand Up @@ -101,6 +106,11 @@ void SampleParticlesExplosion::onInitApp()

m_forwardRP = new CForwardRP();
m_forwardRP->initRender(w, h);

m_postProcessorRP = new CPostProcessorRP();
m_postProcessorRP->enableBloomEffect(true);
m_postProcessorRP->initRender(w, h);
m_forwardRP->setPostProcessor(m_postProcessorRP);
}

bool SampleParticlesExplosion::OnEvent(const SEvent& event)
Expand Down Expand Up @@ -222,6 +232,43 @@ void SampleParticlesExplosion::initFireSystem(Particle::CParticleComponent *ps)
fireGroup->addEmitter(fireEmitter4);
fireGroup->addEmitter(fireEmitter5);
fireGroup->addEmitter(fireEmitter6);

// GROUP: SMOKE
Particle::CGroup *smokeGroup = ps->createParticleGroup();

Particle::CQuadRenderer *smoke = factory->createQuadRenderer();

texture = CTextureManager::getInstance()->getTexture("Particles/Textures/explosion.png");
smoke->setMaterialType(Particle::AddtiveAlpha, Particle::Camera);
smoke->setAtlas(2, 2);
smoke->SizeX = 0.3f;
smoke->SizeY = 0.3f;
smoke->getMaterial()->setTexture(0, texture);
smoke->getMaterial()->applyMaterial();

smokeGroup->setRenderer(smoke);
smokeGroup->createModel(Particle::ColorR)->setStart(0.3f)->setEnd(0.2f);
smokeGroup->createModel(Particle::ColorG)->setStart(0.25f)->setEnd(0.2f);
smokeGroup->createModel(Particle::ColorB)->setStart(0.2f);
smokeGroup->createModel(Particle::Scale)->setStart(5.0f)->setEnd(10.0f);
smokeGroup->createModel(Particle::RotateZ)->setStart(0.0f, 2.0f * core::PI);
smokeGroup->createModel(Particle::RotateSpeedZ)->setStart(1.1f, 2.2f);
smokeGroup->createModel(Particle::FrameIndex)->setStart(0.0f, 3.0f);
smokeGroup->LifeMin = 5.0f;
smokeGroup->LifeMax = 5.0f;

Particle::CInterpolator *smokeAlphaInterpolator = smokeGroup->createInterpolator();
smokeAlphaInterpolator->addEntry(0.0f, 0.0f);
smokeAlphaInterpolator->addEntry(0.2f, 0.2f);
smokeAlphaInterpolator->addEntry(1.0f, 0.0f);
smokeGroup->createModel(Particle::ColorA)->setInterpolator(smokeAlphaInterpolator);

Particle::CEmitter *smokeEmitter = factory->createSphericEmitter(core::vector3df(0.0f, 1.0f, 0.0f), 0.0f, 0.5f * core::PI);
smokeEmitter->setZone(factory->createSphereZone(core::vector3df(), 1.2f));
smokeEmitter->setFlow(25);
smokeEmitter->setForce(0.5f, 1.0f);

smokeGroup->addEmitter(smokeEmitter);
}

void SampleParticlesExplosion::initParticleSystem(Particle::CParticleComponent *ps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SampleParticlesExplosion :
CCamera *m_camera;

CForwardRP *m_forwardRP;
CPostProcessorRP *m_postProcessorRP;

CGlyphFont* m_font;

Expand Down

0 comments on commit 1a0491e

Please sign in to comment.