mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-30 23:33:02 +00:00
gfx-shader: Initial code
This commit is contained in:
parent
0a761b97a2
commit
f1b9a1a712
2 changed files with 336 additions and 1365 deletions
File diff suppressed because it is too large
Load diff
|
@ -16,19 +16,13 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <limits>
|
#include <filesystem>
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include "gfx/shader/gfx-shader-param.hpp"
|
||||||
#include <vector>
|
|
||||||
#include "gfx-source-texture.hpp"
|
|
||||||
#include "obs/gs/gs-effect.hpp"
|
#include "obs/gs/gs-effect.hpp"
|
||||||
#include "obs/gs/gs-mipmapper.hpp"
|
|
||||||
#include "obs/gs/gs-rendertarget.hpp"
|
|
||||||
#include "obs/gs/gs-texture.hpp"
|
|
||||||
#include "obs/gs/gs-vertexbuffer.hpp"
|
|
||||||
|
|
||||||
// OBS
|
// OBS
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -43,281 +37,82 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define S_SHADER_FILE "Shader.File"
|
|
||||||
#define S_SHADER_TECHNIQUE "Shader.Technique"
|
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
namespace effect_source {
|
namespace shader {
|
||||||
/* enum class value_mode {
|
enum class size_type {
|
||||||
INPUT,
|
Pixel,
|
||||||
SLIDER,
|
Percent,
|
||||||
};
|
|
||||||
enum class string_mode {
|
|
||||||
TEXT,
|
|
||||||
MULTILINE,
|
|
||||||
PASSWORD,
|
|
||||||
};
|
|
||||||
enum class texture_mode {
|
|
||||||
FILE,
|
|
||||||
SOURCE,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class effect_source;
|
enum class shader_mode {
|
||||||
|
Source,
|
||||||
class parameter {
|
Filter,
|
||||||
protected:
|
Transition,
|
||||||
std::weak_ptr<gfx::effect_source::effect_source> _parent;
|
|
||||||
|
|
||||||
std::shared_ptr<gs::effect> _effect;
|
|
||||||
std::shared_ptr<gs::effect_parameter> _param;
|
|
||||||
|
|
||||||
std::string _name;
|
|
||||||
std::string _visible_name;
|
|
||||||
std::string _description;
|
|
||||||
std::string _formulae;
|
|
||||||
bool _visible;
|
|
||||||
|
|
||||||
public:
|
|
||||||
parameter(std::shared_ptr<gfx::effect_source::effect_source> parent, std::shared_ptr<gs::effect> effect,
|
|
||||||
std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
virtual ~parameter();
|
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) = 0;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) = 0;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) = 0;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) = 0;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) = 0;
|
|
||||||
|
|
||||||
virtual void prepare() = 0;
|
|
||||||
|
|
||||||
virtual void assign() = 0;
|
|
||||||
|
|
||||||
std::shared_ptr<gs::effect_parameter> get_param();
|
|
||||||
|
|
||||||
virtual void enum_active_sources(obs_source_enum_proc_t, void*){};
|
|
||||||
|
|
||||||
public:
|
|
||||||
static std::shared_ptr<gfx::effect_source::parameter>
|
|
||||||
create(std::shared_ptr<gfx::effect_source::effect_source> parent, std::shared_ptr<gs::effect> effect,
|
|
||||||
std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class bool_parameter : public parameter {
|
class shader {
|
||||||
bool _value;
|
obs_source_t* _self;
|
||||||
|
|
||||||
public:
|
// Inputs
|
||||||
bool_parameter(std::shared_ptr<gfx::effect_source::effect_source> parent,
|
shader_mode _mode;
|
||||||
std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
uint32_t _base_width;
|
||||||
|
uint32_t _base_height;
|
||||||
|
std::shared_ptr<gs::texture> _input_a;
|
||||||
|
std::shared_ptr<gs::texture> _input_b;
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) override;
|
|
||||||
|
|
||||||
virtual void prepare() override;
|
|
||||||
|
|
||||||
virtual void assign() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class value_parameter : public parameter {
|
|
||||||
union {
|
|
||||||
float_t f[4];
|
|
||||||
int32_t i[4];
|
|
||||||
} _value;
|
|
||||||
union {
|
|
||||||
float_t f[4];
|
|
||||||
int32_t i[4];
|
|
||||||
} _minimum;
|
|
||||||
union {
|
|
||||||
float_t f[4];
|
|
||||||
int32_t i[4];
|
|
||||||
} _maximum;
|
|
||||||
union {
|
|
||||||
float_t f[4];
|
|
||||||
int32_t i[4];
|
|
||||||
} _step;
|
|
||||||
value_mode _mode = value_mode::INPUT;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
std::string name[4];
|
|
||||||
std::string visible_name[4];
|
|
||||||
} _cache;
|
|
||||||
|
|
||||||
public:
|
|
||||||
value_parameter(std::shared_ptr<gfx::effect_source::effect_source> parent,
|
|
||||||
std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) override;
|
|
||||||
|
|
||||||
virtual void prepare() override;
|
|
||||||
|
|
||||||
virtual void assign() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class matrix_parameter : public parameter {
|
|
||||||
matrix4 _value;
|
|
||||||
matrix4 _minimum;
|
|
||||||
matrix4 _maximum;
|
|
||||||
matrix4 _step;
|
|
||||||
value_mode _mode = value_mode::INPUT;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
std::string name[16];
|
|
||||||
std::string visible_name[16];
|
|
||||||
} _cache;
|
|
||||||
|
|
||||||
public:
|
|
||||||
matrix_parameter(std::shared_ptr<gfx::effect_source::effect_source> parent,
|
|
||||||
std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) override;
|
|
||||||
|
|
||||||
virtual void prepare() override;
|
|
||||||
|
|
||||||
virtual void assign() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class string_parameter : public parameter {
|
|
||||||
std::string _value;
|
|
||||||
string_mode _mode = string_mode::TEXT;
|
|
||||||
|
|
||||||
public:
|
|
||||||
string_parameter(std::shared_ptr<gfx::effect_source::effect_source> parent,
|
|
||||||
std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) override;
|
|
||||||
|
|
||||||
virtual void prepare() override;
|
|
||||||
|
|
||||||
virtual void assign() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class texture_parameter : public parameter {
|
|
||||||
std::string _file_name;
|
|
||||||
std::shared_ptr<gs::texture> _file;
|
|
||||||
|
|
||||||
float_t _last_check;
|
|
||||||
size_t _last_size;
|
|
||||||
time_t _last_modify_time;
|
|
||||||
time_t _last_create_time;
|
|
||||||
|
|
||||||
std::string _source_name;
|
|
||||||
std::shared_ptr<obs::source> _source;
|
|
||||||
std::shared_ptr<gfx::source_texture> _source_renderer;
|
|
||||||
std::shared_ptr<gs::texture> _source_tex;
|
|
||||||
|
|
||||||
texture_mode _mode = texture_mode::FILE;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
std::string name[4];
|
|
||||||
std::string visible_name[4];
|
|
||||||
} _cache;
|
|
||||||
|
|
||||||
void load_texture(std::string file);
|
|
||||||
|
|
||||||
public:
|
|
||||||
texture_parameter(std::shared_ptr<gfx::effect_source::effect_source> parent,
|
|
||||||
std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
||||||
|
|
||||||
bool modified2(obs_properties_t* props, obs_property_t* property, obs_data_t* settings);
|
|
||||||
|
|
||||||
virtual void defaults(obs_properties_t* props, obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void remove_properties(obs_properties_t* props) override;
|
|
||||||
|
|
||||||
virtual void update(obs_data_t* data) override;
|
|
||||||
|
|
||||||
virtual void tick(float_t time) override;
|
|
||||||
|
|
||||||
virtual void prepare() override;
|
|
||||||
|
|
||||||
virtual void assign() override;
|
|
||||||
|
|
||||||
virtual void enum_active_sources(obs_source_enum_proc_t, void*) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::pair<gs::effect_parameter::type, std::string> param_ident_t;
|
|
||||||
typedef std::function<bool(std::shared_ptr<gs::effect_parameter> param)> valid_property_cb_t;
|
|
||||||
typedef std::function<void(std::shared_ptr<gs::effect> effect)> param_override_cb_t;
|
|
||||||
*/
|
|
||||||
class effect_source {
|
|
||||||
// Shader
|
// Shader
|
||||||
std::string _source_file;
|
gs::effect _shader;
|
||||||
std::shared_ptr<gs::effect> _effect;
|
std::filesystem::path _shader_file;
|
||||||
|
std::string _shader_tech;
|
||||||
|
|
||||||
std::string _file;
|
// Shader Params
|
||||||
std::shared_ptr<gs::effect> _effect;
|
std::map<std::string, std::shared_ptr<parameter>> _shader_params;
|
||||||
std::string _tech;
|
|
||||||
std::map<param_ident_t, std::shared_ptr<parameter>> _params;
|
|
||||||
|
|
||||||
std::shared_ptr<gs::vertex_buffer> _tri;
|
// Options
|
||||||
|
size_type _width_type;
|
||||||
float_t _last_check;
|
double_t _width_value;
|
||||||
size_t _last_size;
|
size_type _height_type;
|
||||||
time_t _last_modify_time;
|
double_t _height_value;
|
||||||
time_t _last_create_time;
|
|
||||||
|
|
||||||
|
// Cache
|
||||||
float_t _time;
|
float_t _time;
|
||||||
float_t _time_active;
|
std::mt19937_64 _random;
|
||||||
float_t _time_since_last_tick;
|
std::list<std::string> _string_cache;
|
||||||
|
|
||||||
std::uniform_real_distribution<float_t> _random_dist{0.f, 1.f};
|
|
||||||
std::default_random_engine _random_generator;
|
|
||||||
|
|
||||||
void load_file(std::string file);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
effect_source(obs_source_t* self);
|
shader(obs_source_t* self, shader_mode mode);
|
||||||
~effect_source();
|
~shader();
|
||||||
|
|
||||||
|
void load_shader(std::filesystem::path file);
|
||||||
|
|
||||||
|
void load_shader_params();
|
||||||
|
|
||||||
void properties(obs_properties_t* props);
|
void properties(obs_properties_t* props);
|
||||||
|
|
||||||
|
bool on_shader_changed(obs_properties_t* props, obs_property_t* prop, obs_data_t* data);
|
||||||
|
|
||||||
|
bool on_technique_changed(obs_properties_t* props, obs_property_t* prop, obs_data_t* data);
|
||||||
|
|
||||||
|
void update_shader(obs_data_t* data);
|
||||||
|
|
||||||
|
void update_technique(obs_data_t* data);
|
||||||
|
|
||||||
void update(obs_data_t* data);
|
void update(obs_data_t* data);
|
||||||
|
|
||||||
|
uint32_t width();
|
||||||
|
|
||||||
|
uint32_t height();
|
||||||
|
|
||||||
bool tick(float_t time);
|
bool tick(float_t time);
|
||||||
|
|
||||||
void render(bool is_matrix_valid = false);
|
void render();
|
||||||
|
|
||||||
obs_source_t* get_self();
|
public:
|
||||||
|
void set_size(uint32_t w, uint32_t h);
|
||||||
|
|
||||||
void enum_active_sources(obs_source_enum_proc_t, void*);
|
void set_input_a(std::shared_ptr<gs::texture> tex);
|
||||||
|
|
||||||
bool modified2(obs_properties_t* props, obs_property_t* property, obs_data_t* settings);
|
void set_input_b(std::shared_ptr<gs::texture> tex);
|
||||||
};
|
};
|
||||||
} // namespace effect_source
|
} // namespace shader
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|
Loading…
Reference in a new issue