diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index dc8506b7..08716e2c 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -38,7 +38,7 @@ gfx::shader::shader::shader(obs_source_t* self, shader_mode mode) _width_type(size_type::Percent), _width_value(1.0), _height_type(size_type::Percent), _height_value(1.0), - _time(0), _random(), _have_current_params(false) + _time(0), _time_loop(0), _loops(0), _random(), _have_current_params(false) { _random.seed(static_cast(time(NULL))); } @@ -362,6 +362,15 @@ bool gfx::shader::shader::tick(float_t time) // Update State _time += time; + _time_loop += time; + if (_time_loop > 1.) { + _time_loop -= 1.; + + // Loops + _loops += 1; + if (_loops >= 4194304) + _loops = -_loops; + } return false; } @@ -379,7 +388,7 @@ void gfx::shader::shader::prepare_render() if (gs::effect_parameter el = _shader.get_parameter("Time"); el != nullptr) { if (el.get_type() == gs::effect_parameter::type::Float4) { el.set_float4( - _time, 0, 0, + _time, _time_loop, static_cast(_loops), static_cast(static_cast(_random()) / static_cast(std::numeric_limits::max()))); } diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index 2ba28133..7b714a40 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -56,9 +56,9 @@ namespace gfx { obs_source_t* _self; // Inputs - shader_mode _mode; - uint32_t _base_width; - uint32_t _base_height; + shader_mode _mode; + uint32_t _base_width; + uint32_t _base_height; // Shader gs::effect _shader; @@ -77,6 +77,8 @@ namespace gfx { // Cache float_t _time; + float_t _time_loop; + int32_t _loops; std::mt19937_64 _random; bool _have_current_params;