//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   vsa shaderdump19/SM3000.pso /Fcshaderdump19/SM3000.pso.dis
//
//
// Parameters:
//
float4 AmbientColor : register(c0);
sampler2D BaseMap : register(s0);
float4 LightData[30] : register(c9);
float3 MatAlpha : register(c3);
sampler2D NormalMap : register(s1);
float4 ToggleADTS : register(c5);
float4 ToggleNumLights : register(c6);

float4 TESR_ShadowData : register(c40);

sampler2D TESR_ShadowMapBufferNear : register(s8) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };
sampler2D TESR_ShadowMapBufferFar : register(s9) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };



//
// Registers:
//
//   Name            Reg   Size
//   --------------- ----- ----
//   AmbientColor    const_0       1
//   MatAlpha        const_3       1
//   ToggleADTS      const_5       1
//   ToggleNumLights const_6       1
//   LightData[0]       const_9          1
//   LightData[1]       const_10          1
//   LightData[2]       const_11          1
//   LightData[3]       const_12          1
//   LightData[4]       const_13          1
//   LightData[5]       const_14          1
//   LightData[6]       const_15          1
//   LightData[7]       const_16          1
//   LightData[8]       const_17         1
//   LightData[9]       const_18         1
//   LightData[10]       const_19         1
//   LightData[11]       const_20         1
//   LightData[12]       const_21         1
//   LightData[13]       const_22         1
//   LightData[14]       const_23         1
//   LightData[15]       const_24         1
//   LightData[16]       const_25        1
//   LightData[17]       const_26        1
//   LightData[18]       const_27        1
//   LightData[19]       const_28        1
//   LightData[20]       const_29       1
//   LightData[21]       const_30       1
//   LightData[22]       const_31       1
//   LightData[23]       const_32       1
//   LightData[24]       const_33       1
//   LightData[25]       const_34       1
//   LightData[26]       const_35       1
//   LightData[27]       const_36       1
//   LightData[28]       const_37       1
//   LightData[29]       const_38       1
//   BaseMap         texture_0       1
//   NormalMap       texture_1       1
//


// Structures:

struct VS_OUTPUT {
    float2 BaseUV : TEXCOORD0;
    float3 color_0 : COLOR0;       
    
    float4 texcoord_1 : TEXCOORD1;
    float4 texcoord_2 : TEXCOORD2;
    
    float3 texcoord_3 : TEXCOORD3_centroid;
    float3 texcoord_4 : TEXCOORD4_centroid;
    float3 texcoord_5 : TEXCOORD5_centroid;
    float3 texcoord_6 : TEXCOORD6_centroid;
    float4 texcoord_7 : TEXCOORD7_centroid;
    
};

struct PS_OUTPUT {
    float4 color_0 : COLOR0;
};

// Code:

#include "..\Includes\Shadow.hlsl"

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)
#define	shade(n, l)		max(dot(n, l), 0)
#define	shades(n, l)		saturate(dot(n, l))
#define	weight(v)		dot(v, 1)
#define	sqr(v)			((v) * (v))

    const float4 const_1 = {-0.5, 0, 1, 15};
    const int4 const_2 = {-1, -2, 0, 2};
    const int4 const_39 = {2, -10, -11, -12};
    const int4 const_4 = {2, -2, -3, -4};
    const int4 const_40 = {2, -12, -13, -14};
    const int4 const_41 = {2, -20, -21, -22};
    const int4 const_42 = {2, -22, -23, -24};
    const int4 const_43 = {2, -26, -27, -28};
    const int4 const_44 = {2, -28, -29, 0};
    const int4 const_45 = {2, -6, -7, -8};
    const int4 const_46 = {2, -14, -15, -16};
    const int4 const_47 = {2, -16, -17, -18};
    const int4 const_48 = {2, -18, -19, -20};
    const int4 const_49 = {2, -24, -25, -26};
    const int4 const_7 = {2, -4, -5, -6};
    const int4 const_8 = {2, -8, -9, -10};

    float3 l11;
    float3 l14;
    float3 l17;
    float3 l20;
    float3 l23;
    float3 l26;
    float3 l265;
    float3 l29;
    float3 l32;
    float3 l35;
    float3 l38;
    float3 l41;
    float3 l44;
    float3 l45;
    float3 l5;
    float3 l8;
    float3 m148;
    float3 m151;
    float3 m155;
    float3 m159;
    float3 m163;
    float3 m167;
    float3 m171;
    float3 m175;
    float3 m179;
    float3 m183;
    float3 m187;
    float3 m191;
    float3 m195;
    float3 m199;
    float3 m202;
    float1 q0;
    float1 q10;
    float3 q12;
    float1 q13;
    float3 q15;
    float1 q16;
    float3 q18;
    float1 q19;
    float3 q2;
    float3 q21;
    float1 q22;
    float3 q24;
    float1 q25;
    float3 q27;
    float1 q28;
    float3 q3;
    float3 q30;
    float1 q31;
    float3 q33;
    float1 q34;
    float3 q36;
    float1 q37;
    float3 q39;
    float1 q4;
    float1 q40;
    float3 q42;
    float1 q43;
    float3 q6;
    float1 q7;
    float3 q9;
    float3 q94;
    float4 r0;
    float4 r1;
    float4 r2;
    float3 r3;
    float3 r4;
    float3 r5;
    float3 r6;
    float3 r7;
    float Shadow;

