Skip to content

Commit

Permalink
obs-shaderfilter: add defaults and update example
Browse files Browse the repository at this point in the history
shaders to use default values with notes
  • Loading branch information
Charles Fettinger committed Apr 6, 2019
1 parent 8470c0f commit 895b8b0
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 120 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# obs-shaderfilter
# obs-shaderfilter 1.1

## Introduction

Expand Down Expand Up @@ -28,6 +28,7 @@ necessary files should look like this:
| |---pulse.effect
| |---rectangular_drop_shadow.shader
| |---rounded_rect.shader
| |---many more...
| |---locale
| |---en-US.ini
|---obs-plugins
Expand Down Expand Up @@ -56,7 +57,12 @@ or other parts of the effect for some reason, you can check the "Override entire
Any parameters you add to your shader (defined as `uniform` variables) will be detected by the plugin and exposed
in the properties window to have their values set. Currently, only `int`, `float`, `bool`, `string`, `texture2d`, and `float4`
parameters are supported. (`float4` parameters will be interpreted by the properties window as colors.) `string` is used for
notes and instructions, but could be used in an effect or shader.
notes and instructions, but could be used in an effect or shader.

#### Defaults

You set default values as a normal assignment ```uniform string notes = 'my note';```, except for `float4`
which requires bracket \{\} notation like ```uniform float4 mycolor = { 0.75, 0.75, 0.75, 1.0};```

Note that if your shader has syntax errors and fails to compile, OBS does not provide any error messages; you will
simply see your source render nothing at all. In many cases the output of the effect parser will be written to the
Expand Down Expand Up @@ -88,7 +94,9 @@ handle these variables being missing, but the shader may malfunction.)
Several examples are provided in the plugin's *data/examples* folder. These can be used as-is for some hopefully
useful common tasks, or used as a reference in developing your own shaders. Note that the *.shader* and *.effect*
extensions are for clarity only, and have no specific meaning to the plugin. Text files with any extension can be
loaded.
loaded.

I recommend *.shader* do not require `override_entire_effect` as pixel shaders, while *.effect* signifies vertex shaders with `override_entire_effect` required.

* *blink.shader*—A shader that fades the opacity of the output in and out over time, with a configurable speed
multiplier. Demonstrates the user of the `elapsed_time` parameter.
Expand All @@ -105,6 +113,7 @@ loaded.
not affect the internal effect template used by the plugin.)
* *gradient.shader*— This shader has a little brother *simple_gradient.shader*, but lets you choose three colors and animate gradients.
* *glitch_analog.shader*—A shader that creates glitch effects similar to analog signal issues. Includes support for alpha channel.
* *hexagon.shader*—A shader that creates a grid of hexagons with several options for you to set. This is an example of making shapes.
* *luminance.shader*—A shader that adds an alpha layer based on brightness instead of color. Extremely useful for making live
video special effects, like replacing backgrounds or foregrounds.
* *multiply.shader*—A shader that multiplies the input by another image specified in the parameters. Demonstrates the use
Expand Down
4 changes: 2 additions & 2 deletions data/examples/Luminance.shader
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
uniform float4 color;
uniform float level;
uniform float level = 10;
uniform bool invertImageColor;
uniform bool invertAlphaChannel;

Expand Down Expand Up @@ -34,4 +34,4 @@ float4 mainImage(VertData v_in) : TARGET
rgba *= color;
rgba.a = clamp((intensity * level),0.0,1.0);
return rgba;
}
}
2 changes: 1 addition & 1 deletion data/examples/blink.shader
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uniform float speed;
uniform float speed = 0.5;

float4 mainImage(VertData v_in) : TARGET
{
Expand Down
12 changes: 7 additions & 5 deletions data/examples/bloom.shader
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Bloom shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
//https://github.com/Oncorporation/obs-shaderfilter

uniform int angleSteps = 12;
uniform int radiusSteps = 10;
uniform float ampFactor = 1.3;
uniform string notes = "";
uniform int Angle_Steps = 5; //<range 1 - 20>
uniform int Radius_Steps = 9; //<range 0 - 20>
uniform float ampFactor = 2.0;
uniform string notes = "Steps limited in range from 0 to 20. Edit bloom.shader to remove limits at your own risk.";

float4 mainImage(VertData v_in) : TARGET
{
float radiusSteps = clamp(Radius_Steps, 0, 20);
float angleSteps = clamp(Angle_Steps, 1, 20);
float PI = 3.1415926535897932384626433832795;//acos(-1);
float minRadius = (0.0 * uv_pixel_interval.y);
float maxRadius = (10.0 * uv_pixel_interval.y);
Expand Down Expand Up @@ -42,4 +44,4 @@ float4 mainImage(VertData v_in) : TARGET
outputPixel += accumulatedColor * ampFactor;

return outputPixel;
}
}
6 changes: 3 additions & 3 deletions data/examples/cartoon.effect
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float2 uv_size;
uniform string notes;
uniform string notes = "5/2 seems reasonable";

uniform int hue_steps;
uniform int value_steps;
uniform int hue_steps = 5;
uniform int value_steps = 2;

sampler_state textureSampler {
Filter = Linear;
Expand Down
7 changes: 4 additions & 3 deletions data/examples/cell_shaded.shader
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Cell Shaded shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
//https://github.com/Oncorporation/obs-shaderfilter

uniform int Angle_Steps = 5; //<range 1 - 20
uniform int Radius_Steps = 9; //<range 0 - 20
uniform int Angle_Steps = 5; //<range 1 - 20>
uniform int Radius_Steps = 9; //<range 0 - 20>
uniform float ampFactor = 2.0;
uniform string notes = "Steps limited in range from 0 to 20. Edit bloom.shader to remove limits at your own risk.";

float4 mainImage(VertData v_in) : TARGET
{
Expand Down Expand Up @@ -41,4 +42,4 @@ float4 mainImage(VertData v_in) : TARGET
accumulatedColor *= ampFactor;

return c0 - accumulatedColor; // Cell shaded style
}
}
7 changes: 4 additions & 3 deletions data/examples/drop_shadow.shader
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Drop Shadow shader modified by Charles Fettinger
// impose a limiter to keep from crashing the system
uniform int shadow_offset_x;
uniform int shadow_offset_y;
uniform int shadow_blur_size;
uniform int shadow_offset_x = 5;
uniform int shadow_offset_y = 5;
uniform int shadow_blur_size = 3;
uniform string notes = "blur size is limited to a max of 15 to ensure GPU";

uniform float4 shadow_color;

Expand Down
6 changes: 3 additions & 3 deletions data/examples/drunk.shader
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ float4 mainImage(VertData v_in) : TARGET

// convert input for vector math
float blur_amount = (float)blur /100;
float glow_amount = (float)glow_percent / 10;
float glow_amount = (float)glow_percent * 0.1;
float speed = (float)pulse_speed * 0.01;
float luminance_floor = float(min_brightness) /100;
float luminance_ceiling = float(max_brightness) /100;
float luminance_floor = float(min_brightness) * 0.01;
float luminance_ceiling = float(max_brightness) * 0.01;

float4 color = image.Sample(textureSampler, v_in.uv);
float4 temp_color = color;
Expand Down
2 changes: 1 addition & 1 deletion data/examples/edge_detection.shader
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uniform bool edge_multiply;
uniform float4 non_edge_color;
uniform bool non_edge_multiply;
uniform bool alpha_channel;
uniform float alpha_level;
uniform float alpha_level = 100;
uniform bool alpha_invert;
uniform float rand_f;

Expand Down
1 change: 1 addition & 0 deletions data/examples/filter_template.shader
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float2 uv_size;
uniform string notes = "add notes here";

sampler_state textureSampler {
Filter = Linear;
Expand Down
8 changes: 4 additions & 4 deletions data/examples/glitch_analog.shader
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

// analog glitch shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
//https://github.com/Oncorporation/obs-shaderfilter
uniform float scan_line_jitter_displacement; // (displacement, threshold)
uniform int scan_line_jitter_threshold_percent;
uniform float scan_line_jitter_displacement = 0.33; // (displacement, threshold)
uniform int scan_line_jitter_threshold_percent = 95;
uniform float vertical_jump_amount;
uniform float vertical_speed;// (amount, speed)
uniform float horizontal_shake;
Expand All @@ -11,7 +11,7 @@ uniform float color_drift_speed;// (amount, speed)
uniform int pulse_speed_percent = 0;
uniform int alpha_percent = 100;
uniform bool rotate_colors;
uniform string notes;
uniform string notes ="play with settings!";


float nrand(float x, float y)
Expand Down Expand Up @@ -62,4 +62,4 @@ float4 mainImage(VertData v_in) : TARGET
}

return float4(src1.x, src2.x, src1.y, alpha);
}
}
18 changes: 9 additions & 9 deletions data/examples/gradient.shader
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// gradient shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
//https://github.com/Oncorporation/obs-shaderfilter
uniform float4 start_color;
uniform float start_step;
uniform float4 middle_color;
uniform float middle_step;
uniform float4 end_color;
uniform float end_step;
uniform int alpha_percent = 100;
uniform float4 start_color = { 0.1, 0.3, 0.1, 1.0 };
uniform float start_step = 0.15;
uniform float4 middle_color = { 1.0, 1.0, 1.0, 1.0 };
uniform float middle_step = 0.4;
uniform float4 end_color = { 0.75, 0.75, 0.75, 1.0};
uniform float end_step = 0.9;
uniform int alpha_percent = 90;
uniform int pulse_speed = 0;
uniform bool ease;
uniform bool rotate_colors;
uniform bool horizontal;
uniform bool vertical;
uniform int gradient_center_width_percentage = 50;
uniform int gradient_center_height_percentage = 50;
uniform string notes;
uniform string notes = "gradient center items will change the center location. Pulse Speed greater than 0 will animate. Easing seem to be too fast.";

float EaseInOutCircTimer(float t, float b, float c, float d) {
t /= d / 2;
Expand Down Expand Up @@ -128,4 +128,4 @@ float4 mainImage(VertData v_in) : TARGET
return color;


}
}
63 changes: 63 additions & 0 deletions data/examples/hexagon.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Hexagon shader by Charles Fettinger for obs-shaderfilter plugin 4/2019
//https://github.com/Oncorporation/obs-shaderfilter

uniform float4 Hex_Color;
uniform int Alpha_Percent = 100;
uniform float Quantity = 25;
uniform int Border_Width = 15; // <- -15 to 85, -15 off top
uniform bool Blend;
uniform bool Equilateral;
uniform bool Zoom_Animate;
uniform int Speed_Percent = 100;
uniform bool Glitch;
uniform float Distort_X = 1.0;
uniform float Distort_Y = 1.0;
uniform float Offset_X = 0.0;
uniform float Offset_Y = 0.0;
uniform string notes= "Tiles:equilateral: around 12.33,nonequilateral: square rootable number. Distort of 1 is normal.";


// 0 on edges, 1 in non_edge
float hex(float2 p) {
float xyratio = 1;
if (Equilateral)
xyratio = uv_size.x /uv_size.y;

// calc p
p.x = mul(p.x,xyratio);
p.y += (floor(p.x) % 2.0)*0.5;
p = abs(((p % 1.0) - 0.5));
return abs(max(p.x*1.5 + p.y, p.y*2.0) -1);
}

float4 mainImage(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv * uv_scale + uv_offset);
float alpha = (float)Alpha_Percent * 0.01;
float quantity = clamp(sqrt(Quantity), 0.0, 100.0);
float border_width = clamp(float(Border_Width - 15), -15, 100) * 0.01;
float speed = (float)Speed_Percent * 0.01;
float time = (1 + sin(elapsed_time * speed))*0.5;
if (Zoom_Animate)
quantity *= time;

// create a (pos)ition reference, hex radius and smoothstep out the non_edge
float2 pos = float2(v_in.uv.x * max(0,Distort_X), (1 - v_in.uv.y) * max(0,Distort_Y)) * uv_scale + uv_offset + float2(Offset_X, Offset_Y);
if (Glitch)
quantity *= lerp(pos.x, pos.y, rand_f);
float2 p = (pos * quantity); // number of hexes to be created
float r = (1.0 -0.7)*0.5; // cell default radius
float non_edge = smoothstep(0.0, r + border_width, hex(p)); // approach border become edge

