Skip to content

Commit

Permalink
Integrate SmokeParticle
Browse files Browse the repository at this point in the history
  • Loading branch information
lhog committed Sep 12, 2024
1 parent 8708ef7 commit 2ab9e8e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

uniform ivec2 arraySizes;
uniform vec4 frameInfo; // gs->frameNum, globalRendering->timeOffset, gu->modGameTime, prevSyncedFrame
uniform vec3 windVec; // vec * speed

uniform vec3 camPos;
uniform vec3 camDir[3]; // right, up, forward
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
return {
EarlyExit =
[[
int syncedTime = int(frameInfo.x - createFrame);
float currTime = syncedTime + frameInfo.y;
float age = ageRate * syncedTime;
if (age >= 1.0)
return;
]],
MainCode =
[[
bool doUpdate = (frameInfo.x > frameInfo.w);
if (doUpdate) {
pos += speed;
pos += windVec * age * 0.05;
size += sizeExpansion;
size += ((startSize - size) * 0.2 * float(size < startSize));
SavePos(pos);
SaveSize(size);
}
float alpha = (1.0 - age);
color *= alpha;
SetCurrentAnimation(animParams, currTime);
vec3 drawPos = pos + speed * frameInfo.y;
float drawSize = size + sizeExpansion * frameInfo.y;
// rotParams do we need it?
AddEffectsQuadCamera(
drawOrder,
animParams,
drawPos, vec2(drawSize), texCoord,
color
);
]]
}
1 change: 1 addition & 0 deletions rts/Rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ set(sources_engine_Rendering
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/MuzzleFlameParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/NanoParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/SimpleParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/SmokeParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/FBO.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/StreamBuffer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/GeometryBuffer.cpp"
Expand Down
23 changes: 23 additions & 0 deletions rts/Rendering/Env/Particles/Classes/SmokeProjectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Rendering/GlobalRendering.h"
#include "Rendering/Env/Particles/ProjectileDrawer.h"
#include "Rendering/GL/RenderBuffers.h"
#include "Rendering/Env/Particles/Generators/ParticleGeneratorHandler.h"
#include "Rendering/Textures/TextureAtlas.h"
#include "Sim/Misc/Wind.h"
#include "Sim/Projectiles/ExpGenSpawnableMemberInfo.h"
Expand Down Expand Up @@ -67,6 +68,28 @@ CSmokeProjectile::CSmokeProjectile(

useAirLos |= ((pos.y - CGround::GetApproximateHeight(pos.x, pos.z, false)) > 10.0f);
alwaysVisible |= (owner == nullptr);

auto& pg = ParticleGeneratorHandler::GetInstance().GetGenerator<SmokeParticleGenerator>();
pgOffset = pg.Add({
.pos = pos,
.size = size,
.startSize = startSize,
.sizeExpansion = sizeExpansion,
.ageRate = ageSpeed,
.speed = speed,
.createFrame = createFrame,
.animParams = animParams,
.color = SColor{color, color, color, 1.0f},
.rotParams = rotParams,
.drawOrder = drawOrder,
.texCoord = *projectileDrawer->GetSmokeTexture(textureNum)
});
}

CSmokeProjectile::~CSmokeProjectile()
{
auto& pg = ParticleGeneratorHandler::GetInstance().GetGenerator<SmokeParticleGenerator>();
pg.Del(pgOffset);
}


Expand Down
7 changes: 4 additions & 3 deletions rts/Rendering/Env/Particles/Classes/SmokeProjectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CSmokeProjectile : public CProjectile
float sizeExpansion,
float color
);
~CSmokeProjectile() override;

void Update() override;
void Draw() override;
Expand All @@ -32,16 +33,16 @@ class CSmokeProjectile : public CProjectile

static bool GetMemberInfo(SExpGenSpawnableMemberInfo& memberInfo);

public:
float size;
private:
float color;
float age;
float ageSpeed;
public:
float size;
private:
float startSize;
float sizeExpansion;
int textureNum;
size_t pgOffset;
};

