// rtsEffect.fx

//

// Different ways of rendering a texture to the full screen.

//

// Copyright (c)2005, David Nikdel

 

 

////////// GLOBALS //////////

//

float4x4 TheMatrix : WORLDVIEWPROJ; // hehe

texture texture0; // screen texture

sampler2D sampler0 : TEXUNIT0 = sampler_state

{

    Texture = (texture0);

    MIPFILTER = NONE;

    MAGFILTER = LINEAR;

    MINFILTER = LINEAR;

};

 

 

////////// STRUCTURES //////////

//

struct VERTEX

{

      float4 position : POSITION;

      float2 tex0 : TEXCOORD0;

};

struct FRAGMENT

{

      float4 position : POSITION;

      float2 tex0 : TEXCOORD0;

};

struct PIXEL

{

     float4 color : COLOR0;

};

 

 

////////// PARAMETERS //////////

//

float p_Amplitude;

float p_Aspect; // eg 16/9

 

 

////////// VERTEX SHADER //////////

// This is just a bare minimum vertex shader

//

void vs(in VERTEX IN, out FRAGMENT OUT)

{

      OUT.position = mul(IN.position, TheMatrix);

      OUT.tex0 = IN.tex0;

}

 

 

////////// PIXEL SHADER //////////

// This pixel shader distorts the view by stretching it more as it gets near the sides.

//

void ps(in FRAGMENT IN, out PIXEL OUT)

{

      float2 tt = float2(IN.tex0.x - 0.5f, (IN.tex0.y - 0.5f)/p_Aspect);

      float mag2 = tt.x*tt.x + tt.y*tt.y;

      tt /= 1.01f + p_Amplitude*mag2;

      OUT.color = tex2D(sampler0, float2(tt.x + 0.5f, tt.y*p_Aspect + 0.5f));

}

 

 

////////// TECHNIQUE //////////

//

technique teqStretch

{

      pass p0

      {

            vertexshader = compile vs_1_1 vs();

            pixelshader = compile ps_2_0 ps();

      }

}