string Description = "Ocean Glass";

float4x4 WorldViewProj : WorldViewProjection;
float fTime : Time;

float distortSize
<
	string UIWidget = "slider";
	float UIMax = 0.5;
	float UIMin = -0.1;
	float UIStep = 0.001;
> = 0.137000;
float distortSpeed 
<
	string UIWidget = "slider";
	float UIMax = 0.2;
	float UIMin = 0.0;
	float UIStep = 0.01;
> = 0.070000;

texture BaseTex : DIFFUSE
<
	string ResourceName = "wall5c.jpg";
	string Type = "2D";
>;

sampler texture1 = sampler_state
{
	Texture = <BaseTex>;
	MinFilter = Anisotropic;
	MagFilter = Linear;
	MipFilter = Linear;
	AddressU = Clamp;
	AddressV = Clamp;
};

texture DistortTex : DIFFUSE
<
	string ResourceName = "rock_N.dds";
	string Type = "2D";
>;

sampler distortSmp = sampler_state
{
	Texture = <DistortTex>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	AddressU = Wrap;
	AddressV = Wrap;
};

struct app_in
{
	float4 pos : POSITION;
	float2 uv : TEXCOORD0;
};

struct vs_out
{
	float4 pos : POSITION;
	float2 uv : TEXCOORD0;
};

vs_out DefaultVertexShader( app_in IN )
{
	vs_out OUT;
	
	OUT.pos = mul( IN.pos, WorldViewProj );
	OUT.uv = IN.uv;
	
	return OUT;
}

float4 DefaultPixelShader( vs_out IN ) : COLOR
{
	//calculate an offset value using the variable and time values
	float2 offset = float2( sin(fTime*distortSpeed), cos(fTime*distortSpeed) );
	
	//offset the uv co-odinate by the offset value and read the texture
	float2 uv = IN.uv + (tex2D(distortSmp, IN.uv + offset).x - 0.25) * distortSize;
	return tex2D( texture1, uv );
}

technique MyShader
<
	
>
{
	pass p0
	{
		VertexShader = compile vs_1_1 DefaultVertexShader( );
		PixelShader = compile ps_2_0 DefaultPixelShader( );
	}
}
