diff --git a/assets/shaders/explosion.vs b/assets/shaders/explosion.vs index 26dd04b1..9e1e1fde 100644 --- a/assets/shaders/explosion.vs +++ b/assets/shaders/explosion.vs @@ -104,7 +104,7 @@ varying vec3 fragNormal; void main() { // Send vertex attributes to fragment shader - fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5); + fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + center + vec3(frame))) * 0.5); fragColor = vertexColor; fragNormal = vertexNormal; fragTexCoord = vertexTexCoord; diff --git a/lib/Ray/sources/Shaders/Shaders.cpp b/lib/Ray/sources/Shaders/Shaders.cpp index 0def3c96..811fe34a 100644 --- a/lib/Ray/sources/Shaders/Shaders.cpp +++ b/lib/Ray/sources/Shaders/Shaders.cpp @@ -6,6 +6,7 @@ #include #include "Exceptions/RayError.hpp" +#include "Vector/Vector3.hpp" namespace RAY { @@ -38,6 +39,7 @@ namespace RAY SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &value, SHADER_UNIFORM_FLOAT); } + void Shader::setShaderUniformVar(const std::string &varName, int value) { if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) { @@ -60,4 +62,18 @@ namespace RAY { EndShaderMode(); } + + void Shader::setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector) + { + if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) { + int varShaderIndex = GetShaderLocation(*this->_rayLibShader, varName.c_str()); + + if (varShaderIndex < 0) { + throw Exception::WrongInputError("The loaded shader doesn't have a variable called: " + varName); + } + this->_shaderIndexVars[varName] = varShaderIndex; + } + SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &vector, SHADER_UNIFORM_VEC3); + } + } \ No newline at end of file diff --git a/lib/Ray/sources/Shaders/Shaders.hpp b/lib/Ray/sources/Shaders/Shaders.hpp index 20231ea7..a4616670 100644 --- a/lib/Ray/sources/Shaders/Shaders.hpp +++ b/lib/Ray/sources/Shaders/Shaders.hpp @@ -9,6 +9,7 @@ #include #include #include "Utils/Cache.hpp" +#include "Vector/Vector3.hpp" namespace RAY { @@ -46,6 +47,8 @@ namespace RAY //! @note Throw if the var is not found void setShaderUniformVar(const std::string &varName, int value); + void setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector); + void setLocation(::ShaderLocationIndex, const std::string &name); //! @brief ctor if no vertexfile in needed set it to nullptr diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 02ed40aa..d792bec8 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -53,6 +53,7 @@ namespace BBM .addComponent("assets/shaders/explosion.fs", "assets/shaders/explosion.vs", [](WAL::Entity &entity, WAL::Wal &wal, std::chrono::nanoseconds dtime) { auto &ctx = entity.getComponent(); auto &shader = entity.getComponent(); + auto &pos = entity.getComponent(); ctx.clock += dtime; if (duration_cast(ctx.clock).count() <= 10) @@ -69,7 +70,8 @@ namespace BBM shader.shader.setShaderUniformVar("frame", ctx.frameCounter); shader.shader.setShaderUniformVar("alpha", ctx.alpha); shader.shader.setShaderUniformVar("radius", ctx.explosionRadius); - }) + shader.shader.setShaderUniformVar("center", pos.position); + }, true) .addComponent(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) { explosion.scheduleDeletion(); })