2018-03-20 11:45:41 +00:00
|
|
|
// Modern effects for a modern Streamer
|
|
|
|
// Copyright (C) 2017 Michael Fabian Dirks
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2022-11-28 08:11:55 +00:00
|
|
|
#include "gfx/gfx-util.hpp"
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "gfx/shader/gfx-shader-param.hpp"
|
|
|
|
#include "obs/gs/gs-effect.hpp"
|
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
|
|
|
|
#include "warning-disable.hpp"
|
2019-12-18 05:37:47 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <list>
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <map>
|
2019-08-07 15:14:44 +00:00
|
|
|
#include <random>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2018-09-28 09:55:55 +00:00
|
|
|
|
2021-06-08 02:47:04 +00:00
|
|
|
namespace streamfx::gfx {
|
2019-12-18 05:37:47 +00:00
|
|
|
namespace shader {
|
|
|
|
enum class size_type {
|
|
|
|
Pixel,
|
|
|
|
Percent,
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
enum class shader_mode {
|
|
|
|
Source,
|
|
|
|
Filter,
|
|
|
|
Transition,
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2020-05-13 06:41:32 +00:00
|
|
|
typedef std::map<std::string_view, std::shared_ptr<parameter>> shader_param_map_t;
|
2019-12-25 18:18:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
class shader {
|
|
|
|
obs_source_t* _self;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2022-11-28 08:11:55 +00:00
|
|
|
std::shared_ptr<streamfx::gfx::util> _gfx_util;
|
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Inputs
|
2020-08-10 01:29:05 +00:00
|
|
|
shader_mode _mode;
|
|
|
|
uint32_t _base_width;
|
|
|
|
uint32_t _base_height;
|
|
|
|
bool _active;
|
2021-10-15 14:30:01 +00:00
|
|
|
bool _visible;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Shader
|
2021-06-08 02:38:24 +00:00
|
|
|
streamfx::obs::gs::effect _shader;
|
2019-12-25 18:18:44 +00:00
|
|
|
std::filesystem::path _shader_file;
|
|
|
|
std::string _shader_tech;
|
|
|
|
std::filesystem::file_time_type _shader_file_mt;
|
|
|
|
uintmax_t _shader_file_sz;
|
|
|
|
float_t _shader_file_tick;
|
|
|
|
shader_param_map_t _shader_params;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Options
|
|
|
|
size_type _width_type;
|
|
|
|
double_t _width_value;
|
|
|
|
size_type _height_type;
|
|
|
|
double_t _height_value;
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Cache
|
2020-07-05 21:00:09 +00:00
|
|
|
bool _have_current_params;
|
2019-12-21 17:23:26 +00:00
|
|
|
float_t _time;
|
2020-03-28 21:17:33 +00:00
|
|
|
float_t _time_loop;
|
2020-04-03 16:40:05 +00:00
|
|
|
int32_t _loops;
|
2019-12-21 17:23:26 +00:00
|
|
|
std::mt19937_64 _random;
|
2020-07-05 21:00:09 +00:00
|
|
|
int32_t _random_seed;
|
|
|
|
float_t _random_values[16]; // 0..4 Per-Instance-Random, 4..8 Per-Activation-Random 9..15 Per-Frame-Random
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2020-04-23 05:56:12 +00:00
|
|
|
// Rendering
|
2021-06-08 02:38:24 +00:00
|
|
|
bool _rt_up_to_date;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _rt;
|
2020-04-23 05:56:12 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
public:
|
2019-12-18 05:37:47 +00:00
|
|
|
shader(obs_source_t* self, shader_mode mode);
|
|
|
|
~shader();
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool is_shader_different(const std::filesystem::path& file);
|
2019-08-07 18:39:55 +00:00
|
|
|
|
2022-07-21 11:09:10 +00:00
|
|
|
bool is_technique_different(std::string_view tech);
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2022-07-21 11:09:10 +00:00
|
|
|
bool load_shader(const std::filesystem::path& file, std::string_view tech, bool& shader_dirty,
|
2019-12-22 05:14:26 +00:00
|
|
|
bool& param_dirty);
|
2019-12-21 17:23:26 +00:00
|
|
|
|
2020-03-31 20:34:22 +00:00
|
|
|
static void defaults(obs_data_t* data);
|
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
void properties(obs_properties_t* props);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2020-04-03 16:40:05 +00:00
|
|
|
bool on_refresh_properties(obs_properties_t* props, obs_property_t* prop);
|
|
|
|
|
|
|
|
bool on_shader_or_technique_modified(obs_properties_t* props, obs_property_t* prop, obs_data_t* data);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool update_shader(obs_data_t* data, bool& shader_dirty, bool& param_dirty);
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
void update(obs_data_t* data);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
uint32_t width();
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
uint32_t height();
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
uint32_t base_width();
|
2020-06-21 16:42:05 +00:00
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
uint32_t base_height();
|
2020-06-21 16:42:05 +00:00
|
|
|
|
2019-08-07 16:42:54 +00:00
|
|
|
bool tick(float_t time);
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2020-03-28 17:37:00 +00:00
|
|
|
void prepare_render();
|
|
|
|
|
2021-03-28 12:29:19 +00:00
|
|
|
void render(gs_effect* effect);
|
2019-08-07 15:37:34 +00:00
|
|
|
|
2021-11-25 04:56:41 +00:00
|
|
|
obs_source_t* get();
|
|
|
|
|
2021-11-25 20:07:56 +00:00
|
|
|
std::filesystem::path get_shader_file();
|
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
public:
|
2020-08-10 01:29:05 +00:00
|
|
|
void set_size(uint32_t w, uint32_t h);
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2021-11-25 20:43:49 +00:00
|
|
|
void set_input_a(std::shared_ptr<streamfx::obs::gs::texture> tex, bool srgb = false);
|
2019-08-07 18:39:55 +00:00
|
|
|
|
2021-11-25 20:43:49 +00:00
|
|
|
void set_input_b(std::shared_ptr<streamfx::obs::gs::texture> tex, bool srgb = false);
|
2020-03-28 17:37:00 +00:00
|
|
|
|
|
|
|
void set_transition_time(float_t t);
|
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
void set_transition_size(uint32_t w, uint32_t h);
|
2020-07-05 21:00:09 +00:00
|
|
|
|
2021-10-15 14:30:01 +00:00
|
|
|
void set_visible(bool visible);
|
|
|
|
|
2020-07-05 21:00:09 +00:00
|
|
|
void set_active(bool active);
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-12-18 05:37:47 +00:00
|
|
|
} // namespace shader
|
2021-06-08 02:47:04 +00:00
|
|
|
} // namespace streamfx::gfx
|