Skip to main content
added 175 characters in body
Source Link

Figured it out, or at least figured out a workaround, thanks toin part with the help of this answer. It seems the tex2D method was not sampling the textures how I rewrotewanted it to with sampler2D samplers. I refactored the shader to use only one sampler to sample both texturesSamplerStates and the Texture2D.Sample function, like so:

Texture2D ScreenTexture;
Texture2D DistortionMap;
SamplerState Sampler; // TODO: Double check AddressU = Clamp behavior

float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, 
float2 texCoord : TEXCOORD0) : COLOR0
{
    return ScreenTexture.Sample(Sampler, texCoord + (DistortionMap.Sample(Sampler, texCoord).rg * 2 - 1));
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
    }
}

Note that I was able to do this with either one or two samplers, so I decided to just use one.

Figured it out, or at least figured out a workaround, thanks to this answer. I rewrote the shader to use only one sampler to sample both textures, like so:

Texture2D ScreenTexture;
Texture2D DistortionMap;
SamplerState Sampler; // TODO: Double check AddressU = Clamp behavior

float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, 
float2 texCoord : TEXCOORD0) : COLOR0
{
    return ScreenTexture.Sample(Sampler, texCoord + (DistortionMap.Sample(Sampler, texCoord).rg * 2 - 1));
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
    }
}

Figured it out, or at least figured out a workaround, in part with the help of this answer. It seems the tex2D method was not sampling the textures how I wanted it to with sampler2D samplers. I refactored the shader to use SamplerStates and the Texture2D.Sample function, like so:

Texture2D ScreenTexture;
Texture2D DistortionMap;
SamplerState Sampler;

float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, 
float2 texCoord : TEXCOORD0) : COLOR0
{
    return ScreenTexture.Sample(Sampler, texCoord + (DistortionMap.Sample(Sampler, texCoord).rg * 2 - 1));
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
    }
}

Note that I was able to do this with either one or two samplers, so I decided to just use one.

Source Link

Figured it out, or at least figured out a workaround, thanks to this answer. I rewrote the shader to use only one sampler to sample both textures, like so:

Texture2D ScreenTexture;
Texture2D DistortionMap;
SamplerState Sampler; // TODO: Double check AddressU = Clamp behavior

float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, 
float2 texCoord : TEXCOORD0) : COLOR0
{
    return ScreenTexture.Sample(Sampler, texCoord + (DistortionMap.Sample(Sampler, texCoord).rg * 2 - 1));
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
    }
}