data/shaders: Displacement filter example

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-08-07 20:40:14 +02:00
parent 250dc97603
commit 458eca143a

View file

@ -0,0 +1,84 @@
// 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 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 float4x4 Random<
bool visible = false;
string name = "Random Array";
string description = "A float4x4 value containing random values between 0 and 1";
>;
uniform texture2d ImageSource<
bool visible = false;
string name = "Source Texture (Filter, Transition)";
>;
uniform float2 ImageSource_Size<
bool visible = false;
string name = "Source Texture Size (Filter, Transition)";
>;
uniform float2 ImageSource_Texel<
bool visible = false;
string name = "Source Texture Texel Size (Filter, Transition)";
>;
// Shader Parameters
uniform texture2d p_texture <
bool visible = true;
string name = "Displacement Map";
>;
uniform float p_scale <
bool visible = true;
string name = "Displacement Scale";
float minimum = 0.0;
float maximum = 100.0;
float step = 0.01;
> = 1.0;
// ---------- Shader Code
sampler_state def_sampler {
AddressU = Wrap;
AddressV = Wrap;
Filter = Linear;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct FragData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
FragData VSDefault(VertData v_in) {
FragData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
// ---------- Pass Through
float4 PS_Draw(FragData v_in) : TARGET {
float4 disp = p_texture.Sample(def_sampler, v_in.uv);
float2 uv_off = (disp.xy - 0.5) * p_scale;
return ImageSource.Sample(def_sampler, v_in.uv + uv_off);
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PS_Draw(v_in);
}
}