// make the border colorable - non_edge is scaled
float4 color = float4(non_edge, non_edge,non_edge,1.0) ;
if (non_edge < 1)
{
color = Hex_Color;
color.a = alpha;
if (Blend)
color = lerp(rgba, color, 1 - non_edge);
return lerp(rgba,color,alpha);
}
return lerp(rgba, color * rgba, alpha);
}
8 changes: 4 additions & 4 deletions data/examples/luminance2.shader
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
uniform float4 color;
uniform float lumaMax;
uniform float lumaMin;
uniform float lumaMaxSmooth;
uniform float lumaMinSmooth;
uniform float lumaMax = 1.05;
uniform float lumaMin = 0.01;
uniform float lumaMaxSmooth = 0.10;
uniform float lumaMinSmooth = 0.01;
uniform bool invertImageColor;
uniform bool invertAlphaChannel;
uniform string notes = "'luma max' - anything above will be transparent. 'luma min' - anything below will be transparent. 'luma(min or max)Smooth - make the transparency fade in or out by a distance. 'invert color' - inverts the color of the screen. 'invert alpha channel' - flips all settings on thier head, which is excellent for testing.";
Expand Down
15 changes: 8 additions & 7 deletions data/examples/perlin_noise.shader
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,20 @@ float pnoise(float2 P, float2 rep)
}
//The good bits~ adapting the noise generator for the plugin and giving some control over the shader
//todo: pseudorandom number generator w/ seed
uniform float speed;
uniform float speed = 0.5;
uniform bool animated;
uniform bool apply_to_channel;
uniform bool inverted;
uniform bool multiply;
uniform float speed_horizonal;
uniform float speed_vertical;
uniform float iterations;
uniform float speed_horizonal = 0.5;
uniform float speed_vertical = 0;
uniform float iterations = 4;
//how much c_noise do we want? white
uniform float white_noise;
uniform float white_noise = 0.5;
//how much p_noise do we want? black
uniform float black_noise;
//todo: s_noise (simplex)
uniform float black_noise = 0.5;
uniform string notes = "white noise and black noise and iterations.. enjoy!";

float2 noisePosition(float t){
return float2(sin(2.2 * t) - cos(1.4 * t), cos(1.3 * t) + sin(-1.9 *t));
}
Expand Down
4 changes: 2 additions & 2 deletions data/examples/pixelation.effect
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VertData mainTransform(VertData v_in)
return vert_out;
}

uniform float pixelation;// <float min = 1; float step = 0.1;>;
uniform float pixelation = 8;// <float min = 1; float step = 0.1;>;

float4 mainImage(VertData v_in) : TARGET
{
Expand All @@ -38,7 +38,7 @@ float4 mainImage(VertData v_in) : TARGET
pixelated_high = pixelated_low + ((strength - 1) / strength);

return (image.Sample(textureSampler, pixelated_low * uv_pixel_interval) +
image.Sample(textureSampler, pixelated_high * uv_pixel_interval)) / 2.0;
image.Sample(textureSampler, pixelated_high * uv_pixel_interval)) / 2.0;
}

technique Draw
Expand Down
8 changes: 6 additions & 2 deletions data/examples/pixelation.shader
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// pixelation shader by Charles Fettinger for obs-shaderfilter plugin 3/2019
// with help from SkeltonBowTV
// https://github.com/Oncorporation/obs-shaderfilter
uniform float Target_Width = 320;
uniform float Target_Height = 180;
uniform string notes = "adjust width and height to your screen dimension";

float4 mainImage(VertData v_in) : TARGET
{
float targetWidth = max(2.0, Target_Width);
float targetHeight = max(2.0, Target_Height);
const float PI = 3.14159265f;//acos(-1);
float2 tex1;
int pixelSizeX = uv_size.x / targetWidth;
int pixelSizeY = uv_size.y / targetWidth;
int pixelSizeY = uv_size.y / targetHeight;

int pixelX = v_in.uv.x * uv_size.x;
int pixelY = v_in.uv.y * uv_size.y;
Expand All @@ -19,4 +23,4 @@ float4 mainImage(VertData v_in) : TARGET
float4 c1 = image.Sample(textureSampler, tex1 );

return c1;
}
}
Loading

0 comments on commit 895b8b0

Please sign in to comment.