obs-StreamFX/data/examples/shaders/source/plasma.effect
2019-12-21 19:09:42 +01:00

149 lines
3.2 KiB
Text

// 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 float array of length 4, with the indexes being:\n[0] Time Visible in Seconds\n[1] Last Render Time\n[2] Current System Time (24h looping)\n[3] Random value between 0 and 1.";
>;
// Params
uniform float PlasmaUVScale <
bool visible = true;
int order = 0;
string name = "UV Scaling";
string suffix = " %";
string type = "slider";
float minimum = 1.0;
float maximum = 10000.0;
float step = 0.01;
float scale = 0.01;
> = 100.0;
uniform float PlasmaTwists <
bool visible = true;
int order = 1;
string name = "Twists";
string type = "slider";
float minimum = 0.01;
float maximum = 100.0;
float step = 0.01;
float scale = 3.1415926535897932384626433832795;
> = 1.0;
uniform float4 PlasmaLowColor <
bool visible = true;
int order = 2;
string name = "Color 1";
string type = "slider";
float minimum = -1000.0;
float maximum = 1000.0;
float step = 0.01;
float scale = 0.01;
> = {100.0, 0.0, 0.0, 100.0};
uniform float4 PlasmaMiddleColor <
bool visible = true;
int order = 3;
string name = "Color 2";
string type = "slider";
float minimum = -1000.0;
float maximum = 1000.0;
float step = 0.01;
float scale = 0.01;
> = {0.0, 100.0, 0.0, 100.0};
uniform float4 PlasmaHighColor <
bool visible = true;
int order = 4;
string name = "Color 3";
string type = "slider";
float minimum = -1000.0;
float maximum = 1000.0;
float step = 0.01;
float scale = 0.01;
> = {0.0, 0.0, 100.0, 100.0};;
struct StageData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
StageData VSDefault(StageData data) {
data.pos = mul(float4(data.pos.xyz, 1.0), ViewProj);
data.uv *= PlasmaUVScale;
return data;
}
float Plasma1(float2 uv, float t) {
return sin(uv.x * 10 + t);
}
float Plasma2(float2 uv, float t) {
return sin(10 * (uv.x*sin(t/2)+uv.y*cos(t/3))+t);
}
float Plasma3(float2 uv, float t) {
float cx = uv.x + .5*sin(t/5);
float cy = uv.y + .5*cos(t/3);
return sin(sqrt(100*(cx*cx+cy*cy)+1)+t);
}
float4 BasicPlasma(StageData data) : TARGET {
return float4(Plasma1(data.uv, Time[0]), Plasma2(data.uv, Time[0]), Plasma3(data.uv, Time[0]), 1.0);
}
technique Basic
{
pass
{
vertex_shader = VSDefault(data);
pixel_shader = BasicPlasma(data);
}
}
float4 Plasma(StageData data) : TARGET {
float a = Plasma1(data.uv, Time[0]);
float b = Plasma2(data.uv, Time[0]);
float c = Plasma3(data.uv, Time[0]);
float v = abs(sin((a + b + c) * (PlasmaTwists / 100.0)));
return float4(v,v,v, 1.0);
}
technique Draw
{
pass
{
vertex_shader = VSDefault(data);
pixel_shader = Plasma(data);
}
}
float4 ColoredPlasma(StageData data) : TARGET {
float a = Plasma1(data.uv, Time[0]);
float b = Plasma2(data.uv, Time[0]);
float c = Plasma3(data.uv, Time[0]);
float v = abs(sin((a + b + c) * (PlasmaTwists / 100.0)));
float v1 = clamp(v * 2.0, 0., 1.);
float v2 = clamp((v - 0.5) * 2.0, 0., 1.);
float3 col = lerp(lerp(PlasmaLowColor, PlasmaMiddleColor, v1), PlasmaHighColor, v2);
return float4(col, 1.0);
}
technique Colored
{
pass
{
vertex_shader = VSDefault(data);
pixel_shader = ColoredPlasma(data);
}
}