Pixel Distort
Performs absolute pixel shifting on underlying data. Download the .cap to see an example. Cannibalized from DistortNormal and Offset.
The layer with PixelDistort becomes a coordinate array where R,G equals X,Y for picking final color values. Sprite/Canvas dimensions act as a multiplier to distortion values. Only rotations in 90 degrees increments give predictable results.
*EDIT*
Updated the shader - functionality is the same, but now for pasting to canvas, Max X distortion and Max Y distortion should just be set to DisplayWidth and DisplayHeight. Also, B and A channel usage has been removed, since the distortion strenght is now relative to the source dimensions.
// Pixel Distort
// Q'ba
// PS 2
// Shifts BG.RGB values based on FG.RG
//#CROSS-SAMPLING : changes Tex.xy.
//#PARAM float xmax 256 : Max X distortion: In pixels. Corresponds to R=255. For pasting into Canvas, set to DisplayWidth.
float xmax;
//#PARAM float ymax 256 : Max Y distortion : In pixels. Corresponds to G=255. For pasting into Canvas, set to DisplayHeight.
float ymax;
//#PARAM float poff 0.5 : Precission offset : In pixels. Prevents sampling the preceeding/superceeding pixel.
float poff;
float pixelWidth;
float pixelHeight;
float boxLeft;
float boxTop;
// Foreground texture
texture ForegroundTexture;
// Background texture
texture BackgroundTexture;
// Foreground sampler
sampler2D foreground = sampler_state {
Texture = (ForegroundTexture);
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};
// OriginalTexture sampler
sampler2D background = sampler_state {
Texture = (BackgroundTexture);
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};
// Effect function
float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 col = tex2D(foreground, Tex.xy);
{
Tex.x = boxLeft+pixelWidth*(poff+col.r*xmax);
Tex.y = boxTop+pixelHeight*(poff+col.g*ymax);
col = tex2D(background, Tex.xy);
}
return col;
}
// ConstructEffect
technique ConstructEffect
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 EffectProcess();
}
}