obs-StreamFX/data/effects/displace.effect

56 lines
1.1 KiB
Text
Raw Normal View History

2017-06-28 21:55:30 +00:00
uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d displacementMap;
uniform float2 texelScale;
uniform float2 displacementScale;
sampler_state textureSampler {
Filter = Linear;
2017-06-28 21:55:30 +00:00
AddressU = Wrap;
AddressV = Wrap;
};
sampler_state dispTextureSampler {
Filter = Linear;
2017-06-28 21:55:30 +00:00
AddressU = Clamp;
AddressV = Clamp;
};
struct VertDataIn {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct VertDataOut {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertDataOut VSDefault(VertDataIn v_in)
{
VertDataOut vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 PSDisplace(VertDataOut v_in) : TARGET
{
float2 disp = displacementMap.Sample(dispTextureSampler, v_in.uv).rg - float2(.5, .5);
2017-06-28 21:55:30 +00:00
// Method 1: Only Math
disp = (floor(abs(disp * 255.0)) / 255.0) * sign(disp);
2017-08-19 22:25:20 +00:00
2017-06-28 21:55:30 +00:00
float2 uv = v_in.uv + (disp * texelScale * displacementScale);
2017-08-19 22:25:20 +00:00
return image.Sample(textureSampler, uv);
2017-06-28 21:55:30 +00:00
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDisplace(v_in);
}
}