mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-24 04:15:11 +00:00
gfx/blur/dual-filtering: Clean up code
Cleans up the code slightly, without affecting actual functionality
This commit is contained in:
parent
011bee032a
commit
733b325f98
4 changed files with 35 additions and 44 deletions
|
@ -37,7 +37,6 @@ uniform float4x4 ViewProj;
|
|||
uniform texture2d pImage;
|
||||
uniform float2 pImageSize;
|
||||
uniform float2 pImageTexel;
|
||||
uniform float2 pImageHalfTexel;
|
||||
uniform float pSize;
|
||||
uniform float pSizeInverseMul;
|
||||
uniform float pAngle;
|
||||
|
|
|
@ -4,15 +4,14 @@
|
|||
// Technique: Down
|
||||
//------------------------------------------------------------------------------
|
||||
float4 PSDown(VertexInformation vtx) : TARGET {
|
||||
//vtx.uv = ((floor(vtx.uv * pImageSize) + float2(0.5, 0.5)) * pImageTexel);
|
||||
|
||||
float4 pxCC = pImage.Sample(LinearClampSampler, vtx.uv) * 4.0;
|
||||
float4 pxTL = pImage.Sample(LinearClampSampler, vtx.uv - pImageHalfTexel);
|
||||
float4 pxTR = pImage.Sample(LinearClampSampler, vtx.uv + pImageHalfTexel);
|
||||
float4 pxBL = pImage.Sample(LinearClampSampler, vtx.uv + float2(pImageHalfTexel.x, -pImageHalfTexel.y));
|
||||
float4 pxBR = pImage.Sample(LinearClampSampler, vtx.uv - float2(pImageHalfTexel.x, -pImageHalfTexel.y));
|
||||
float4 pxTL = pImage.Sample(LinearClampSampler, vtx.uv - pImageTexel.xy);
|
||||
float4 pxTR = pImage.Sample(LinearClampSampler, vtx.uv + pImageTexel.xy);
|
||||
float4 pxBL = pImage.Sample(LinearClampSampler, vtx.uv + float2(pImageTexel.x, -pImageTexel.y));
|
||||
float4 pxBR = pImage.Sample(LinearClampSampler, vtx.uv - float2(pImageTexel.x, -pImageTexel.y));
|
||||
|
||||
return (pxCC + pxTL + pxTR + pxBL + pxBR) * 0.125;
|
||||
// return (pxCC + pxTL + pxTR + pxBL + pxBR) / 8;
|
||||
}
|
||||
|
||||
technique Down {
|
||||
|
@ -26,16 +25,14 @@ technique Down {
|
|||
// Technique: Up
|
||||
//------------------------------------------------------------------------------
|
||||
float4 PSUp(VertexInformation vtx) : TARGET {
|
||||
//vtx.uv = ((floor(vtx.uv * pImageSize) + float2(0.5, 0.5)) * pImageTexel);
|
||||
|
||||
float4 pxL = pImage.Sample(LinearClampSampler, vtx.uv - float2(pImageHalfTexel.x * 2.0, 0.));
|
||||
float4 pxBL = pImage.Sample(LinearClampSampler, vtx.uv - float2(pImageHalfTexel.x, -pImageHalfTexel.y));
|
||||
float4 pxB = pImage.Sample(LinearClampSampler, vtx.uv + float2(0., pImageHalfTexel.y * 2.0));
|
||||
float4 pxBR = pImage.Sample(LinearClampSampler, vtx.uv + pImageHalfTexel);
|
||||
float4 pxR = pImage.Sample(LinearClampSampler, vtx.uv + float2(pImageHalfTexel.x * 2.0, 0.));
|
||||
float4 pxTR = pImage.Sample(LinearClampSampler, vtx.uv + float2(pImageHalfTexel.x, -pImageHalfTexel.y));
|
||||
float4 pxT = pImage.Sample(LinearClampSampler, vtx.uv - float2(0., pImageHalfTexel.y * 2.0));
|
||||
float4 pxTL = pImage.Sample(LinearClampSampler, vtx.uv - pImageHalfTexel);
|
||||
float4 pxL = pImage.Sample(LinearClampSampler, vtx.uv + float2(-pImageTexel.x * 2, 0. ));
|
||||
float4 pxBL = pImage.Sample(LinearClampSampler, vtx.uv + float2(-pImageTexel.x, pImageTexel.y)); // * 2.0
|
||||
float4 pxB = pImage.Sample(LinearClampSampler, vtx.uv + float2( 0., pImageTexel.y * 2));
|
||||
float4 pxBR = pImage.Sample(LinearClampSampler, vtx.uv + float2( pImageTexel.x, pImageTexel.y)); // * 2.0
|
||||
float4 pxR = pImage.Sample(LinearClampSampler, vtx.uv + float2( pImageTexel.x * 2, 0. ));
|
||||
float4 pxTR = pImage.Sample(LinearClampSampler, vtx.uv + float2( pImageTexel.x, -pImageTexel.y)); // * 2.0
|
||||
float4 pxT = pImage.Sample(LinearClampSampler, vtx.uv + float2( 0., -pImageTexel.y * 2));
|
||||
float4 pxTL = pImage.Sample(LinearClampSampler, vtx.uv + float2(-pImageTexel.x, -pImageTexel.y)); // * 2.0
|
||||
|
||||
return (((pxTL + pxTR + pxBL + pxBR) * 2.0) + pxL + pxR + pxT + pxB) * 0.083333333333;
|
||||
// return (((pxTL + pxTR + pxBL + pxBR) * 2.0) + pxL + pxR + pxT + pxB) / 12;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
#include "gfx-blur-dual-filtering.hpp"
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include "obs/gs/gs-helper.hpp"
|
||||
#include "plugin.hpp"
|
||||
|
@ -180,7 +181,7 @@ std::shared_ptr<::streamfx::gfx::blur::dual_filtering_data> streamfx::gfx::blur:
|
|||
}
|
||||
|
||||
streamfx::gfx::blur::dual_filtering::dual_filtering()
|
||||
: _data(::streamfx::gfx::blur::dual_filtering_factory::get().data()), _size(0), _size_iterations(0)
|
||||
: _data(::streamfx::gfx::blur::dual_filtering_factory::get().data()), _size(0), _iterations(0)
|
||||
{
|
||||
auto gctx = streamfx::obs::gs::context();
|
||||
_rts.resize(ST_MAX_LEVELS + 1);
|
||||
|
@ -214,11 +215,8 @@ double_t streamfx::gfx::blur::dual_filtering::get_size()
|
|||
|
||||
void streamfx::gfx::blur::dual_filtering::set_size(double_t width)
|
||||
{
|
||||
_size = width;
|
||||
_size_iterations = size_t(round(width));
|
||||
if (_size_iterations >= ST_MAX_LEVELS) {
|
||||
_size_iterations = ST_MAX_LEVELS;
|
||||
}
|
||||
_size = width;
|
||||
_iterations = std::clamp<size_t>(static_cast<size_t>(round(width)), 0, ST_MAX_LEVELS);
|
||||
}
|
||||
|
||||
void streamfx::gfx::blur::dual_filtering::set_step_scale(double_t, double_t) {}
|
||||
|
@ -238,8 +236,6 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::dual_filterin
|
|||
return _input_texture;
|
||||
}
|
||||
|
||||
std::size_t actual_iterations = _size_iterations;
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_reset_blend_state();
|
||||
gs_enable_color(true, true, true, true);
|
||||
|
@ -253,36 +249,36 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::dual_filterin
|
|||
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
|
||||
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
|
||||
|
||||
uint32_t width = _input_texture->get_width();
|
||||
uint32_t height = _input_texture->get_height();
|
||||
uint32_t width = _input_texture->get_width();
|
||||
uint32_t height = _input_texture->get_height();
|
||||
size_t iterations = _iterations;
|
||||
|
||||
// Downsample
|
||||
for (std::size_t n = 1; n <= actual_iterations; n++) {
|
||||
for (std::size_t n = 1; n <= iterations; n++) {
|
||||
#ifdef ENABLE_PROFILING
|
||||
auto gdm = streamfx::obs::gs::debug_marker(streamfx::obs::gs::debug_color_azure_radiance, "Down %" PRIuMAX, n);
|
||||
#endif
|
||||
|
||||
// Select Texture
|
||||
std::shared_ptr<streamfx::obs::gs::texture> tex_cur;
|
||||
std::shared_ptr<streamfx::obs::gs::texture> tex;
|
||||
if (n > 1) {
|
||||
tex_cur = _rts[n - 1]->get_texture();
|
||||
tex = _rts[n - 1]->get_texture();
|
||||
} else { // Idx 0 is a simply considered as a straight copy of the original and not rendered to.
|
||||
tex_cur = _input_texture;
|
||||
tex = _input_texture;
|
||||
}
|
||||
|
||||
// Reduce Size
|
||||
uint32_t owidth = width >> n;
|
||||
uint32_t oheight = height >> n;
|
||||
if ((owidth <= 0) || (oheight <= 0)) {
|
||||
actual_iterations = n - 1;
|
||||
if ((owidth == 0) || (oheight == 0)) {
|
||||
iterations = n - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Apply
|
||||
effect.get_parameter("pImage").set_texture(tex_cur);
|
||||
effect.get_parameter("pImage").set_texture(tex);
|
||||
effect.get_parameter("pImageSize").set_float2(float_t(owidth), float_t(oheight));
|
||||
effect.get_parameter("pImageTexel").set_float2(1.0f / owidth, 1.0f / oheight);
|
||||
effect.get_parameter("pImageHalfTexel").set_float2(0.5f / owidth, 0.5f / oheight);
|
||||
effect.get_parameter("pImageTexel").set_float2(0.5f / owidth, 0.5f / oheight);
|
||||
|
||||
{
|
||||
auto op = _rts[n]->render(owidth, oheight);
|
||||
|
@ -294,25 +290,24 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::dual_filterin
|
|||
}
|
||||
|
||||
// Upsample
|
||||
for (std::size_t n = actual_iterations; n > 0; n--) {
|
||||
for (std::size_t n = iterations; n > 0; n--) {
|
||||
#ifdef ENABLE_PROFILING
|
||||
auto gdm = streamfx::obs::gs::debug_marker(streamfx::obs::gs::debug_color_azure_radiance, "Up %" PRIuMAX, n);
|
||||
#endif
|
||||
|
||||
// Select Texture
|
||||
std::shared_ptr<streamfx::obs::gs::texture> tex_in = _rts[n]->get_texture();
|
||||
std::shared_ptr<streamfx::obs::gs::texture> tex = _rts[n]->get_texture();
|
||||
|
||||
// Get Size
|
||||
uint32_t iwidth = width >> n;
|
||||
uint32_t iheight = height >> n;
|
||||
uint32_t iwidth = tex->get_width();
|
||||
uint32_t iheight = tex->get_height();
|
||||
uint32_t owidth = width >> (n - 1);
|
||||
uint32_t oheight = height >> (n - 1);
|
||||
|
||||
// Apply
|
||||
effect.get_parameter("pImage").set_texture(tex_in);
|
||||
effect.get_parameter("pImage").set_texture(tex);
|
||||
effect.get_parameter("pImageSize").set_float2(float_t(iwidth), float_t(iheight));
|
||||
effect.get_parameter("pImageTexel").set_float2(1.0f / iwidth, 1.0f / iheight);
|
||||
effect.get_parameter("pImageHalfTexel").set_float2(0.5f / iwidth, 0.5f / iheight);
|
||||
effect.get_parameter("pImageTexel").set_float2(0.5f / iwidth, 0.5f / iheight);
|
||||
|
||||
{
|
||||
auto op = _rts[n - 1]->render(owidth, oheight);
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace streamfx::gfx {
|
|||
std::shared_ptr<::streamfx::gfx::blur::dual_filtering_data> _data;
|
||||
|
||||
double_t _size;
|
||||
std::size_t _size_iterations;
|
||||
std::size_t _iterations;
|
||||
|
||||
std::shared_ptr<streamfx::obs::gs::texture> _input_texture;
|
||||
|
||||
|
|
Loading…
Reference in a new issue