mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-15 08:15:06 +00:00
5a3954ae0e
Fixes several files incorrectly stated a different license from the actual project, as well as the copyright headers included in all files. This change has no effect on the licensing terms, it should clear up a bit of confusion by contributors. Plus the files get a bit smaller, and we have less duplicated information across the entire project. Overall the project is GPLv2 if not built with Qt, and GPLv3 if it is built with Qt. There are no parts licensed under a different license, all have been adapted from other compatible licenses into GPLv2 or GPLv3.
137 lines
3.6 KiB
Text
137 lines
3.6 KiB
Text
// AUTOGENERATED COPYRIGHT HEADER START
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
|
|
|
// Always provided by OBS
|
|
uniform float4x4 ViewProj<
|
|
bool automatic = true;
|
|
string name = "View Projection Matrix";
|
|
>;
|
|
|
|
// Provided by Stream Effects
|
|
uniform float4 Time<
|
|
bool automatic = true;
|
|
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 automatic = true;
|
|
string name = "Random Array";
|
|
string description = "A float4x4 value containing random values between 0 and 1";
|
|
>;
|
|
uniform float4 ViewSize<
|
|
bool automatic = true;
|
|
>;
|
|
uniform texture2d InputA<
|
|
bool automatic = true;
|
|
>;
|
|
uniform texture2d InputB<
|
|
bool automatic = true;
|
|
>;
|
|
uniform float TransitionTime<
|
|
bool automatic = true;
|
|
>;
|
|
uniform int2 TransitionSize<
|
|
bool automatic = true;
|
|
>;
|
|
|
|
uniform bool _0_oldStyle<
|
|
string name = "Retro Style";
|
|
|
|
> = false;
|
|
uniform float2 _1_pixelateCenter<
|
|
string name = "Pixelation Center";
|
|
string field_type = "slider";
|
|
float2 minimum = {0., 0.};
|
|
float2 maximum = {100., 100.};
|
|
float2 scale = {0.01, 0.01};
|
|
> = {50., 50.};
|
|
uniform float _2_maximumBlockSize<
|
|
string name = "Maximum Pixelation";
|
|
string field_type = "slider";
|
|
float minimum = 1.0;
|
|
float maximum = 16.0;
|
|
float step = 1.0;
|
|
> = 12.;
|
|
uniform float2 _3_blockOffset<
|
|
string name = "Block Offset";
|
|
string field_type = "slider";
|
|
float2 minimum = {0., 0.};
|
|
float2 maximum = {100., 100.};
|
|
float2 scale = {0.01, 0.01};
|
|
> = {50., 50.};
|
|
uniform float _4_transitionRange<
|
|
string name = "Transition Range";
|
|
string field_type = "slider";
|
|
float minimum = 0.;
|
|
float maximum = 100.;
|
|
float scale = .005;
|
|
float step = .01;
|
|
> = 25.0;
|
|
|
|
// ---------- Shader Code
|
|
sampler_state def_sampler {
|
|
AddressU = Clamp;
|
|
AddressV = Clamp;
|
|
Filter = Linear;
|
|
};
|
|
|
|
struct VertData {
|
|
float4 pos : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
VertData VSDefault(VertData v_in) {
|
|
VertData vert_out;
|
|
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
|
vert_out.uv = v_in.uv;
|
|
return vert_out;
|
|
}
|
|
|
|
float4 PSDefault(VertData v_in) : TARGET {
|
|
float animProgress = TransitionTime;
|
|
|
|
// Progress as a bounce value (0..1..0)
|
|
float animStuff = 1.0 - (abs(animProgress - 0.5) * 2.0);
|
|
// There are two ways to calculate this, one is pixel aligned the other is block aligned.
|
|
float animBlockSize = 0;
|
|
if (_0_oldStyle) {
|
|
// Block Size, always a multiple of 2. (Block Aligned)
|
|
animBlockSize = pow(2.0, floor(_2_maximumBlockSize * animStuff));
|
|
} else {
|
|
// Block Size, always a multiple of 2. (Pixel Aligned)
|
|
animBlockSize = floor(pow(2.0, _2_maximumBlockSize * animStuff));
|
|
}
|
|
|
|
// UV Calculations
|
|
float2 finalUV = v_in.uv;
|
|
finalUV -= _1_pixelateCenter; // Offset by the pixelation center.
|
|
finalUV *= ViewSize.xy; // Convert to 0..Resolution UVs for pixelation.
|
|
finalUV /= animBlockSize; // Divide by current block size.
|
|
finalUV = floor(finalUV) + _3_blockOffset; // Use floor() on it to get aligned pixels.
|
|
finalUV *= animBlockSize; // Multiply by current block size.
|
|
finalUV *= ViewSize.zw; // Convert back to 0..1 UVs for texture sampling.
|
|
finalUV += _1_pixelateCenter; // Revert the offset by the pixelation center again.
|
|
|
|
float4 sampleA = InputA.Sample(def_sampler, finalUV);
|
|
float4 sampleB = InputB.Sample(def_sampler, finalUV);
|
|
|
|
float transition = clamp(
|
|
((TransitionTime - 0.5) / _4_transitionRange) * .5 + .5,
|
|
0.,
|
|
1.
|
|
);
|
|
|
|
float4 rgb = lerp(sampleA, sampleB, transition);
|
|
|
|
return rgb;
|
|
}
|
|
|
|
technique Draw
|
|
{
|
|
pass
|
|
{
|
|
vertex_shader = VSDefault(v_in);
|
|
pixel_shader = PSDefault(v_in);
|
|
}
|
|
}
|