mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 18:41:14 +00:00
examples: New example source shaders
This commit is contained in:
parent
d13778b017
commit
3f5adab815
3 changed files with 241 additions and 79 deletions
|
@ -38,7 +38,7 @@ The subject line of a commit should begin with the prefix followed by a `: `, an
|
|||
### Prefixes
|
||||
- effects: Anything modifying generic effects like blur.effect, color-conversion.effect, mask.effect, etc.
|
||||
- locale: Changes in `/data/locale`.
|
||||
- shaders: Changes in `/data/shaders` that are not directly influenced by a change to custom shaders.
|
||||
- examples: Changes in `/data/examples` that are not directly influenced by a change to one of the filters, sources or transitions.
|
||||
- project: Changes to files like README, CONTRIBUTING, AUTHORS, etc.
|
||||
- cmake: Changes to CMake build scripts.
|
||||
- ci: Changes to Continuous Integration.
|
||||
|
|
|
@ -8,46 +8,65 @@ uniform float4x4 ViewProj<
|
|||
uniform float4 Time<
|
||||
bool visible = false;
|
||||
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.";
|
||||
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.";
|
||||
>;
|
||||
uniform float4x4 Random<
|
||||
/*uniform float4x4 Random<
|
||||
bool visible = false;
|
||||
string name = "Random Array";
|
||||
string description = "A float4x4 value containing random values between 0 and 1";
|
||||
string name = "Random Matrix";
|
||||
string description = "A float4x4 value containing random values between 0 and 1. Changes every frame.";
|
||||
>;
|
||||
uniform float4x4 Seed<
|
||||
bool visible = false;
|
||||
string name = "Seed Matrix";
|
||||
string description = "A float4x4 value containing random seeds values between 0 and 1. Values determined once on Source creation.";
|
||||
>;*/
|
||||
|
||||
// Shader Parameters
|
||||
uniform float4 p_my_val<
|
||||
// Parameters
|
||||
uniform bool BoolParameter<
|
||||
bool visible = true;
|
||||
string name = "Color";
|
||||
float4 minimum = {0., 0., 0., 0.};
|
||||
float4 maximum = {1., 1., 1., 1.};
|
||||
float4 step = {.01, .01, .01, .01};
|
||||
> = {0., 0., 0., 1.};
|
||||
|
||||
uniform float2 p_plasma1<
|
||||
string name = "Bool Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
/*uniform int IntParameter<
|
||||
bool visible = true;
|
||||
string name = "Plasma UV 1";
|
||||
string mode = "slider";
|
||||
float2 minimum = {0., 0.};
|
||||
float2 maximum = {1., 1.};
|
||||
float2 step = {.01, .01};
|
||||
> = {0.25, 0.25};
|
||||
uniform float2 p_plasma2<
|
||||
string name = "Int Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform int2 Int2Parameter<
|
||||
bool visible = true;
|
||||
string name = "Plasma UV 2";
|
||||
string mode = "slider";
|
||||
float2 minimum = {0., 0.};
|
||||
float2 maximum = {1., 1.};
|
||||
float2 step = {.01, .01};
|
||||
> = {0.75, 0.75};
|
||||
uniform float4 p_plasma_color<
|
||||
string name = "Int2 Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform int3 Int3Parameter<
|
||||
bool visible = true;
|
||||
string name = "Plasma Color";
|
||||
float4 minimum = {0., 0., 0., 0.};
|
||||
float4 maximum = {1., 1., 1., 1.};
|
||||
float4 step = {.01, .01, .01, .01};
|
||||
> = {1.0, 1.0, 1.0, 1.0};
|
||||
string name = "Int3 Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform int4 Int4Parameter<
|
||||
bool visible = true;
|
||||
string name = "Int4 Parameter";
|
||||
string description = "Example";
|
||||
>;*/
|
||||
uniform float FloatParameter<
|
||||
bool visible = true;
|
||||
string name = "Float Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform float2 Float2Parameter<
|
||||
bool visible = true;
|
||||
string name = "Float2 Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform float3 Float3Parameter<
|
||||
bool visible = true;
|
||||
string name = "Float3 Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
uniform float4 Float4Parameter<
|
||||
bool visible = true;
|
||||
string name = "Float4 Parameter";
|
||||
string description = "Example";
|
||||
>;
|
||||
|
||||
// ---------- Shader Code
|
||||
sampler_state def_sampler {
|
||||
|
@ -73,51 +92,12 @@ FragData VSDefault(VertData v_in) {
|
|||
return vert_out;
|
||||
}
|
||||
|
||||
// ---------- Random Color
|
||||
float4 PS_Random(FragData v_in) : TARGET {
|
||||
return float4(Random[0][0], Random[0][1], Random[0][2], 1.0);
|
||||
}
|
||||
|
||||
technique Random
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PS_Random(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Plasma Color
|
||||
float4 PS_Plasma(FragData v_in) : TARGET {
|
||||
float dst1 = distance(v_in.uv, p_plasma1);
|
||||
float dst2 = distance(v_in.uv, p_plasma2);
|
||||
|
||||
float dst1s = dst1 * dst1;
|
||||
float dst2s = dst2 * dst2;
|
||||
|
||||
float dst = min(dst1s, dst2s) * (50. + (1. + sin(Time.y * 5.0)) * 100.0);
|
||||
|
||||
float4 t;
|
||||
t.a = 1.;
|
||||
t.r = p_plasma_color.r * ((1. + sin(dst)) * .5);
|
||||
t.g = p_plasma_color.g * ((1. + cos(dst)) * .5);
|
||||
t.b = p_plasma_color.b * ((1. + sin(dst)) * .5) * ((1. + cos(dst)) * .5);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
technique Plasma
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PS_Plasma(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Fixed Color
|
||||
float4 PS_Fixed(FragData v_in) : TARGET {
|
||||
return p_my_val;
|
||||
float4 PSTime(FragData v_in) : TARGET {
|
||||
return float4(
|
||||
cos(Time[0] * 5.) * 0.5 + 0.5,
|
||||
cos(Time[0] * 0.) * 0.5 + 0.5,
|
||||
cos(Time[0] * 0.) * 0.5 + 0.5,
|
||||
1.0);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
|
@ -125,6 +105,77 @@ technique Draw
|
|||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PS_Fixed(v_in);
|
||||
pixel_shader = PSTime(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSBool(FragData v_in) : TARGET {
|
||||
if (BoolParameter)
|
||||
return float4(
|
||||
cos(Time[0] * 5.) * 0.5 + 0.5,
|
||||
cos(Time[0] * 0.) * 0.5 + 0.5,
|
||||
cos(Time[0] * 0.) * 0.5 + 0.5,
|
||||
1.0);
|
||||
return float4(0, 0, 0, 1.0);
|
||||
}
|
||||
|
||||
technique Bool
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSBool(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSFloat(FragData v_in) : TARGET {
|
||||
return float4(FloatParameter.xxx, 1.0);
|
||||
}
|
||||
|
||||
technique Float
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSFloat(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSFloat2(FragData v_in) : TARGET {
|
||||
return Float2Parameter.xxxy;
|
||||
}
|
||||
|
||||
technique Float2
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSFloat2(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSFloat3(FragData v_in) : TARGET {
|
||||
return float4(Float3Parameter, 1.0);
|
||||
}
|
||||
|
||||
technique Float3
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSFloat3(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSFloat4(FragData v_in) : TARGET {
|
||||
return Float4Parameter;
|
||||
}
|
||||
|
||||
technique Float4
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSFloat4(v_in);
|
||||
}
|
||||
}
|
||||
|
|
111
data/examples/shaders/source/plasma.effect
Normal file
111
data/examples/shaders/source/plasma.effect
Normal file
|
@ -0,0 +1,111 @@
|
|||
// 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 PlasmaScale<
|
||||
bool visible = true;
|
||||
string name = "Plasma Scale";
|
||||
float min = 100.0;
|
||||
float max = 1000.0;
|
||||
> = 100.0;
|
||||
uniform float3 LowColor<
|
||||
float min = 0.0;
|
||||
float max = 100.0;
|
||||
> = {0.0, 0.0, 0.0};
|
||||
uniform float3 MiddleColor<
|
||||
float min = 0.0;
|
||||
float max = 100.0;
|
||||
> = {0.5, 0.5, 0.5};
|
||||
uniform float3 HighColor<
|
||||
float min = 0.0;
|
||||
float max = 100.0;
|
||||
> = {1.0, 1.0, 1.0};
|
||||
|
||||
struct StageData {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
StageData VSDefault(StageData data) {
|
||||
data.pos = mul(float4(data.pos.xyz, 1.0), ViewProj);
|
||||
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) * (PlasmaScale / 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) * (PlasmaScale / 100.0)));
|
||||
|
||||
float v1 = clamp(v * 2.0, 0., 1.);
|
||||
float v2 = clamp((v - 0.5) * 2.0, 0., 1.);
|
||||
float3 col = lerp(lerp(LowColor, MiddleColor, v1), HighColor, v2);
|
||||
|
||||
return float4(col, 1.0);
|
||||
}
|
||||
|
||||
technique Colored
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(data);
|
||||
pixel_shader = ColoredPlasma(data);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue