//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
// Parameters:

float3 DiffuseDir : register(c0);
float3 DiffuseColor : register(c1);
float3 ScaleMask : register(c2);
float4 WindData : register(c4);
float4 AlphaParam : register(c5);
float4 AmbientColor : register(c6);
float4 AddlParams : register(c7);
row_major float4x4 ModelViewProj : register(c9);
float4 FogColor : register(c14);
float4 FogParam : register(c15);
float4 InstanceData[228] : register(c20);
float4 TESR_GrassScale : register(c248);
row_major float4x4 TESR_ShadowCameraToLightTransformNear : register(c249);
row_major float4x4 TESR_ShadowCameraToLightTransformFar : register(c16);

// Registers:
//
//   Name          Reg   Size
//   ------------- ----- ----
//   DiffuseDir    const_0       1
//   DiffuseColor  const_1       1
//   ScaleMask     const_2       1
//   WindData      const_4       1
//   AlphaParam    const_5       1
//   AmbientColor  const_6       1
//   AddlParams    const_7       1
//   ModelViewProj[0] const_9        1
//   ModelViewProj[1] const_10        1
//   ModelViewProj[2] const_11        1
//   ModelViewProj[3] const_12        1
//   FogColor      const_14      1
//   FogParam      const_15      1
//   InstanceData[0]  const_20       1
//   InstanceData[1]  const_21       1
//


// Structures:

struct VS_INPUT {
    float4 LPOSITION : POSITION;
    float4 LCOLOR_0 : COLOR0;
    float4 LTEXCOORD_0 : TEXCOORD0;
    float4 LTEXCOORD_1 : TEXCOORD1;
};

struct VS_OUTPUT {
    float4 color_0 : COLOR0;
    float4 position : POSITION;
    float2 texcoord_0 : TEXCOORD0;
    float4 texcoord_4 : TEXCOORD4;
    float4 texcoord_5 : TEXCOORD5;
	float4 texcoord_6 : TEXCOORD6;  
  	float4 texcoord_7 : TEXCOORD7;
};

// Code:

VS_OUTPUT main(VS_INPUT IN) {
    VS_OUTPUT OUT;

#define	PI				3.14159274
#define	anglei(v)		(((v) + PI) / (2 * PI))
#define	angler(v)		(((v) * (2 * PI)) - PI)
#define	fracr(v)		angler(frac(anglei(v)))	// signed modulo % PI
#define	expand(v)		(((v) - 0.5) / 0.5)
#define	shades(n, l)	saturate(dot(n, l))
#define	sqr(v)			((v) * (v))

    const float4 const_3 = {-0.5, 0.01, 1, (1.0 / 17)};
    const int4 const_8 = {0, 2, -1, 1};

    float1 q0;
    float4 r0;
    float4 r1;
    float3 r2;
    float3 r3;
    float2 r4;
    float3 r5;

    r0.xyzw = frac(InstanceData[0 + IN.LTEXCOORD_1.x]);
    r1.xyz = r0.xyz - 0.5;
    q0.x = InstanceData[0 + IN.LTEXCOORD_1.x].y + InstanceData[0 + IN.LTEXCOORD_1.x].x;
    r0.xyz = 2 * r1.xyz;
    r3.yz = r0.x * const_8.zw;
    r3.x = (2 * r1.y) - r0.z;
    r1.xyz = abs(r0.xyz);
    r1.xyzw = (r1.yzxz >= r1.xxyy ? 1.0 : 0.0);
    r4.xy = r1.yw * r1.xz;
    r3.z = r4.y * r3.z;
    r2.xyz = ((r0.w * IN.LCOLOR_0.xyz) * shades(DiffuseDir.xyz, r0.xyz)) * DiffuseColor.rgb;
    r0.w = -r0.y;
    r3.xy = (r4.y * r3.xy) + r0.wx;
    r1.x = -r3.x;
    r1.yz = (r0.zy * const_8.zw) - r3.yz;
    r1.xyz = (r4.x * r1.xyz) + r3.xyz;
    r5.xyz = normalize(r1.xyz);
    r1.x = expand(frac(q0.x / 17));	// [0,1] to [-1,+1]
    r1.w = sqrt(1.0 - sqr(r1.x));	// arcsin = 1 / sqrt(1 - x²)
    r1.yz = const_3.yz;
    r3.xyz = (((r1.y * InstanceData[0 + IN.LTEXCOORD_1.x].w) * ScaleMask.xyz) + r1.z) * IN.LPOSITION.xyz;
	r3.xyz = r3.xyz * TESR_GrassScale.xyz;
    r1.z = 0;
    r1.y = -r1.w;
    r0.xyz = (r3.z * r0.xyz) + ((dot(r1.xyz, r3.xyz) * cross(r5.xyz, r0.xyz)) + (r5.xyz * dot(r1.wxz, r3.xyz)));
    r1.w = IN.LPOSITION.w;
    r0.xy = (((sin(fracr((q0.x / 128) + WindData.w)) * WindData.z) * sqr(IN.LCOLOR_0.w)) * WindData.xy) + r0.xy;
    r1.xyz = r0.xyz + InstanceData[0 + IN.LTEXCOORD_1.x].xyz;
	r0.xyzw = mul(ModelViewProj, r1.xyzw);
    r1.xy = saturate((length(r0.xyzw) - AlphaParam.xz) / AlphaParam.yw);
    OUT.color_0.rgb = FogColor.rgb;
    OUT.color_0.a = 1 - saturate((FogParam.x - length(r0.xyz)) / FogParam.y);
    OUT.position.xyzw = r0.xyzw;
    OUT.texcoord_0.xy = IN.LTEXCOORD_0.xy;
    OUT.texcoord_4.xyzw = AmbientColor.rgba;
    OUT.texcoord_5.w = r1.x * (1 - r1.y);
    OUT.texcoord_5.xyz = r2.xyz * AddlParams.x;
	 OUT.texcoord_6.xyzw = mul(r0.xyzw, TESR_ShadowCameraToLightTransformNear);
	  OUT.texcoord_7.xyzw = mul(r0.xyzw, TESR_ShadowCameraToLightTransformFar);
    return OUT;
};

// approximately 95 instruction slots used