#define	TanSpaceProj	float3x3(r4.xyz, r6.xyz, r5.xyz)

    r0.xyzw = tex2D(NormalMap, IN.BaseUV.xy);
    r3.xyz = normalize(expand(r0.xyz));
    r5.xyz = normalize(IN.texcoord_5.xyz);
    r6.xyz = normalize(IN.texcoord_4.xyz);
    r4.xyz = normalize(IN.texcoord_3.xyz);
    l265.xyz = mul(TanSpaceProj, LightData[1].xyz);
    r0.xyz = shade(r3.xyz, l265.xyz) * LightData[0].xyz;
    r2.yzw = const_1.yzw;
    q0.x = min(ToggleNumLights.y, r2.w - ToggleNumLights.x);
    r0.w = 1;
    r2.w = (q0.x >= 0.0 ? 0 : (frac(q0.x) <= 0.0 ? 0 : 1)) + (q0.x - frac(q0.x));
    r1.w = (r2.w <= 0.0 ? 0 : 1);
    r0.xyzw = (ToggleNumLights.x <= 0.0 ? r2.y : r0.xyzw);

    if (0 < r1.w) {
      r7.x = 2 * r0.w;
      r7.yz = r7.x + const_2.xy;
      q2.xyz = r7.x + const_2.zxy;
      r0.w = r0.w + 1;
      r7.xyz = (q2.xyz >= 0.0 ? q2.xyz : -r7.xyz);
      r1.xyzw = (r7.z <= 0.0 ? LightData[3].xyzw : (r7.y <= 0.0 ? LightData[2].xyzw : (r7.x <= 0.0 ? LightData[1].xyzw : r2.y)));
      q3.xyz = r1.xyz - IN.texcoord_6.xyz;
      q4.x = saturate(length(q3.xyz) / r1.w);
      m148.xyz = mul(TanSpaceProj, q3.xyz);
      l5.xyz = (r7.z <= 0.0 ? LightData[2].xyz : (r7.y <= 0.0 ? LightData[1].xyz : (r7.x <= 0.0 ? LightData[0].xyz : r2.y)));
      r0.xyz = (max(dot(r3.xyz, normalize(m148.xyz)) * (1.0 - sqr(q4.x)), 0) * l5.xyz) + r0.xyz;
    }


    if (1 < r2.w) {
      r7.xyz = (2 * r0.w) + const_4.yzw;
      r1.xyzw = (r7.z == 0.0 ? LightData[5].xyzw : (r7.y == 0.0 ? LightData[4].xyzw : (r7.x == 0.0 ? LightData[3].xyzw : r2.y)));
      q6.xyz = r1.xyz - IN.texcoord_6.xyz;
      q7.x = saturate(length(q6.xyz) / r1.w);
      r1.w = r0.w + 1;
      m151.xyz = mul(TanSpaceProj, q6.xyz);
      l8.xyz = (r7.z == 0.0 ? LightData[4].xyz : (r7.y == 0.0 ? LightData[3].xyz : (r7.x == 0.0 ? LightData[2].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m151.xyz)) * (1.0 - sqr(q7.x)), 0) * l8.xyz) + r0.xyz;
    }
    else {
      r1.xyz = r0.xyz;
      r1.w = r0.w;
    }


    if (2 < r2.w) {
      r7.xyz = (2 * r1.w) + const_7.yzw;
      r1.w = r1.w + 1;
      r0.xyzw = (r7.z == 0.0 ? LightData[7].xyzw : (r7.y == 0.0 ? LightData[6].xyzw : (r7.x == 0.0 ? LightData[5].xyzw : r2.y)));
      q9.xyz = r0.xyz - IN.texcoord_6.xyz;
      q10.x = saturate(length(q9.xyz) / r0.w);
      m155.xyz = mul(TanSpaceProj, q9.xyz);
      l11.xyz = (r7.z == 0.0 ? LightData[6].xyz : (r7.y == 0.0 ? LightData[5].xyz : (r7.x == 0.0 ? LightData[4].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m155.xyz)) * (1.0 - sqr(q10.x)), 0) * l11.xyz) + r1.xyz;
    }


    if (3 < r2.w) {
      r7.xyz = (2 * r1.w) + const_45.yzw;
      r1.w = r1.w + 1;
      r0.xyzw = (r7.z == 0.0 ? LightData[9].xyzw : (r7.y == 0.0 ? LightData[8].xyzw : (r7.x == 0.0 ? LightData[7].xyzw : r2.y)));
      q12.xyz = r0.xyz - IN.texcoord_6.xyz;
      q13.x = saturate(length(q12.xyz) / r0.w);
      m159.xyz = mul(TanSpaceProj, q12.xyz);
      l14.xyz = (r7.z == 0.0 ? LightData[8].xyz : (r7.y == 0.0 ? LightData[7].xyz : (r7.x == 0.0 ? LightData[6].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m159.xyz)) * (1.0 - sqr(q13.x)), 0) * l14.xyz) + r1.xyz;
    }


    if (4 < r2.w) {
      r7.xyz = (2 * r1.w) + const_8.yzw;
      r1.w = r1.w + 1;
      r0.xyzw = (r7.z == 0.0 ? LightData[11].xyzw : (r7.y == 0.0 ? LightData[10].xyzw : (r7.x == 0.0 ? LightData[9].xyzw : r2.y)));
      q15.xyz = r0.xyz - IN.texcoord_6.xyz;
      q16.x = saturate(length(q15.xyz) / r0.w);
      m163.xyz = mul(TanSpaceProj, q15.xyz);
      l17.xyz = (r7.z == 0.0 ? LightData[10].xyz : (r7.y == 0.0 ? LightData[9].xyz : (r7.x == 0.0 ? LightData[8].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m163.xyz)) * (1.0 - sqr(q16.x)), 0) * l17.xyz) + r1.xyz;
    }


    if (5 < r2.w) {
      r7.xyz = (2 * r1.w) + const_39.yzw;
      r1.w = r1.w + 1;
      r0.xyzw = (r7.z == 0.0 ? LightData[13].xyzw : (r7.y == 0.0 ? LightData[12].xyzw : (r7.x == 0.0 ? LightData[11].xyzw : r2.y)));
      q18.xyz = r0.xyz - IN.texcoord_6.xyz;
      q19.x = saturate(length(q18.xyz) / r0.w);
      m167.xyz = mul(TanSpaceProj, q18.xyz);
      l20.xyz = (r7.z == 0.0 ? LightData[12].xyz : (r7.y == 0.0 ? LightData[11].xyz : (r7.x == 0.0 ? LightData[10].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m167.xyz)) * (1.0 - sqr(q19.x)), 0) * l20.xyz) + r1.xyz;
    }


    if (6 < r2.w) {
      r7.xyz = (2 * r1.w) + const_40.yzw;
      r1.w = r1.w + 1;
      r0.xyzw = (r7.z == 0.0 ? LightData[15].xyzw : (r7.y == 0.0 ? LightData[14].xyzw : (r7.x == 0.0 ? LightData[13].xyzw : r2.y)));
      q21.xyz = r0.xyz - IN.texcoord_6.xyz;
      q22.x = saturate(length(q21.xyz) / r0.w);
      m171.xyz = mul(TanSpaceProj, q21.xyz);
      l23.xyz = (r7.z == 0.0 ? LightData[14].xyz : (r7.y == 0.0 ? LightData[13].xyz : (r7.x == 0.0 ? LightData[12].xyz : r2.y)));
      r1.xyz = (max(dot(r3.xyz, normalize(m171.xyz)) * (1.0 - sqr(q22.x)), 0) * l23.xyz) + r1.xyz;
    }


          
    
               Shadow = GetLightAmount(IN.texcoord_1, IN.texcoord_2);
    
   
    r1 *= Shadow;

    r0.xyzw = tex2D(BaseMap, IN.BaseUV.xy);
    q94.xyz = (r1.xyz + ((ToggleADTS.x * AmbientColor.rgb) + (r2.z - ToggleADTS.x))) * (r0.xyz * IN.color_0.rgb);
    OUT.color_0.a = r0.w * MatAlpha.x;
    OUT.color_0.rgb = (IN.texcoord_7.w * (IN.texcoord_7.xyz - q94.xyz)) + q94.xyz;

    return OUT;
};

// approximately 448 instruction slots used (2 texture, 446 arithmetic)
