//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   vsa shaderdump19/WATERDISPLACE005.pso
//    /Fcshaderdump19/WATERDISPLACE005.pso.dis
//
//
// Parameters:
//
#define rr TESR_ReciprocalResolutionWater.y

float4 BlendAmount : register(c1);
float4 TextureOffset : register(c2);
float4 fDamp : register(c3);
float4 RainVars : register(c4);
float4 WadingVars : register(c5);
float4 TESR_ReciprocalResolutionWater : register(c6);
float4 TESR_Tick : register(c7);
float4 TESR_WaveParams : register(c8);

sampler2D DisplaceMap : register(s0);
sampler2D HeightMap2 : register(s1);
sampler3D TESR_samplerWater : register(s2) < string ResourceName = "Water\water_NRM.dds"; > = sampler_state { ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };

//
//
// Registers:
//
//   Name         Reg   Size
//   ------------ ----- ----
//   fDamp        const_3       1
//   DisplaceMap  texture_0       1
//


// Structures:

struct VS_OUTPUT {
    float2 texcoord_0 : TEXCOORD0;
};

struct PS_OUTPUT {
    float4 color_0 : COLOR0;
};

// Code:

PS_OUTPUT main(VS_OUTPUT IN) {
    PS_OUTPUT OUT;

#define	expand(v)		(((v) - 0.5) / 0.5)
#define	compress(v)		(((v) * 0.5) + 0.5)

    const float2 const_0 = {-rr,   0};
    const float2 const_1 = {-rr,  rr};
    const float2 const_2 = { 0,  -rr};
    const float2 const_3 = { rr,  rr};
    const float2 const_4 = {-rr, -rr};

    float1 q3;
    float1 q4;
    float4 r0;
    float4 r1;
    float4 r2;
    float4 r3;
    float4 r4;
    float4 r5;
    float4 r6;
    float4 r7;

    r0.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy - const_2.xy);
    float rain = r0.b;
    r3.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy - const_1.xy);
    r7.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy - const_0.xy);
    r5.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy - const_4.xy);
    r1.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy + const_2.xy);
    r4.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy + const_1.xy);
    r6.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy + const_0.xy);
    r2.xyzw = tex2D(DisplaceMap, IN.texcoord_0.xy + const_3.xy);
    r0.z = 1;
    q4.x = (fDamp.x * abs(r4.x)) + (((fDamp.x * -abs(r5.x)) - (2 * (abs(r1.x) * fDamp.x))) - (fDamp.x * abs(r3.x)));
    q3.x = (fDamp.x * abs(r3.x)) + (((fDamp.x * -abs(r5.x)) - (2 * (abs(r6.x) * fDamp.x))) - (fDamp.x * abs(r4.x)));
    r0.y =   (fDamp.x * abs(r2.x)) + ((2 * (abs(r0.x) * fDamp.x)) + q4.x);
    r0.x = -((fDamp.x * abs(r2.x)) + ((2 * (abs(r7.x) * fDamp.x)) + q3.x));
    r0.z = 1.0 / length(r0.xyz);
    r0.xy = r0.xy * r0.z;

    OUT.color_0.a = 1;
    OUT.color_0.rgb = compress(r0.xyz);

    if (rain > 0.95) {
		float frame = TESR_Tick.y * TESR_WaveParams.z / 1500;
		float4 sampledResult = tex3D(TESR_samplerWater, float3(IN.texcoord_0.xy, frac(frame))).rgba;

		OUT.color_0.rg = saturate((sampledResult.rg * 2 - 1 + r0.xy) * 0.5 + 0.5);
		OUT.color_0.b = sampledResult.b;
    }

    return OUT;
};

// approximately 48 instruction slots used (8 texture, 40 arithmetic)