#endif /* SMOKE_PROJECTILE_H */
3 changes: 3 additions & 0 deletions rts/Rendering/Env/Particles/Generators/ParticleGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Game/GlobalUnsynced.h"
#include "lua/LuaParser.h"
#include "Sim/Misc/GlobalSynced.h"
#include "Sim/Misc/Wind.h"

// to not repeat in derived classes
#include "Rendering/Textures/TextureAtlas.h"
Expand Down Expand Up @@ -142,6 +143,7 @@ inline void ParticleGenerator<ParticleDataType, ParticleGenType>::UpdateCommonUn
);

shader->SetUniform("frameInfo", currFrame, globalRendering->timeOffset, gu->modGameTime, prevFrame);
shader->SetUniform3v("windVec", &envResHandler.GetCurrentWindVec().x);

shader->SetUniform3v("camPos", &camera->GetPos().x);
shader->SetUniform3v("camDir[0]", &camera->GetRight().x);
Expand Down Expand Up @@ -433,6 +435,7 @@ inline Shader::IProgramObject* ParticleGenerator<ParticleDataType, ParticleGenTy

shader->SetUniform("arraySizes", 0, 0);
shader->SetUniform("frameInfo", 0.0f, 0.0f, 0.0f, 0.0f);
shader->SetUniform("windVec", 0.0f, 0.0f, 0.0f);
shader->SetUniform("camPos", 0.0f, 0.0f, 0.0f);
shader->SetUniform("camDir[0]", 0.0f, 0.0f, 0.0f);
shader->SetUniform("camDir[1]", 0.0f, 0.0f, 0.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "MuzzleFlameParticleGenerator.h"
#include "NanoParticleGenerator.h"
#include "SimpleParticleGenerator.h"
#include "SmokeParticleGenerator.h"

namespace Shader {
struct IProgramObject;
Expand Down Expand Up @@ -103,7 +104,8 @@ class ParticleGeneratorHandler {
MuzzleFlameParticleGenerator,
NanoParticleGenerator,
// skipped shields and repulsor
SimpleParticleGenerator
SimpleParticleGenerator,
SmokeParticleGenerator
>;

std::unique_ptr<GeneratorsTuple> generators;
Expand Down
19 changes: 19 additions & 0 deletions rts/Rendering/Env/Particles/Generators/SmokeParticleGenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "SmokeParticleGenerator.h"

CR_BIND(SmokeParticleData, )
CR_REG_METADATA(SmokeParticleData,
(
CR_MEMBER(pos),
CR_MEMBER(size),
CR_MEMBER(startSize),
CR_MEMBER(sizeExpansion),
CR_MEMBER(ageRate),
CR_IGNORED(unused),
CR_MEMBER(speed),
CR_MEMBER(createFrame),
CR_MEMBER(animParams),
CR_MEMBER(color),
CR_MEMBER(rotParams),
CR_MEMBER(drawOrder),
CR_MEMBER(texCoord)
))
40 changes: 40 additions & 0 deletions rts/Rendering/Env/Particles/Generators/SmokeParticleGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include "ParticleGenerator.h"

struct SmokeParticleData {
CR_DECLARE_STRUCT(SmokeParticleData)
float3 pos;
float size;

float startSize;
float sizeExpansion;
float ageRate;
float unused;

float3 speed;
int32_t createFrame;

float3 animParams;
SColor color;

float3 rotParams;
int32_t drawOrder;

AtlasedTexture texCoord;

int32_t GetMaxNumQuads() const { return 1 * (texCoord != AtlasedTexture::DefaultAtlasTexture); }
void Invalidate() {
texCoord = AtlasedTexture::DefaultAtlasTexture;
}
};
static_assert(sizeof(SmokeParticleData) % 16 == 0);

class SmokeParticleGenerator : public ParticleGenerator<SmokeParticleData, SmokeParticleGenerator> {
friend class ParticleGenerator<SmokeParticleData, SmokeParticleGenerator>;
public:
SmokeParticleGenerator() {}
~SmokeParticleGenerator() {}
protected:
bool GenerateCPUImpl() { return false; }
};

0 comments on commit 2ab9e8e

Please sign in to comment.