[EFFECT] Pixel Distort

Completed plugins, behaviors and effects.

Post » Mon Dec 31, 2012 11:10 am

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.

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();
Funky Koval2013-01-05 06:20:07
Posts: 86
Reputation: 1,220

Return to Completed addons

Who is online

Users browsing this forum: No registered users and 0 guests