diff --git a/assets/shaders/mask.vs b/assets/shaders/mask.vs index 3b3c31e7..58cb597e 100644 --- a/assets/shaders/mask.vs +++ b/assets/shaders/mask.vs @@ -99,7 +99,7 @@ varying vec3 fragPosition; void main() { // Send vertex attributes to fragment shader - fragPosition = vec3(0, frame, 0) + vertexPosition + vertexPosition * vec3(cnoise(vertexNormal) * 0.5); + fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5); // Calculate final vertex position gl_Position = mvp * vec4(fragPosition , 1.0); //gl_Position = vec4(vertexNormal, 1.0); diff --git a/sources/Component/Shaders/ShaderComponent.cpp b/sources/Component/Shaders/ShaderComponent.cpp index 5a1edcf9..febb859a 100644 --- a/sources/Component/Shaders/ShaderComponent.cpp +++ b/sources/Component/Shaders/ShaderComponent.cpp @@ -22,12 +22,12 @@ namespace BBM ShaderComponent::ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) + const WAL::Callback &onFixedUpdate) : WAL::Component(entity), shader(vertexFilePath, fragmentFilePath), fragmentFilePath(fragmentFilePath), vertexFilePath(vertexFilePath), - onFixedUpdate(onFixedUpdate) + update(onFixedUpdate) { } @@ -44,7 +44,7 @@ namespace BBM ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) + const WAL::Callback &onFixedUpdate) : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) { } @@ -60,7 +60,7 @@ namespace BBM ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) + const WAL::Callback &onFixedUpdate) : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) { } diff --git a/sources/Component/Shaders/ShaderComponent.hpp b/sources/Component/Shaders/ShaderComponent.hpp index 9ce04079..747ba37d 100644 --- a/sources/Component/Shaders/ShaderComponent.hpp +++ b/sources/Component/Shaders/ShaderComponent.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace BBM @@ -25,7 +26,7 @@ namespace BBM std::string vertexFilePath; //! @brief the function called to update shaders vars - WAL::Callback onFixedUpdate; + WAL::Callback update; //! @brief getter for _shader RAY::Shader &getShader(); @@ -45,7 +46,7 @@ namespace BBM ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback()); //! @brief Default copy ctor ShaderComponent(const ShaderComponent &) = default; @@ -69,7 +70,7 @@ namespace BBM ShaderComponentModel(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback()); //! @brief Default copy ctor ShaderComponentModel(const ShaderComponentModel &) = default; @@ -89,7 +90,7 @@ namespace BBM ShaderComponentDrawable2D(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback()); //! @brief Default copy ctor ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index f206fedb..ac503b87 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -29,8 +29,6 @@ #include "Map/Map.hpp" #include "Component/Score/ScoreComponent.hpp" -int glob = 0; - namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM @@ -63,22 +61,16 @@ namespace BBM return scene.addEntity("player") .addComponent() - //.addComponent("assets/player/player.iqm", true) - .addComponent(GenMeshSphere(1, 16, 16)) + .addComponent("assets/player/player.iqm", true) + //.addComponent(GenMeshSphere(1, 16, 16)) .addComponent() .addComponent() .addComponent() .addComponent() - .addComponent("assets/shaders/mask.fs", "assets/shaders/mask.vs", [](WAL::Entity &entity, WAL::Wal &wal) { - /*auto &shader = entity.getComponent(); - shader.shader.setShaderUniformVar("frame", glob); - glob++; - glob %= 10;*/ - }) .addComponent() // .addComponent("assets/shaders/glsl330/predator.fs") .addComponent>() - //.addComponent("assets/player/player.iqm", 3) + .addComponent("assets/player/player.iqm", 3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() .addComponent(soundPath) @@ -86,8 +78,8 @@ namespace BBM .addComponent() .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { - //auto &animation = entity.getComponent(); - //animation.setAnimIndex(5); + auto &animation = entity.getComponent(); + animation.setAnimIndex(5); }); } } \ No newline at end of file diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index e7b385a1..6857bbb9 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -11,9 +11,13 @@ #include "Component/Health/HealthComponent.hpp" #include #include +#include +#include "Component/Shaders/ShaderComponent.hpp" #include "Component/Collision/CollisionComponent.hpp" #include "Component/Tag/TagComponent.hpp" +int glob = 0; + using namespace std::chrono_literals; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -44,14 +48,27 @@ namespace BBM return; wal.getScene()->scheduleNewEntity("explosion") .addComponent(position) + .addComponent("assets/shaders/mask.fs", "assets/shaders/mask.vs", [](WAL::Entity &entity, WAL::Wal &wal, std::chrono::nanoseconds dtime) { + static std::chrono::nanoseconds nanoseconds {}; + auto &shader = entity.getComponent(); + + nanoseconds += dtime; + if (duration_cast(nanoseconds).count() <= 400) + return; + std::cout << "test" << std::endl; + shader.shader.setShaderUniformVar("frame", glob); + glob++; + glob %= 40; + }) .addComponent(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) { explosion.scheduleDeletion(); }) - .addComponent("assets/bombs/explosion/explosion.glb", false, + .addComponent(GenMeshSphere(0.5, 16, 16)); + /*.addComponent("assets/bombs/explosion/explosion.glb", false, std::make_pair( MAP_DIFFUSE, "assets/bombs/explosion/blast.png" - )); + ));*/ wal.getSystem().dispatchEvent([position, size, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { diff --git a/sources/System/Shaders/ShaderDrawable2DSystem.cpp b/sources/System/Shaders/ShaderDrawable2DSystem.cpp index edc58268..c8e7ae8d 100644 --- a/sources/System/Shaders/ShaderDrawable2DSystem.cpp +++ b/sources/System/Shaders/ShaderDrawable2DSystem.cpp @@ -11,10 +11,10 @@ namespace BBM { } - void ShaderDrawable2DSystem::onFixedUpdate(WAL::ViewEntity &entity) + void ShaderDrawable2DSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &shader = entity->getComponent(); - shader.onFixedUpdate(entity, this->_wal); + shader.update(entity, this->_wal, dtime); } } \ No newline at end of file diff --git a/sources/System/Shaders/ShaderDrawable2DSystem.hpp b/sources/System/Shaders/ShaderDrawable2DSystem.hpp index 6358f040..59d22534 100644 --- a/sources/System/Shaders/ShaderDrawable2DSystem.hpp +++ b/sources/System/Shaders/ShaderDrawable2DSystem.hpp @@ -15,7 +15,7 @@ namespace BBM public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @brief ctor explicit ShaderDrawable2DSystem(WAL::Wal &wal); diff --git a/sources/System/Shaders/ShaderModelSystem.cpp b/sources/System/Shaders/ShaderModelSystem.cpp index 20197fed..07baa38a 100644 --- a/sources/System/Shaders/ShaderModelSystem.cpp +++ b/sources/System/Shaders/ShaderModelSystem.cpp @@ -11,10 +11,10 @@ namespace BBM { } - void ShaderModelSystem::onFixedUpdate(WAL::ViewEntity &entity) + void ShaderModelSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &shader = entity->getComponent(); - shader.onFixedUpdate(entity, this->_wal); + shader.update(entity, this->_wal, dtime); } } \ No newline at end of file diff --git a/sources/System/Shaders/ShaderModelSystem.hpp b/sources/System/Shaders/ShaderModelSystem.hpp index 7c2b4ae0..7680e88f 100644 --- a/sources/System/Shaders/ShaderModelSystem.hpp +++ b/sources/System/Shaders/ShaderModelSystem.hpp @@ -15,7 +15,7 @@ namespace BBM public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @brief ctor explicit ShaderModelSystem(WAL::Wal &wal); diff --git a/sources/System/Shaders/ShaderSystem.cpp b/sources/System/Shaders/ShaderSystem.cpp index 93121b14..8a86e3b6 100644 --- a/sources/System/Shaders/ShaderSystem.cpp +++ b/sources/System/Shaders/ShaderSystem.cpp @@ -12,10 +12,10 @@ namespace BBM { } - void ShaderSystem::onFixedUpdate(WAL::ViewEntity &entity) + void ShaderSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &shader = entity->getComponent(); - shader.onFixedUpdate(entity, this->_wal); + shader.update(entity, this->_wal, dtime); } } \ No newline at end of file diff --git a/sources/System/Shaders/ShaderSystem.hpp b/sources/System/Shaders/ShaderSystem.hpp index f2bc8e94..874505d0 100644 --- a/sources/System/Shaders/ShaderSystem.hpp +++ b/sources/System/Shaders/ShaderSystem.hpp @@ -14,7 +14,7 @@ namespace BBM public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @brief ctor explicit ShaderSystem(WAL::Wal &wal);