mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-11 06:15:05 +00:00
gfx-shader: Additional stable time values
'Time.x' gets inaccurate if OBS Studio is running for more than two hours, therefore we have to do something to fix it. By allowing the shader code to control when things loop using 'Time.y' (0..1) and 'Time.z' (the number of times 'Time.y' wrapped back to 0), a much more stable animation can be achieved.
This commit is contained in:
parent
7d5c4361e3
commit
79406b0b08
2 changed files with 16 additions and 5 deletions
|
@ -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),
|
_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<unsigned long long>(time(NULL)));
|
_random.seed(static_cast<unsigned long long>(time(NULL)));
|
||||||
}
|
}
|
||||||
|
@ -362,6 +362,15 @@ bool gfx::shader::shader::tick(float_t time)
|
||||||
|
|
||||||
// Update State
|
// Update State
|
||||||
_time += time;
|
_time += time;
|
||||||
|
_time_loop += time;
|
||||||
|
if (_time_loop > 1.) {
|
||||||
|
_time_loop -= 1.;
|
||||||
|
|
||||||
|
// Loops
|
||||||
|
_loops += 1;
|
||||||
|
if (_loops >= 4194304)
|
||||||
|
_loops = -_loops;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +388,7 @@ void gfx::shader::shader::prepare_render()
|
||||||
if (gs::effect_parameter el = _shader.get_parameter("Time"); el != nullptr) {
|
if (gs::effect_parameter el = _shader.get_parameter("Time"); el != nullptr) {
|
||||||
if (el.get_type() == gs::effect_parameter::type::Float4) {
|
if (el.get_type() == gs::effect_parameter::type::Float4) {
|
||||||
el.set_float4(
|
el.set_float4(
|
||||||
_time, 0, 0,
|
_time, _time_loop, static_cast<float_t>(_loops),
|
||||||
static_cast<float_t>(static_cast<double_t>(_random())
|
static_cast<float_t>(static_cast<double_t>(_random())
|
||||||
/ static_cast<double_t>(std::numeric_limits<unsigned long long>::max())));
|
/ static_cast<double_t>(std::numeric_limits<unsigned long long>::max())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,9 @@ namespace gfx {
|
||||||
obs_source_t* _self;
|
obs_source_t* _self;
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
shader_mode _mode;
|
shader_mode _mode;
|
||||||
uint32_t _base_width;
|
uint32_t _base_width;
|
||||||
uint32_t _base_height;
|
uint32_t _base_height;
|
||||||
|
|
||||||
// Shader
|
// Shader
|
||||||
gs::effect _shader;
|
gs::effect _shader;
|
||||||
|
@ -77,6 +77,8 @@ namespace gfx {
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
float_t _time;
|
float_t _time;
|
||||||
|
float_t _time_loop;
|
||||||
|
int32_t _loops;
|
||||||
std::mt19937_64 _random;
|
std::mt19937_64 _random;
|
||||||
bool _have_current_params;
|
bool _have_current_params;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue