diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 17856c7f8cbbc54b9bb374fa559f0284303e49f5..b57749730f3a301658418dba70c6498cc4c125f2 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -3,6 +3,6 @@ Pos=60,60 Size=400,400 [Window][Particle Generator] -Pos=60,60 -Size=733,329 +Pos=13,14 +Size=505,662 diff --git a/ParticleGenerator/res/shaders/scene/Billboard-Sprite-Little.vert b/ParticleGenerator/res/shaders/scene/Billboard-Sprite-Little.vert new file mode 100644 index 0000000000000000000000000000000000000000..3cbbd8c3c13c502a8507ce9c9c13fc60b49f7dc8 --- /dev/null +++ b/ParticleGenerator/res/shaders/scene/Billboard-Sprite-Little.vert @@ -0,0 +1,25 @@ +#version 460 core + +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTex; + +uniform mat4 uView; +uniform mat4 uProj; +uniform mat4 uModels[16]; +uniform vec4 uFrames[16]; + +out vec2 zTex; +out vec4 zFrame; + +void main() { + vec3 cameraRight = vec3(uView[0][0], uView[1][0], uView[2][0]); + vec3 cameraUp = vec3(uView[0][1], uView[1][1], uView[2][1]); + vec3 particlePosition = vec3(uModels[gl_InstanceID][0][3], uModels[gl_InstanceID][1][3], uModels[gl_InstanceID][2][3]); + vec2 particleSize = vec2(1.0, 1.0); + + vec3 vertexPosition = particlePosition + cameraRight * aPos.x * particleSize.x + cameraUp * aPos.y * particleSize.y; + + gl_Position = uProj * uView * uModels[gl_InstanceID] * vec4(vertexPosition, 1.0); + zTex = aTex; + zFrame = uFrames[gl_InstanceID]; +} \ No newline at end of file diff --git a/ParticleGenerator/res/shaders/scene/Billboard-Sprite.frag b/ParticleGenerator/res/shaders/scene/Billboard-Sprite.frag index 1c629490342c04b8b7c63a4d4141a8fe06e2e877..2b1ef0f6bc5e1c5da07f7a9224e85e92c402222a 100644 --- a/ParticleGenerator/res/shaders/scene/Billboard-Sprite.frag +++ b/ParticleGenerator/res/shaders/scene/Billboard-Sprite.frag @@ -13,5 +13,11 @@ void main() { (zFrame.x / uSize.x) + (zFrame.z / uSize.x) * zTex.x, (zFrame.y / uSize.y) + (zFrame.w / uSize.y) * zTex.y ); - FragColor = texture(uTexture, coord) * uColor; + + vec4 color = texture(uTexture, coord); + if(color.a < 0.1) { + discard; + } + + FragColor = color * uColor; } \ No newline at end of file diff --git a/ParticleGenerator/res/shaders/scene/Phong.frag b/ParticleGenerator/res/shaders/scene/Phong.frag index 1e211fc0717b01c1a819a679fe1b838840183097..6b061f5dbf4629488479ad486ecdca16b2320732 100644 --- a/ParticleGenerator/res/shaders/scene/Phong.frag +++ b/ParticleGenerator/res/shaders/scene/Phong.frag @@ -12,7 +12,7 @@ uniform vec4 uColor; uniform sampler2D uSlot; void main() { - float ambientStrength = 0.25; + float ambientStrength = 1.0; vec4 ambient = ambientStrength * uColor; vec3 norm = normalize(zNormal); diff --git a/ParticleGenerator/res/textures/glow2bgb.png b/ParticleGenerator/res/textures/glow2bgb.png new file mode 100644 index 0000000000000000000000000000000000000000..3c55b4430e4d1e3c2be3d44d33db8586e14778c5 Binary files /dev/null and b/ParticleGenerator/res/textures/glow2bgb.png differ diff --git a/ParticleGenerator/res/textures/mastergig.png b/ParticleGenerator/res/textures/mastergig.png new file mode 100644 index 0000000000000000000000000000000000000000..af64cd11b1f7e7acf2abd9e18405a5b8ac294406 Binary files /dev/null and b/ParticleGenerator/res/textures/mastergig.png differ diff --git a/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp index 0f7a62dba8b3dc18bbcfe789bbbc1739456c18a7..3179ac7cfb8e308a2279bd821e22f0a6346a3b75 100644 --- a/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp +++ b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp @@ -26,7 +26,7 @@ namespace pg::interface { color = ImVec4(0.75f, 0.75f, 0.15f, 1.f); } - ImGui::TextColored(color, "Particule Number : %i / %i", count, max); + ImGui::TextColored(color, "Particules Number : %i / %i", count, max); ImGui::ProgressBar(pc); if(ImGui::Button("Spawn", ImVec2(size.x * 0.5f, 25))) { this->_scene->spawn(1, current_time); diff --git a/ParticleGenerator/src/Particle/generator/Generator.hpp b/ParticleGenerator/src/Particle/generator/Generator.hpp index 6416090cbb277853e4acfb16f09b4b3348615f69..b1f6f6b50758439bcb8b8711f0ae4086a240b249 100644 --- a/ParticleGenerator/src/Particle/generator/Generator.hpp +++ b/ParticleGenerator/src/Particle/generator/Generator.hpp @@ -40,4 +40,20 @@ namespace pg::particle { virtual std::vector<std::unique_ptr<T>> generate(size_t count, size_t birth = 0) const = 0; inline std::vector<std::unique_ptr<T>> operator()(size_t count, size_t birth = 0) const {return this->generate(count, birth);} }; -} \ No newline at end of file +} + +template <typename T> +using ParticleContainer = std::vector<T>; + +using Vec3 = glm::vec3; + +template <typename T> +class Generator { + private: + Vec3 position; + Vec3 positionVariation; + Vec3 rotation; + + public: + virtual Container<T> generate(unsigned int number, long when) const = 0; +}; \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Renderer.cpp b/ParticleGenerator/src/Scene/Renderer.cpp index 4bb373645f04899e4982134933f60a0f98178511..6cb112b873ff1e42a571377e35ad4c8cf593a78c 100644 --- a/ParticleGenerator/src/Scene/Renderer.cpp +++ b/ParticleGenerator/src/Scene/Renderer.cpp @@ -31,7 +31,8 @@ namespace pg::scene { } void Renderer::render(std::optional<Scene *> scene, const Camera & camera, double current_time) { - glClearColor(0.f, 0.f, 0.f, 1.f); + //glClearColor(0.f, 0.f, 0.f, 1.f); + glClearColor(1.f, 1.f, 1.f, 1.0f); glEnable(GL_BLEND); glEnable(GL_MULTISAMPLE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/ParticleGenerator/src/Scene/Scenes/BillboardTest.cpp b/ParticleGenerator/src/Scene/Scenes/BillboardTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47c4bff7173843ae77d7c7a0c1608b996ef77151 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/BillboardTest.cpp @@ -0,0 +1,99 @@ +#include "BillboardTest.hpp" + +namespace pg::scene { + BillboardTest::BillboardTest() + : SceneParticle(1) {} + + + void BillboardTest::initialize() { + this->_billboards.initialize(); + if(!this->_program.usable()) { + pg::Source vertices("res/shaders/scene/Billboard-Sprite-Little.vert", pg::Source::Categorie::VERTEX); + pg::Source fragment("res/shaders/scene/Billboard-Sprite.frag", pg::Source::Categorie::FRAGMENT); + + this->_program << vertices; + this->_program << fragment; + + this->_program.link(); + + vertices.release(); + fragment.release(); + } + + this->_texture.load("res/textures/mastergig.png"); + this->_frames.clear(); + this->_frames.push_back(glm::vec4(0, 0, 16, 16)); + this->_frames.push_back(glm::vec4(16, 0, 16, 16)); + this->_frames.push_back(glm::vec4(32, 0, 16, 16)); + this->_frames.push_back(glm::vec4(48, 0, 16, 16)); + this->_frames.push_back(glm::vec4(64, 0, 16, 16)); + this->_frames.push_back(glm::vec4(80, 0, 16, 16)); + this->_frames.push_back(glm::vec4(96, 0, 16, 16)); + this->_frames.push_back(glm::vec4(112, 0, 16, 16)); + this->_frames.push_back(glm::vec4(96, 0, 16, 16)); + + glClearColor(0.25f, 0.f, 0.15f, 1.0f); + } + + void BillboardTest::update(double) { + + } + + void BillboardTest::render(const Camera & camera, double current_time) { + glClearColor(1.f, 1.f, 1.f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + const glm::mat4 VIEW_MATRIX = camera.getViewMatrix(); + const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix(); + + std::vector<glm::mat4> models; + std::vector<glm::vec4> frames; + + float x = 6.f; + float y = 1.f; + for(size_t i = 0; i < 9; i++) { + glm::mat4 model = glm::mat4(1.f); + model = glm::translate(model, glm::vec3(x, y , 0.0)); + + models.push_back(model); + + frames.push_back(this->_frames.at(i%this->_frames.size())); + + x += -2.f; + + if(i == 5) { + y -= 3.f; + x = 3.f; + } + } + + + this->_texture.bind(0); + this->_program.use(); + + this->_program.setUniform("uView", VIEW_MATRIX); + this->_program.setUniform("uProj", PROJECTION_MATRIX); + this->_program.setUniform("uModels", models); + this->_program.setUniform("uFrames", frames); + + this->_program.setUniform("uSlot", 0); + this->_program.setUniform("uSize", glm::vec2(128.f, 16.f)); + this->_program.setUniform("uColor", glm::vec4(1.f)); + + if(this->isRenderEnable()) { + this->_billboards.draw(13); + } + + pg::error::OpenGLError::check(); + + glDisable(GL_DEPTH_TEST); + } + + void BillboardTest::destroy() { + + } + + void BillboardTest::spawn(int count, double current_time) { + + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/BillboardTest.hpp b/ParticleGenerator/src/Scene/Scenes/BillboardTest.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1cad17bea3f68c646fd7963d54b9d6a2508c4b32 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/BillboardTest.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "../Scene.hpp" +#include "../../Mesh/Billboard.hpp" + +namespace pg::scene { + class BillboardTest : public scene::SceneParticle { + private: + Billboard _billboards; + Material _texture; + Program _program; + std::vector<glm::vec4> _frames; + + public: + BillboardTest(); + virtual ~BillboardTest() = default; + + virtual void initialize(); + virtual void render(const Camera &, double); + virtual void update(double); + virtual void destroy(); + + virtual void spawn(int, double); + virtual std::string name() const {return "Billboard Test Scene";} + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/System/FrameHistorical.cpp b/ParticleGenerator/src/System/FrameHistorical.cpp index 7636911fcc83e64c4fd55b4f36f32f4a7753286b..b8e911dc85b372b458d90110024f285777d86ff5 100644 --- a/ParticleGenerator/src/System/FrameHistorical.cpp +++ b/ParticleGenerator/src/System/FrameHistorical.cpp @@ -20,7 +20,7 @@ namespace pg::interface { if(!this->_frames.empty()) { float max = *std::max_element(this->_frames.begin(), this->_frames.end()); - ImGui::Text("Frame Per Second : %f", this->getFramePerSecond()); + ImGui::Text("Frames Per Seconds : %f", this->getFramePerSecond()); ImGui::PlotLines("", this->_frames.data(), static_cast<int>(this->_frames.size()), 0, NULL, 0.0f, max * 1.1f, ImVec2(0, 80)); } } diff --git a/ParticleGenerator/src/main.cpp b/ParticleGenerator/src/main.cpp index 55817466b87f13462e940da70efe20a10bb78dec..015865320745ce3d903fa57a099fbd0a1f782a72 100644 --- a/ParticleGenerator/src/main.cpp +++ b/ParticleGenerator/src/main.cpp @@ -16,6 +16,7 @@ #include "Scene/Scenes/MeshGeneratorModel.hpp" #include "Scene/Scenes/PathPregenerated.hpp" #include "Scene/Scenes/PathAnimated.hpp" +#include "Scene/Scenes/BillboardTest.hpp" #include "Interface/Manager.hpp" @@ -88,6 +89,7 @@ int main(int argc, const char * argv[]) { pg::scene::MeshGeneratorModel meshGeneratorModel; pg::scene::PathPregenerated pathPregenerated(&bezier, ctrlPoints); pg::scene::PathAnimated pathAnimated(&bezier); + pg::scene::BillboardTest billboardTest; pg::Manager manager(window); pg::interface::Manager imanager(window, manager); @@ -100,6 +102,7 @@ int main(int argc, const char * argv[]) { manager.add(&meshGeneratorModel); manager.add(&pathPregenerated); manager.add(&pathAnimated); + manager.add(&billboardTest); while(window.isOpen()) { double current_time = glfwGetTime();