mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-15 00:05:06 +00:00
examples/sahders: Add concentric rings shader (ShaderToy: Xsl3RX) (#310)
This commit is contained in:
parent
5ba3d7e478
commit
f2ec4200cf
1 changed files with 145 additions and 0 deletions
145
data/examples/shaders/source/shadertoy-Xsl3RX.effect
Normal file
145
data/examples/shaders/source/shadertoy-Xsl3RX.effect
Normal file
|
@ -0,0 +1,145 @@
|
|||
// Target with smoothstep by possum
|
||||
// https://www.shadertoy.com/view/Xsl3RX
|
||||
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
|
||||
// Contact the author for other licensing options
|
||||
|
||||
// type conversion
|
||||
#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 Time.x
|
||||
#define iResolution ViewSize
|
||||
|
||||
// Always provided by OBS
|
||||
uniform float4x4 ViewProj<
|
||||
bool automatic = true;
|
||||
string name = "View Projection Matrix";
|
||||
>;
|
||||
|
||||
|
||||
// Provided by Stream Effects
|
||||
uniform float4 Time<
|
||||
// x: Time in seconds since the source was created.
|
||||
// y: Time in the current second.
|
||||
// z: Total seconds passed since the source was created.
|
||||
// w: Reserved
|
||||
bool automatic = true;
|
||||
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.";
|
||||
>;
|
||||
uniform float4 ViewSize<
|
||||
// x: Width
|
||||
// y: Height
|
||||
// z: 1. / Width
|
||||
// w: 1. / Height
|
||||
bool automatic = true;
|
||||
>;
|
||||
uniform texture2d InputA<
|
||||
bool automatic = true;
|
||||
>;
|
||||
uniform float4x4 Random<
|
||||
bool automatic = true;
|
||||
string name = "Random Array";
|
||||
string description = "A float4x4 value containing random values between 0 and 1";
|
||||
>;
|
||||
|
||||
|
||||
// Shader Parameters
|
||||
uniform float pRings<
|
||||
string name = "Rings";
|
||||
string field_type = "slider";
|
||||
float minimum = 1.0;
|
||||
float maximum = 50.0;
|
||||
float step = 0.01;
|
||||
float scale = 1.;
|
||||
> = 5.0;
|
||||
uniform float pVelocity<
|
||||
string name = "Ring Velocity";
|
||||
string field_type = "slider";
|
||||
float minimum = 0.1;
|
||||
float maximum = 10.0;
|
||||
float step = 0.01;
|
||||
float scale = 1.;
|
||||
> = 1.0;
|
||||
uniform float pBorder<
|
||||
string name = "Border Size";
|
||||
string field_type = "slider";
|
||||
float minimum = 0.1;
|
||||
float maximum = 100.0;
|
||||
float step = 0.1;
|
||||
float scale = 0.001;
|
||||
> = 1.;
|
||||
|
||||
// convenience values
|
||||
#define PI 3.1415926f
|
||||
#define TAU 6.2831853f
|
||||
#define TwoPI 6.2831853f
|
||||
#define HalfPI 1.5707963f
|
||||
#define deg30 0.20943951
|
||||
|
||||
float mod(float x, float y) {
|
||||
return x - y * floor(x / y);
|
||||
}
|
||||
|
||||
// ---------- Shader Code
|
||||
sampler_state def_sampler {
|
||||
Filter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
sampler_state imageSampler {
|
||||
Filter = Point;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertFragData {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertFragData VSDefault(VertFragData vtx) {
|
||||
vtx.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj);
|
||||
return vtx;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
float2 position = fragCoord.xy / ViewSize.xy;
|
||||
float aspect = ViewSize.x / ViewSize.y;
|
||||
position.x *= aspect;
|
||||
float dist = distance(position, float2( aspect * 0.5, 0.5));
|
||||
float offset = Time.x * pVelocity;
|
||||
float conv = pRings * 1.;
|
||||
float v = dist * conv - offset;
|
||||
float ringr = floor(v);
|
||||
float ringv = abs( dist - (ringr + float( frac(v) > 0.5) + offset) / conv);
|
||||
float color = smoothstep( -pBorder, pBorder, ringv);
|
||||
if ( mod(ringr, 2.) == 1.) color = 1. - color;
|
||||
fragColor = vec4(color, color, color, 1.);
|
||||
}
|
||||
|
||||
|
||||
float4 PSDefault(VertFragData vtx) : TARGET {
|
||||
float4 col = float4(1., 1., 1., 1.);
|
||||
mainImage(col, vtx.uv * ViewSize.xy);
|
||||
return col;
|
||||
}
|
||||
|
||||
technique Draw
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vtx);
|
||||
pixel_shader = PSDefault(vtx);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue