obs-StreamFX/data/effects/displace.effect
Michael Fabian 'Xaymar' Dirks 50f05e72ae filter-displacement: Improve displacement quality
Earlier versions tried using Trilinear as the Filter, but the correct name is Linear. With this the sampling is now set to be Linear instead of undetermined.

Additionally the logic for the displacement was adjusted and now no longer renders incorrectly when going from texel to texel. This was due to the unstable math being performed to retrieve the sign of the number, but the sign() command can do it without this math being required.
2019-01-31 04:47:38 +01:00

55 lines
1.1 KiB
Text

uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d displacementMap;
uniform float2 texelScale;
uniform float2 displacementScale;
sampler_state textureSampler {
Filter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler_state dispTextureSampler {
Filter = Linear;
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);
// Method 1: Only Math
disp = (floor(abs(disp * 255.0)) / 255.0) * sign(disp);
float2 uv = v_in.uv + (disp * texelScale * displacementScale);
return image.Sample(textureSampler, uv);
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDisplace(v_in);
}
}