mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-05 01:27:26 +00:00
edd1162a48
A lot of the blur effects share quite a bit of code, which can be offloaded into a single include.
97 lines
2.9 KiB
Text
97 lines
2.9 KiB
Text
#include "common.effect"
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Defines
|
|
//------------------------------------------------------------------------------
|
|
#define MAX_BLUR_SIZE 128
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Technique: Directional / Area
|
|
//------------------------------------------------------------------------------
|
|
float4 PSBlur1D(VertexInformation vtx) : TARGET {
|
|
float4 final = pImage.Sample(LinearClampSampler, vtx.uv) * kernelAt(0);
|
|
|
|
// Loop unrolling is only possible with a fixed known maximum.
|
|
// Some compilers may unroll up to x iterations, but most will not.
|
|
for (int n = 1; n <= MAX_BLUR_SIZE; n++) {
|
|
float2 nstep = (pImageTexel * pStepScale) * n;
|
|
float kernel = kernelAt(n);
|
|
final += pImage.Sample(LinearClampSampler, vtx.uv + nstep) * kernel;
|
|
final += pImage.Sample(LinearClampSampler, vtx.uv - nstep) * kernel;
|
|
|
|
if (n >= pSize) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return final;
|
|
}
|
|
|
|
technique Draw {
|
|
pass {
|
|
vertex_shader = VSDefault(vtx);
|
|
pixel_shader = PSBlur1D(vtx);
|
|
}
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Technique: Rotate
|
|
//------------------------------------------------------------------------------
|
|
float4 PSRotate(VertexInformation vtx) : TARGET {
|
|
float4 final = pImage.Sample(LinearClampSampler, vtx.uv) * kernelAt(0);
|
|
|
|
float angstep = pAngle * pStepScale.x;
|
|
|
|
// Loop unrolling is only possible with a fixed known maximum.
|
|
// Some compilers may unroll up to x iterations, but most will not.
|
|
for (int n = 1; n <= MAX_BLUR_SIZE; n++) {
|
|
float kernel = kernelAt(n);
|
|
final += pImage.Sample(LinearClampSampler, rotateAround(vtx.uv, pCenter, angstep * n)) * kernel;
|
|
final += pImage.Sample(LinearClampSampler, rotateAround(vtx.uv, pCenter, angstep * -n)) * kernel;
|
|
|
|
if (n >= pSize) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return final;
|
|
}
|
|
|
|
technique Rotate {
|
|
pass {
|
|
vertex_shader = VSDefault(vtx);
|
|
pixel_shader = PSRotate(vtx);
|
|
}
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Technique: Zoom
|
|
//------------------------------------------------------------------------------
|
|
float4 PSZoom(VertexInformation vtx) : TARGET {
|
|
float4 final = pImage.Sample(LinearClampSampler, vtx.uv) * kernelAt(0);
|
|
|
|
// step is calculated from the direction relative to the center
|
|
float2 dir = normalize(vtx.uv - pCenter) * pStepScale * pImageTexel;
|
|
float dist = distance(vtx.uv, pCenter);
|
|
|
|
// Loop unrolling is only possible with a fixed known maximum.
|
|
// Some compilers may unroll up to x iterations, but most will not.
|
|
for (int n = 1; n <= MAX_BLUR_SIZE; n++) {
|
|
float kernel = kernelAt(n);
|
|
final += pImage.Sample(LinearClampSampler, vtx.uv + (dir * n) * dist) * kernel;
|
|
final += pImage.Sample(LinearClampSampler, vtx.uv - (dir * n) * dist) * kernel;
|
|
|
|
if (n >= pSize) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return final;
|
|
}
|
|
|
|
technique Zoom {
|
|
pass {
|
|
vertex_shader = VSDefault(vtx);
|
|
pixel_shader = PSZoom(vtx);
|
|
}
|
|
}
|