Skip to content

Source Filter Transition Shader

Xaymar edited this page Nov 7, 2021 · 38 revisions

Shader Source/Filter/Transition Windows Linux MacOS Experimental

StreamFX ships with three different ways to use custom shaders in OBS Studio: Source Shader, Filter Shader and Transition Shader. Each has slightly different usage, but can mostly work with almost the same shader and allows you to easily use your own or someone elses shaders in OBS Studio. Shaders allow for quick iteration and enable some effects that were previously impossible.

Version Information
Status Version
Added 0.5
Unstable N/A
Stable N/A
Deprecated N/A
Removed N/A

Guides

Examples

(note: links are currently dead)

Settings

TODO

Writing Shaders

Syntax

The [] denote optional things, while the () denote required things. They are only used to illustrate the structure itself, and must be removed.

Generic Parameters

uniform (type) (name)<
  // 'true' to allow Users to see this parameters, 'false' to hide it. Enables invisible parameters which do special things with scripts.
  [bool visible = true;]
  // 'true' to completely disallow modification from outside. Useful for predefined parameters and values that are spread from other parameters.
  [bool automatic = false;]
  // Name used in the UI.
  [string name = "Name";]
  // Description used in the UI.
  [string description = "Description";]
  // DANGEROUS: Override the detected type with a specific one. Do not use unless you absolutely need it.
  [string type = "bool";] // Turn this into a boolean.
  [string type = "float";] // Turn this into a float.
  [string type = "int";] // Turn this into an integer.
  [string type = "string";] // Turn this into a string.
  [string type = "texture";] // Turn this into a texture.
  [string type = "sampler";] // Turn this into a sampler.
  // DANGEROUS: Override the detected size with a specified one. Do not use unless you absolutely need it.
  [int size = 1;]
>[ = (value)];

Value Parameters

A value parameter is one of the following types: float, float#, float[], float#x#, int, int#, int[], int#x#, uint, uint#, uint[], uint#x#, bool, bool#, bool[], bool#x#. Some types may require type and size overrides in order to be detected correctly.

uniform (type) (name)<
  // ... continued from Generic Parameters
  // Changes the field type to a different one.
  [string field_type = "input";]       // Standard input widget with manual entry and nothing fancy.
  [string field_type = "slider";]      // Horizontal slider with manual entry option.
  [string field_type = "enum";]        // Dropdown with enumeration entries, see "Enumeration Parameters".
  // Suffix for the values.
  [string suffix = " my awesome suffix";]
  // Minimum value that can be set.
  [(type) minimum = {...};] // Defaults to the smallest possible number.
  // Maximum value that can be set.
  [(type) maximum = {...};] // Defaults to the largest possible number.
  // The step of the value.
  [(type) step = {...};] // Defaults to 1.
  // The scale of the value, which is applied to everything. Can be used to greatly increase the precision of an property.
  [(type) scale = {...};] // Defaults to 1.
>[ = (value)];

Enumeration Parameters

A subset of value parameters where the selection is limited to a defined list of values, which can be defined in the shader. This can be useful to have users select from certain behavior instead of requiring them to enter numbers manually.

Entries in the list are limited to int, float and string, the three basic types of parameters. Vector types will simply act as an array of the basic type, and show a dropdown for each vector part. A float4 for example would allow the user to pick a value for r, g, b and a (or x, y, z and w).

uniform (type) (name)<
  // ... continued from Generic Parameters
  // Set the field type to enumeration.
  [string field_type = "enum";]        // Dropdown with enumeration entries.
  // Defines the #. enumeration entry of the list. # must be a continuously increasing number starting from 0.
  [(base type) enum_# = (value);] // The value of the enumeration entry.
  [string enum_#_name = "(name)";] // The name of the enumeration entry, optional. If not specified, defaults to "Unnamed Entry".
>[ = (value)];

Predefined Parameters

float4x4 ViewProj

Camera Projection Matrix, must be used in the Vertex Shader.

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

float4 Time

The current time since the creation of the shader, in seconds.

  • x: Time in seconds since the source was created. (float)
  • y: Time in the current second.
  • z: Time in seconds since the source was created. (rounded down to nearest integer)
  • w: Reserved

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

float4 ViewSize

  • x: Width
  • y: Height
  • z: 1. / Width
  • w: 1. / Height

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

texture2d InputA

Available only to Filters and Transitions, holds a 2D Texture of size ViewSize.xy with the content that is to be filtered or transitioned from.

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

texture2d InputB

Available only to Transitions, holds a 2D Texture of size ViewSize.xy with the content that is to be transitioned to.

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

float TransitionTime

Value from 0 to 1 that describes the current expected progress of the transition. The transition must have completed by the time this value reaches 1 or the transition is cut off.

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

int32 RandomSeed

The seed value used for randomization, user controlled. Changing this automatically regenerates all random values.

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

float4x4 Random

A matrix containing random values that are generated per-instance, per-activation and per-frame. Use it like this:

float4 perInst = float4(Random[0][0], Random[1][0], Random[2][0], Random[3][0]);
float4 perActivation = float4(Random[0][1], Random[1][1], Random[2][1], Random[3][1]);
float4 perFrame1 = float4(Random[0][2], Random[1][2], Random[2][2], Random[3][2]);
float4 perFrame2 = float4(Random[0][3], Random[1][3], Random[2][3], Random[3][3]);

This is an automatically set option, ensure that the user does not see it by setting the annotation 'bool automatic = true;'.

libOBS Semi-HLSL

libOBS works with a customized version of HLSL that is not quite compliant with official HLSL for any DirectX version. It attempts to make sure that the shaders compile fine in all of its supported Graphics APIs, and sacrifices functionality and versatility for it. This means that many effects that would be easily possible with HLSL or GLSL directly will not work always, or might require careful design considerations.

Types

The libOBS Shader parser only supports the following data Types, and no other.

Basic

Name DirectX OpenGL
bool bool bool
float float float
float2 float2 vec2
float3 float3 vec3
float4 float4 vec4
int int int
int2 int2 ivec2
int3 int3 ivec3
int4 int4 ivec4
string string string

Matrices

Name DirectX OpenGL
float3x3 float3x3 mat3x3
float3x4 float3x4 mat3x4
float4x4 float4x4 mat4x4

Textures / Samplers

| texture2d | Texture2D | sampler2D | | texture3d | Texture3D | sampler3D | | texture_cube | TextureCube | samplerCube | | texture_rect | N/A | sampler2DRect | | sampler_state | SamplerState | Metadata only |

Clone this wiki locally