diff --git a/data/shaders/filter/drunk.effect b/data/shaders/filter/drunk.effect new file mode 100644 index 00000000..550ecc7f --- /dev/null +++ b/data/shaders/filter/drunk.effect @@ -0,0 +1,142 @@ +// Always provided by OBS +uniform float4x4 ViewProj< + bool visible = false; + string name = "View Projection Matrix"; +>; + +// Provided by Stream Effects +uniform float4 Time< + bool visible = false; + string name = "Time Array"; + string description = "A float4 value containing the total time, rendering time and the time since the last tick. The last value is a random number between 0 and 1."; +>; +uniform float4x4 Random< + bool visible = false; + string name = "Random Array"; + string description = "A float4x4 value containing random values between 0 and 1"; +>; +uniform texture2d ImageSource< + bool visible = false; + string name = "Source Texture (Filter, Transition)"; +>; +uniform float2 ImageSource_Size< + bool visible = false; + string name = "Source Texture Size (Filter, Transition)"; +>; +uniform float2 ImageSource_Texel< + bool visible = false; + string name = "Source Texture Texel Size (Filter, Transition)"; +>; + +// Shader Parameters +uniform float p_drunk_strength< + bool visible = true; + string name = "Strength"; + float minimum = 0.; + float maximum = 100.; + float step = .01; +> = 25.0; +uniform float p_drunk_speed< + bool visible = true; + string name = "Speed"; + float minimum = 0.; + float maximum = 100.; + float step = .01; +> = 2.0; + +// ---------- Shader Code +sampler_state def_sampler { + AddressU = Clamp; + AddressV = Clamp; + Filter = Linear; +}; + +struct VertData { + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +struct FragData { + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +FragData VSDefault(VertData v_in) { + FragData vert_out; + vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); + vert_out.uv = v_in.uv; + return vert_out; +} + +// ---------- Fixed Color +#define MAX_PTS 5 +#define MAX_LINE 5. + +float random_time_at(int x, int y) { + const float ts[MAX_PTS + 1][MAX_PTS + 1] = { + {.2, .8, -.2, .452, -.2832, .8}, + {-.28, -1, -.42, -.89, .72, -.29}, + {.75, .25, .33, .67, .98, .01}, + {-.28, 0.8, -.32, -.189, .11, .84}, + {-.48, 0.1, -.2323, -.555, .421, .23}, + {-.28, 0.3, -1.3333, 1.333, 4, 1}, + }; + + return ts[x][y]; +} + +float2 mult_at(int x, int y) { + float x2 = fmod(x, 2.); + float y2 = fmod(y, 2.); + + float2 mult; + mult.x = (x2 < 1.) ? -1. : 1.; + mult.y = (y2 < 1.) ? -1. : 1.; + + return mult; +} + +float4 PS_Drunk(FragData v_in) : TARGET { + float2 uvs[MAX_PTS + 1][MAX_PTS + 1]; + for (int x = 0; x <= MAX_PTS; x++) { + for (int y = 0; y <= MAX_PTS; y++) { + float2 off = float2(0, 0); + if ((x > 0) && (x < MAX_PTS)) { + off.x = cos(Time.y * p_drunk_speed + random_time_at(x, y)) * ImageSource_Texel.x; + } + if ((y > 0) && (y < MAX_PTS)) { + off.y = sin(Time.y * p_drunk_speed + random_time_at(x, y)) * ImageSource_Texel.y; + } + off *= (p_drunk_strength / 100.0) * ImageSource_Size * 0.5 * mult_at(x, y); + + uvs[x][y] = float2(x / MAX_LINE + off.x, y / MAX_LINE + off.y); + } + } + + float2 fade = frac(v_in.uv * MAX_LINE); + fade = (sin((fade - 0.5) * 3.141) + 1.0) * 0.5; + + int2 _low = int2(floor(v_in.uv * MAX_LINE)); + int2 _hig = int2(ceil(v_in.uv * MAX_LINE)); + + float2 uv = v_in.uv; + float2 uv_tl = uvs[_low.x][_low.y]; + float2 uv_tr = uvs[_hig.x][_low.y]; + float2 uv_bl = uvs[_low.x][_hig.y]; + float2 uv_br = uvs[_hig.x][_hig.y]; + + float2 uv_t = lerp(uv_tl, uv_tr, fade.x); + float2 uv_b = lerp(uv_bl, uv_br, fade.x); + uv = lerp(uv_t, uv_b, fade.y); + + return ImageSource.Sample(def_sampler, uv); +} + +technique Draw +{ + pass + { + vertex_shader = VSDefault(v_in); + pixel_shader = PS_Drunk(v_in); + } +} diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index f4ffbf0b..e682828f 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -18,6 +18,7 @@ */ #include "filter-blur.hpp" +#include #include #include #include diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 71a2e288..8dedecea 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -18,6 +18,7 @@ */ #include "filter-color-grade.hpp" +#include #include "strings.hpp" #include "util-math.hpp" diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index e4488ddf..f67280ea 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -18,6 +18,7 @@ */ #include "filter-displacement.hpp" +#include #include #include "strings.hpp" diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index e3d6fe15..00e7f5f9 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -18,6 +18,7 @@ */ #include "filter-dynamic-mask.hpp" +#include #include #include "strings.hpp" @@ -260,7 +261,7 @@ void filter::dynamic_mask::dynamic_mask_instance::update(obs_data_t* settings) found = this->_channels.find(kv1.first); if (found == this->_channels.end()) { assert(found != this->_channels.end()); - throw std::exception("Unable to insert element into data _store."); + throw std::runtime_error("Unable to insert element into data _store."); } } @@ -315,7 +316,7 @@ void filter::dynamic_mask::dynamic_mask_instance::save(obs_data_t* settings) found = this->_channels.find(kv1.first); if (found == this->_channels.end()) { assert(found != this->_channels.end()); - throw std::exception("Unable to insert element into data _store."); + throw std::runtime_error("Unable to insert element into data _store."); } } @@ -411,7 +412,7 @@ void filter::dynamic_mask::dynamic_mask_instance::video_render(gs_effect_t* in_e gs_blend_state_pop(); } else { - throw std::exception("Failed to render filter."); + throw std::runtime_error("Failed to render filter."); } this->_filter_texture = this->_filter_rt->get_texture(); diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index 95b031b7..aac3c948 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -18,6 +18,7 @@ */ #include "filter-sdf-effects.hpp" +#include #include "obs/gs/gs-helper.hpp" #include "strings.hpp" diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index f2e89ac9..bfbe1a0c 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -18,6 +18,7 @@ */ #include "filter-shader.hpp" +#include #include "strings.hpp" #include "utility.hpp" @@ -313,9 +314,9 @@ void filter::shader::shader_instance::video_tick(float_t sec_since_last) obs_source_t* target = obs_filter_get_target(_self); { // Update width and height. - _width = obs_source_get_base_width(target); - _height = obs_source_get_base_height(target); - _swidth = _width * _wscale; + _width = obs_source_get_base_width(target); + _height = obs_source_get_base_height(target); + _swidth = _width * _wscale; _sheight = _height * _hscale; } diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 281f5344..dcace777 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -18,6 +18,7 @@ */ #include "filter-transform.hpp" +#include #include "strings.hpp" #include "util-math.hpp" diff --git a/source/gfx/blur/gfx-blur-base.cpp b/source/gfx/blur/gfx-blur-base.cpp index 48720a75..c12f0d56 100644 --- a/source/gfx/blur/gfx-blur-base.cpp +++ b/source/gfx/blur/gfx-blur-base.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-base.hpp" +#include void gfx::blur::base::set_step_scale_x(double_t v) { diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index ee6a955d..4085e297 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-box-linear.hpp" +#include #include #include #include "obs/gs/gs-helper.hpp" diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index f3f2dbbd..b86f1358 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-box.hpp" +#include #include #include #include "obs/gs/gs-helper.hpp" diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index b39e941f..28e71e70 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-dual-filtering.hpp" +#include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" #include "util-math.hpp" diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index 41034652..db9c7cf8 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-gaussian-linear.hpp" +#include #include "obs/gs/gs-helper.hpp" #include "util-math.hpp" diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index 00908393..b0cc7a7d 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-blur-gaussian.hpp" +#include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" #include "util-math.hpp" diff --git a/source/gfx/gfx-effect-source.cpp b/source/gfx/gfx-effect-source.cpp index ff2eb651..14b5d2b4 100644 --- a/source/gfx/gfx-effect-source.cpp +++ b/source/gfx/gfx-effect-source.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-effect-source.hpp" +#include #include #include #include diff --git a/source/gfx/gfx-source-texture.cpp b/source/gfx/gfx-source-texture.cpp index a16b293a..8fc30dd0 100644 --- a/source/gfx/gfx-source-texture.cpp +++ b/source/gfx/gfx-source-texture.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "gfx-source-texture.hpp" +#include gfx::source_texture::~source_texture() { diff --git a/source/obs/gs/gs-indexbuffer.cpp b/source/obs/gs/gs-indexbuffer.cpp index 56dc16e1..dcc4b97b 100644 --- a/source/obs/gs/gs-indexbuffer.cpp +++ b/source/obs/gs/gs-indexbuffer.cpp @@ -18,6 +18,7 @@ */ #include "gs-indexbuffer.hpp" +#include #include "gs-limits.hpp" #include "obs/gs/gs-helper.hpp" diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index 25c25fc9..ffa02b5c 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -18,6 +18,7 @@ */ #include "gs-mipmapper.hpp" +#include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" diff --git a/source/obs/gs/gs-sampler.cpp b/source/obs/gs/gs-sampler.cpp index 1b00f8e0..0111deab 100644 --- a/source/obs/gs/gs-sampler.cpp +++ b/source/obs/gs/gs-sampler.cpp @@ -18,6 +18,7 @@ */ #include "gs-sampler.hpp" +#include gs::sampler::sampler() { diff --git a/source/obs/gs/gs-vertex.cpp b/source/obs/gs/gs-vertex.cpp index c793310f..53320161 100644 --- a/source/obs/gs/gs-vertex.cpp +++ b/source/obs/gs/gs-vertex.cpp @@ -18,6 +18,7 @@ */ #include "gs-vertex.hpp" +#include #include "util-memory.hpp" gs::vertex::vertex() diff --git a/source/obs/obs-source-tracker.cpp b/source/obs/obs-source-tracker.cpp index 1347a34e..1cdd44bf 100644 --- a/source/obs/obs-source-tracker.cpp +++ b/source/obs/obs-source-tracker.cpp @@ -18,6 +18,7 @@ */ #include "obs-source-tracker.hpp" +#include static std::shared_ptr source_tracker_instance; diff --git a/source/obs/obs-source.cpp b/source/obs/obs-source.cpp index 5f61f2c8..7b3b6262 100644 --- a/source/obs/obs-source.cpp +++ b/source/obs/obs-source.cpp @@ -18,6 +18,7 @@ */ #include "obs-source.hpp" +#include void obs::source::handle_destroy(void* p, calldata_t* calldata) { diff --git a/source/obs/obs-tools.cpp b/source/obs/obs-tools.cpp index 91c35733..763521e8 100644 --- a/source/obs/obs-tools.cpp +++ b/source/obs/obs-tools.cpp @@ -18,6 +18,7 @@ */ #include "obs-tools.hpp" +#include #include struct scs_searchdata { diff --git a/source/plugin.cpp b/source/plugin.cpp index 6607b5b6..62bfdaee 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -18,6 +18,7 @@ */ #include "plugin.hpp" +#include #include "obs/obs-source-tracker.hpp" #include "filters/filter-blur.hpp" #include "filters/filter-color-grade.hpp" diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index 04beed26..54c96f40 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -18,6 +18,7 @@ */ #include "source-mirror.hpp" +#include #include #include #include diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index c1771b2f..974c65ec 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -18,6 +18,7 @@ */ #include "source-shader.hpp" +#include #include "strings.hpp" #include "utility.hpp" diff --git a/source/util-math.cpp b/source/util-math.cpp index 60a7af92..6c6530c4 100644 --- a/source/util-math.cpp +++ b/source/util-math.cpp @@ -18,6 +18,7 @@ */ #include "util-math.hpp" +#include #include #include #include "util-memory.hpp" diff --git a/source/util-memory.cpp b/source/util-memory.cpp index a311a123..0e8d10cb 100644 --- a/source/util-memory.cpp +++ b/source/util-memory.cpp @@ -18,6 +18,7 @@ */ #include "util-memory.hpp" +#include #include #define USE_STD_ALLOC_FREE diff --git a/source/utility.cpp b/source/utility.cpp index d03c44cc..839542a0 100644 --- a/source/utility.cpp +++ b/source/utility.cpp @@ -18,6 +18,7 @@ */ #include "utility.hpp" +#include #include #include "plugin.hpp"