diff --git a/CMakeLists.txt b/CMakeLists.txt index e4ae39d5..5552e492 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -845,6 +845,9 @@ if(REQUIRE_SHADER_CODE) "source/gfx/shader/gfx-shader-param-texture.hpp" "source/gfx/shader/gfx-shader-param-texture.cpp" ) + list(APPEND PROJECT_DATA + "data/examples/shaders/feature-test.effect" + ) endif() # Combine it all diff --git a/data/examples/shaders/feature-test.effect b/data/examples/shaders/feature-test.effect new file mode 100644 index 00000000..b8cad0a2 --- /dev/null +++ b/data/examples/shaders/feature-test.effect @@ -0,0 +1,113 @@ +// -------------------------------------------------------------------------------- +// Uniforms set by libobs +uniform float4x4 ViewProj< + bool automatic = true; +>; + +// -------------------------------------------------------------------------------- +// Uniforms set by StreamFX +uniform float4 Time< + bool automatic = true; +>; +uniform float4 ViewSize< + bool automatic = true; +>; + +// Filters, Transitions +uniform texture2d InputA< + bool automatic = true; +>; + +// Transitions +uniform texture2d InputB< + bool automatic = true; +>; +uniform float TransitionTime< + bool automatic = true; +>; + +// -------------------------------------------------------------------------------- +// Parameters +uniform bool BoolParameter = false; +uniform float FloatParameter< + string name = "Float Parameter"; + string description = "This is a 32-bit floating point value."; + string field_type = "input"; + string suffix = " %"; + float minimum = -100.; + float maximum = 100.; + float step = .5; + float scale = .01; +> = 0.; +uniform float2 Float2Parameter< + string name = "Float2 Parameter"; + string description = "This is a 32-bit floating point value."; + string field_type = "input"; + string suffix = " %"; + float2 minimum = {-100., -100.}; + float2 maximum = {100., 100.}; + float2 step = {.5, .5}; + float2 scale = {.01, .01}; +> = {0., 0.}; +uniform float3 Float3Parameter = {0., 0., 0.}; +uniform float4 Float4Parameter = {0., 0., 0., 0.}; +uniform int IntParameter< + string name = "Enum Parameter"; + string description = "This parameter is an enumeration"; + string field_type = "enum"; + // Enumeration + int enum = 4; + int enum_0 = 0; + string enum_0_name = "Null"; + int enum_1 = 1; + string enum_1_name = "One"; + int enum_2 = 2; + string enum_2_name = "Two"; + int enum_3 = 4; + string enum_3_name = "Four"; +> = 0; +uniform int2 Int2Parameter = {0, 0}; +uniform int3 Int3Parameter = {0, 0, 0}; +uniform int4 Int4Parameter = {0, 0, 0, 0}; + +// -------------------------------------------------------------------------------- +// Vertex Processing +struct VertexData { + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +VertexData VSDefault(VertexData vtx) { + vtx.pos = mul(float4(vtx.pos.xyz, 1.), ViewProj); + return vtx; +}; + +// -------------------------------------------------------------------------------- +// Default Technique +float4 PSDefault(VertexData vtx) : TARGET { + if (BoolParameter) + vtx.uv += 1.; + vtx.uv += FloatParameter; + vtx.uv += Float2Parameter; + vtx.uv += Float3Parameter.xy * Float3Parameter.zz; + vtx.uv += Float4Parameter.xy * Float4Parameter.zz; + + if (IntParameter == 1) { + return float4(1., 0., 0., 1.); + } else if (IntParameter == 2) { + return float4(0., 1., 0., 1.); + } else if (IntParameter == 4) { + return float4(0., 0., 1., 1.); + } + + return float4(0., 0., 0., 1.); +} + +technique Draw +{ + pass + { + vertex_shader = VSDefault(vtx); + pixel_shader = PSDefault(vtx); + } +} diff --git a/source/gfx/shader/gfx-shader-param.cpp b/source/gfx/shader/gfx-shader-param.cpp index 3b92add7..3ffa0198 100644 --- a/source/gfx/shader/gfx-shader-param.cpp +++ b/source/gfx/shader/gfx-shader-param.cpp @@ -175,61 +175,6 @@ void gfx::shader::parameter::update(obs_data_t* settings) {} void gfx::shader::parameter::assign() {} -gs::effect_parameter gfx::shader::parameter::get_parameter() -{ - return _param; -} - -gfx::shader::parameter_type gfx::shader::parameter::get_type() -{ - return _type; -} - -std::size_t gfx::shader::parameter::get_size() -{ - return _size; -} - -int32_t gfx::shader::parameter::get_order() -{ - return _order; -} - -const std::string& gfx::shader::parameter::get_key() -{ - return _key; -} - -bool gfx::shader::parameter::is_visible() -{ - return _visible && !is_automatic(); -} - -bool gfx::shader::parameter::is_automatic() -{ - return _automatic; -} - -bool gfx::shader::parameter::has_name() -{ - return _name.length() > 0; -} - -const std::string& gfx::shader::parameter::get_name() -{ - return _name; -} - -bool gfx::shader::parameter::has_description() -{ - return _description.length() > 0; -} - -const std::string& gfx::shader::parameter::get_description() -{ - return _description; -} - std::shared_ptr gfx::shader::parameter::make_parameter(gs::effect_parameter param, std::string prefix) { diff --git a/source/gfx/shader/gfx-shader-param.hpp b/source/gfx/shader/gfx-shader-param.hpp index e28a5e29..2f10f162 100644 --- a/source/gfx/shader/gfx-shader-param.hpp +++ b/source/gfx/shader/gfx-shader-param.hpp @@ -81,27 +81,60 @@ namespace gfx { virtual void assign(); public: - gs::effect_parameter get_parameter(); + inline gs::effect_parameter get_parameter() + { + return _param; + } - parameter_type get_type(); + inline parameter_type get_type() + { + return _type; + } - std::size_t get_size(); + inline std::size_t get_size() + { + return _size; + } - int32_t get_order(); + inline int32_t get_order() + { + return _order; + } - const std::string& get_key(); + inline std::string_view get_key() + { + return _key; + } - bool is_visible(); + inline bool is_visible() + { + return _visible && !_automatic; + } - bool is_automatic(); + inline bool is_automatic() + { + return _automatic; + } - bool has_name(); + inline bool has_name() + { + return _name.length() > 0; + } - const std::string& get_name(); + inline std::string_view get_name() + { + return _name; + } - bool has_description(); + inline bool has_description() + { + return _description.length() > 0; + } - const std::string& get_description(); + inline std::string_view get_description() + { + return _description; + } public: static std::shared_ptr make_parameter(gs::effect_parameter param, std::string prefix); diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index 2e6a4f6b..52a4ed1e 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -509,9 +509,17 @@ void gfx::shader::shader::set_input_a(std::shared_ptr tex) if (!_shader) return; - if (gs::effect_parameter el = _shader.get_parameter("InputA"); el != nullptr) { - if (el.get_type() == gs::effect_parameter::type::Texture) { - el.set_texture(tex); + std::string_view params[] = { + "InputA", + "image", + "tex_a", + }; + for (auto& name : params) { + if (gs::effect_parameter el = _shader.get_parameter(name.data()); el != nullptr) { + if (el.get_type() == gs::effect_parameter::type::Texture) { + el.set_texture(tex); + break; + } } } } @@ -521,9 +529,17 @@ void gfx::shader::shader::set_input_b(std::shared_ptr tex) if (!_shader) return; - if (gs::effect_parameter el = _shader.get_parameter("InputB"); el != nullptr) { - if (el.get_type() == gs::effect_parameter::type::Texture) { - el.set_texture(tex); + std::string_view params[] = { + "InputB", + "image2", + "tex_b", + }; + for (auto& name : params) { + if (gs::effect_parameter el = _shader.get_parameter(name.data()); el != nullptr) { + if (el.get_type() == gs::effect_parameter::type::Texture) { + el.set_texture(tex); + break; + } } } } diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index 3497cf38..aa4fb041 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -38,7 +38,7 @@ namespace gfx { Transition, }; - typedef std::map> shader_param_map_t; + typedef std::map> shader_param_map_t; class shader { obs_source_t* _self;