Skip to content

Commit

Permalink
obs-shaderfilter: Version 1.2
Browse files Browse the repository at this point in the history
Add new standard parameters (loops, local time, 2 new random numbers)
Update UI
Update filter templates
Add fire shader
Add matrix effect
Add Night Sky background
Update Readme
  • Loading branch information
Oncorporation committed Jul 10, 2020
1 parent c7a1525 commit f2cf0b5
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 98 deletions.
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# obs-shaderfilter 1.11
# obs-shaderfilter 1.2

## Introduction

Expand Down Expand Up @@ -51,7 +51,7 @@ that need to render outside the bounds of the original source.

Normally, all that's required for OBS purposes is a pixel shader, so the plugin will wrap your shader text with a
standard template to add a basic vertex shader and other boilerplate. If you wish to customize the vertex shader
or other parts of the effect for some reason, you can check the "Override entire effect" option.
or other parts of the effect for some reason, you can check the "Use Effect File (.effect)" option.

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`
Expand All @@ -77,8 +77,12 @@ handle these variables being missing, but the shader may malfunction.)
* **`image`** (`texture2d`)—The image to which the filter is being applied, either the original output of
the source or the output of the previous filter in the chain. (Standard for all OBS filters.)
* **`elapsed_time`** (`float`)—The time in seconds which has elapsed since the filter was created. Useful for
creating animations.
* **`rand_f`** (`float`)— a random float between 0 and 1.
creating animations.
* **`local_time`** (`float`)— a random float representing the local time.(1.2)
* **`loops`** (`int`)— count of how many loops times the shader has rendered a page.(1.2)
* **`rand_f`** (`float`)— a random float between 0 and 1. changes per frame.
* **`rand_activation_f`** (`float`)— a random float between 0 and 1. changes per activation, load or change of settings.(1.2)
* **`rand_instance_f`** (`float`)— a random float between 0 and 1. changes per instance on load.(1.2)
* **`uv_offset`** (`float2`)—The offset which should be applied to the UV coordinates of the vertices. This is
used in the standard vertex shader to draw extra pixels on the borders of the source.
* **`uv_scale`** (`float2`)—The scale which should be applied to the UV coordinates of the vertices. This is
Expand All @@ -89,8 +93,10 @@ handle these variables being missing, but the shader may malfunction.)
texture, or otherwise scale UV coordinate distances into texel distances.

### New Options in version 1.1+
* *Use Slider Inputs— Converts Integer and floating point inputs into sliders in the UI.
* *Use Shader Time—Start the effect from the loadtime of the shader, not the start up time of OBS Studio.
* **`Use Slider Inputs`**— Converts Integer and floating point inputs into sliders in the UI.
* **`Use Shader Time`**—Start the effect from the loadtime of the shader, not the start up time of OBS Studio.
* **`Override Entire Effect`** renamed **`Use Effect File (.effect)`** in UI and documentation
* Textures moved from the shaders folder to the textures folder. Existing textures are not deleted so as to not disrupt you current scenes.(1.2)

### Example shaders

Expand All @@ -102,29 +108,36 @@ loaded.
I recommend *.shader* as they do not require `override_entire_effect` as pixel shaders, while *.effect* signifies vertex shaders with `override_entire_effect` required.

* *animated_texture.effect*— Animates a texture with polar sizing and color options
* *ascii.shader*— a little example of ascii art
* *background_removal.effect*— simple implementation of background removal. Optional color space corrections
* *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.
* *bloom.shader / glow.shader*— simple shaders to add glow or bloom effects, the glow shader has some additional options for animation
* *cartoon.effect* (Overrides entire effect)— Simple Cartooning based on hue and steps of detail value.
* *cartoon.effect* (Use Effect File (.effect))— Simple Cartooning based on hue and steps of detail value.
* *border.shader*—A shader that adds a solid border to all extra pixels outside the bounds of the input.
* *drop_shadow.shader*—A shader that adds a basic drop shadow to the input. Note that this is done with a simple
uniform blur, so it won't look quite as good as a proper Gaussian blur. This is also an O(N²) blur on the size
of the blur, so be very conscious of your GPU usage with a large blur size.
* *edge_detection.shader*—A shader that detects edges of color. Includes support for alpha channels.
* *filter_template.effect* (Overrides entire effect)—A copy of the default effect used by the plugin, which simply
* *filter_template.effect* (Use Effect File (.effect))—A copy of the default effect used by the plugin, which simply
renders the input directly to the output after scaling UVs to reflect any extra border pixels. This is useful as a starting
point for developing new effects, especially those that might need a custom vertex shader. (Note that modifying this file will
not affect the internal effect template used by the plugin.)
* *filter_template.shader* —A copy of the default shader used by the plugin, which simply
renders the input directly to the output after scaling UVs to reflect any extra border pixels. This is useful as a starting
point for developing new pixel shaders. (Note that modifying this file will not affect the internal effect template used by the plugin.)
* *fire.shader*— A fire example converted from shadertoy
* *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.
* *matrix.effect*— The cat is a glitch conversion from shadertoy. Updated with several configurable options.(1.2)
* *multiply.shader*—A shader that multiplies the input by another image specified in the parameters. Demonstrates the use
of user-defined `texture2d` parameters.
* *perlin_noise.effect* (Overrides entire effect)—An effect generates perlin_noise, used to make water, clouds and glitch effects.
* *pulse.effect* (Overrides entire effect)—An effect that varies the size of the output over time. This demonstrates
* *night_sky.shader*— Animated moon, clouds, stars background(1.2)
* *perlin_noise.effect* (Use Effect File (.effect))—An effect generates perlin_noise, used to make water, clouds and glitch effects.
* *pulse.effect* (Use Effect File (.effect))—An effect that varies the size of the output over time. This demonstrates
a custom vertex shader that manipulates the position of the rendered vertices based on user data. Note that moving the vertices
in the vertex shader will not affect the logical size of the source in OBS, and this may mean that pixels outside the source's
bounds will get cut off by later filters in the filter chain.
Expand All @@ -134,14 +147,14 @@ I recommend *.shader* as they do not require `override_entire_effect` as pixel s
Pixels inside the bounds of the input are treated as solid; pixels outside are treated as opaque. The complexity of the blur
does not increase with its size, so you should be able to make your blur size as large as you like wtihout affecting
GPU load.
* *repeat.effect* (Overrides entire effect)—Duplicates the input video as many times as you like and organizes on the screen.
* *repeat.effect* (Use Effect File (.effect))—Duplicates the input video as many times as you like and organizes on the screen.
* *rgb_color_wheel.shader—A rotatable RGB color wheel!
* *rotatoe.effect* (Overrides entire effect)—A test rotation effect
* *rotatoe.effect* (Use Effect File (.effect))—A test rotation effect
* *rounded_rect.shader*—A shader that rounds the corners of the input, optionally adding a border outside the rounded
edges.
* *scan_line.shader*—An effect that creates old style tv scan lines, for glitch style effects.
* *selective_color.shader*—Create black and white effects with some colorization. (defaults: .4,.03,.25,.25, 5.0, true,true, true, true. cuttoff higher = less color, 0 = all 1 = none)
* *shake.effect* (Overrides entire effect)—creates random screen glitch style shake. Keep the random_scale low for small (0.2-1) for small
* *shake.effect* (Use Effect File (.effect))—creates random screen glitch style shake. Keep the random_scale low for small (0.2-1) for small
jerky movements and larger for less often big jumps.
* *spotlight.shader*—Creates a stationary or animated spotlight effect with color options, speed of animation and glitch
* *shine.shader*—Add shine / glow to any element, use the transition luma wipes (obs-studio\plugins\obs-transitions\data\luma_wipes *SOME NEW WIPES INCLUDED IN THIS RELEASE ZIP*) or create your own,
Expand All @@ -151,7 +164,7 @@ I recommend *.shader* as they do not require `override_entire_effect` as pixel s
suggested default settings is opacity 0.5, innerRadius = 0.5, outerRadius = 1.2
* *zoom_blur.shader*—A shader that creates a zoom with blur effect based on a number of samples and magnitude of each sample. It also includes
an animation with or without easing and a glitch option. Set speed to zero to not use animation. Suggested values are 15 samples and 30-50 magnitude.
* *other*— I have far too many shaders to list. Please check [Examples folder](https://github.com/Oncorporation/obs-shaderfilter/tree/master/data/examples)
* *other*— We have far too many shaders to list. Please check [Examples folder](https://github.com/Oncorporation/obs-shaderfilter/tree/master/data/examples)
or find me on discord, as I have many additional filters for fixing input problems.

## Building
Expand Down Expand Up @@ -180,5 +193,5 @@ mess to deal with and I don't like it.

## Donations

I appreciate donations on twitch.tv/surn , [Bitcoin](bitcoin:3HAN6eVxv81URgj51wxeCd9eMhg3tvriro) or [LiteCoin](litecoin:MQFVTFCZUtcucZJzQCyiSDTirrWGqTyCjM).
Why Crypto? You do not have free speech when you live in fear of everything being taken away on an authoritarian whim, a criminal plot or by a outraged mob.
I appreciate donations/follows/subs on twitch.tv/surn , [Bitcoin](bitcoin:3HAN6eVxv81URgj51wxeCd9eMhg3tvriro) or [LiteCoin](litecoin:MQFVTFCZUtcucZJzQCyiSDTirrWGqTyCjM).
Why Crypto? We do not have free speech when we live in fear of everything being taken away on an authoritarian whim, a criminal plot or an outraged mob?
23 changes: 21 additions & 2 deletions data/examples/filter_template.effect
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
//My effect modified to by Me for use with obs-shaderfilter month/year v.01
uniform float4x4 ViewProj;
uniform texture2d image;

//Section to converting GLSL to HLSL - can delete
#define vec2 float2
#define vec3 float3
#define vec4 float4
#define ivec2 int2
#define ivec3 int3
#define ivec4 int4
#define mat2 float2x2
#define mat3 float3x3
#define mat4 float4x4
#define fract frac
#define mix lerp
#define iTime float

uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float2 uv_size;
uniform string notes;
uniform float rand_f;
uniform float rand_instance_f;
uniform float rand_activation_f;
uniform int loops;
uniform float local_time;
uniform string notes = "add notes here";

sampler_state textureSampler {
Filter = Linear;
Expand Down
51 changes: 31 additions & 20 deletions data/examples/filter_template.shader
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
//My shader modified to by Me for use with obs-shaderfilter month/year v.01

//Section to converting GLSL to HLSL - can delete
#define vec2 float2
#define vec3 float3
#define vec4 float4
#define ivec2 int2
#define ivec3 int3
#define ivec4 int4
#define mat2 float2x2
#define mat3 float3x3
#define mat4 float4x4
#define fract frac
#define mix lerp
#define iTime float

/*
**Shaders have these variables pre loaded by the plugin**
**this section can be deleted**
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float2 uv_size;
uniform float rand_f;
uniform float rand_instance_f;
uniform float rand_activation_f;
uniform int loops;
uniform float local_time;
*/
uniform string notes = "add notes here";

sampler_state textureSampler {
Filter = Linear;
AddressU = Border;
AddressV = Border;
BorderColor = 00000000;
};

struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};

VertData mainTransform(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv * uv_scale + uv_offset;
return vert_out;
}

float4 mainImage(VertData v_in) : TARGET
{
return image.Sample(textureSampler, v_in.uv);
}

/*
**Shaders use the built in Draw technique**
**this section can be deleted**
technique Draw
{
pass
Expand All @@ -42,3 +52,4 @@ technique Draw
pixel_shader = mainImage(v_in);
}
}
*/
132 changes: 132 additions & 0 deletions data/examples/fire.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//fire shader modified by Charles Fettinger for use with obs-shaderfilter 07/20 v.01
// https://github.com/Oncorporation/obs-shaderfilter plugin
// https://www.shadertoy.com/view/MtcGD7 original version

//Section to converting GLSL to HLSL - can delete
#define vec2 float2
#define vec3 float3
#define vec4 float4
#define ivec2 int2
#define ivec3 int3
#define ivec4 int4
#define mat2 float2x2
#define mat3 float3x3
#define mat4 float4x4
#define fract frac
#define mix lerp
//#define iTime float

/*
**Shaders have these variables pre loaded by the plugin**
**this section can be deleted**
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
uniform float2 uv_size;
uniform float rand_f;
uniform float rand_instance_f;
uniform float rand_activation_f;
uniform int loops;
uniform float local_time;
*/
uniform string notes = "add notes here";

uniform bool Invert_Direction <
string name = "Invert Direction";
> = true;

vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));

float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

float rand(vec2 n)
{
return fract(sin(cos(dot(n, vec2(12.9898, 12.1414)))) * 83758.5453);
//return rand_f;
}

float noise(vec2 n)
{
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0, 0.0), vec2(1.0, 1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}

float fbm(vec2 n)
{
float total = 0.0, amplitude = 1.0;
for (int i = 0; i < 5; i++)
{
total += noise(n) * amplitude;
n += n * 1.7;
amplitude *= 0.47;
}
return total;
}

float4 mainImage(VertData v_in) : TARGET
{
//float4 rgba = image.Sample(textureSampler, v_in.uv);
float2 iResolution = 1 - v_in.uv + float2( .99, 1.15);
float iTime = elapsed_time;

const vec3 c1 = vec3(0.5, 0.0, 0.1);
const vec3 c2 = vec3(0.9, 0.1, 0.0);
const vec3 c3 = vec3(0.2, 0.1, 0.7);
const vec3 c4 = vec3(1.0, 0.9, 0.1);
const vec3 c5 = vec3(0.1, 0.1, 0.1);
const vec3 c6 = vec3(0.9, 0.9, 0.9);

vec2 speed = vec2(1.2, 0.1);
float shift = 1.327 - sin(iTime * 2.0) / 2.4;
float alpha = 1.0;

//change the constant term for all kinds of cool distance versions,
//make plus/minus to switch between
//ground fire and fire rain!
float dist = 3.5 - sin(iTime * 0.4) / 1.89;

vec2 p = v_in.uv.xy * dist / iResolution.xx;
p.x -= iTime / 1.1;
float q = fbm(p - iTime * 0.01 + 1.0 * sin(iTime) / 10.0);
float qb = fbm(p - iTime * 0.002 + 0.1 * cos(iTime) / 5.0);
float q2 = fbm(p - iTime * 0.44 - 5.0 * cos(iTime) / 7.0) -6.0;
float q3 = fbm(p - iTime * 0.9 - 10.0 * cos(iTime) / 30.0) -4.0;
float q4 = fbm(p - iTime * 2.0 - 20.0 * sin(iTime) / 20.0) +2.0;
q = (q + qb - .4 * q2 - 2.0 * q3 + .6 * q4) / 3.8;
vec2 r = vec2(fbm(p + q / 2.0 - iTime* speed.x - p.x - p.y),
fbm(p - q - iTime* speed.y));
vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);
vec3 color = vec3(c * cos(shift * 1 - v_in.uv.y / iResolution.y));
color += .05;
color.r *= .8;
vec3 hsv = rgb2hsv(color);
hsv.y *= hsv.z * 1.1;
hsv.z *= hsv.y * 1.13;
hsv.y = (2.2 - hsv.z * .9) * 1.20;
color = hsv2rgb(hsv);

return vec4(color.x, color.y, color.z, alpha);
}



18 changes: 16 additions & 2 deletions data/examples/matrix.effect
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ uniform float2 uv_scale;
uniform float2 uv_size;
uniform float2 uv_pixel_interval;
uniform float rand_f;
uniform float rand_instance_f;
uniform float rand_activation_f;
uniform int loops;
uniform float local_time;


uniform float2 mouse<
string name = "Virtual Mouse Coordinates";
Expand Down Expand Up @@ -66,12 +71,21 @@ uniform bool Apply_To_Alpha_Layer = true;
float vorocloud(float2 p){
float f = 0.0;
float flow = 1.0;
float time = elapsed_time;
if(Invert_Direction){
flow *= -1;
}
/*
//periodically stop
if (loops % 16 >= 8.0)
{
time = local_time - elapsed_time;
}
*/

float r = clamp(Ratio,-50,50);
float2 pp = cos(float2(p.x * 14.0, (16.0 * p.y + cos(floor(p.x * 30.0)) + flow * elapsed_time * PI2)) );
p = cos(p * 12.1 + pp * r + sin(elapsed_time/PI)*(r/PI) + 0.5 * cos(pp.x * r + sin(elapsed_time/PI)*(r/PI)));
float2 pp = cos(float2(p.x * 14.0, (16.0 * p.y + cos(floor(p.x * 30.0)) + flow * time * PI2)) );
p = cos(p * 12.1 + pp * r + sin(time/PI)*(r/PI) + 0.5 * cos(pp.x * r + sin(time/PI)*(r/PI)));

float2 pts[4];

Expand Down
Loading

0 comments on commit f2cf0b5

Please sign in to comment.