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.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-01-31 04:47:38 +01:00
parent cfc828f0f8
commit 50f05e72ae
1 changed files with 6 additions and 9 deletions

View File

@ -5,12 +5,12 @@ uniform float2 texelScale;
uniform float2 displacementScale;
sampler_state textureSampler {
Filter = Trilinear;
Filter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler_state dispTextureSampler {
Filter = Trilinear;
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
@ -35,17 +35,14 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSDisplace(VertDataOut v_in) : TARGET
{
float2 disp = displacementMap.Sample(dispTextureSampler, v_in.uv).rg - float2(0.5, 0.5);
float2 disp = displacementMap.Sample(dispTextureSampler, v_in.uv).rg - float2(.5, .5);
// Handle 0..255 correctly (127, 128 are center)
float2 signdisp = disp * float2(281474976710656.0, 281474976710656.0);
float2 signs = float2(clamp(disp.r, -1.0, 1.0), clamp(disp.g, -1.0, 1.0));
disp = (floor(abs(disp * 127.0)) / 127.0) * signs;
// Method 1: Only Math
disp = (floor(abs(disp * 255.0)) / 255.0) * sign(disp);
float2 uv = v_in.uv + (disp * texelScale * displacementScale);
float4 rgba = image.Sample(textureSampler, uv);
return rgba;
return image.Sample(textureSampler, uv);
}
technique Draw