//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   psa shaderdump19/SM3LL011.pso /Fcshaderdump19/SM3LL011.pso.dis
//
//
// Parameters:

float4 AmbientColor : register(c0);
sampler2D BaseMap : register(s0);
float3 EyePosition : register(c1);
float4 LightData[8] : register(c9);
float3 MatAlpha : register(c3);
sampler2D NormalMap : register(s1);
sampler2D ShadowMap : register(s2);
sampler2D ShadowMask : register(s3);
float4 ToggleADTS : register(c5);
float4 ToggleNumLights : register(c6);
float4 TESR_ShadowData : register(c17);
sampler2D TESR_ShadowMapBuffer : register(s7) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };

// Registers:
//
//   Name            Reg   Size
//   --------------- ----- ----
//   AmbientColor    const_0       1
//   EyePosition     const_1       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
//   BaseMap         texture_0       1
//   NormalMap       texture_1       1
//   ShadowMap       texture_2       1
//   ShadowMask      texture_3       1
//


// Structures:

struct VS_OUTPUT {
    float2 LTEXCOORD_0 : TEXCOORD0;
    float3 LCOLOR_0 : COLOR0;
    float3 LTEXCOORD_3 : TEXCOORD3_centroid;
    float3 LTEXCOORD_4 : TEXCOORD4_centroid;
    float3 LTEXCOORD_5 : TEXCOORD5_centroid;
    float3 LTEXCOORD_6 : TEXCOORD6_centroid;
    float4 LTEXCOORD_1 : TEXCOORD1;
    float4 LTEXCOORD_7 : TEXCOORD7_centroid;
};

struct PS_OUTPUT {
    float4 color_0 : COLOR0;
};

#include "../Shadows/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 int4 const_17 = {2, -2, -3, -4};
    const float4 const_2 = {-0.5, 0, 1, -1};
    const int4 const_4 = {4, -1, -2, 0};
    const int4 const_7 = {2, -4, -5, -6};
    const int4 const_8 = {2, -6, -7, 0};

    float3 eye135;
    float3 l14;
    float3 l17;
    float1 l289;
    float3 l4;
    float3 l51;
    float3 l55;
    float3 l59;
    float3 l70;
    float3 m80;
    float3 m88;
    float3 m94;
    float3 m98;
    float1 q11;
    float1 q13;
    float3 q26;
    float3 q29;
    float3 q3;
    float3 q30;
    float3 q33;
    float3 q34;
    float3 q37;
    float3 q42;
    float1 q5;
    float3 q7;
    float1 q9;
    float4 r0;
    float4 r1;
    float3 r11;
    float4 r2;
    float4 r3;
    float3 r4;
    float3 r5;
    float3 r6;
    float3 r7;
    float3 r8;
    float3 r9;

#define	TanSpaceProj	float3x3(r8.xyz, r7.xyz, r6.xyz)
#define	TanSpaceProj	float3x3(r8.xyz, r7.xyz, r6.xyz)

    r0.xyzw = tex2D(NormalMap, IN.LTEXCOORD_0);
    r3.xyz = normalize(expand(r0.xyz));
    r6.xyz = normalize(IN.LTEXCOORD_5.xyz);
    r7.xyz = normalize(IN.LTEXCOORD_4.xyz);
    r8.xyz = normalize(IN.LTEXCOORD_3.xyz);
    eye135.xyz = mul(TanSpaceProj, EyePosition.xyz - IN.LTEXCOORD_6.xyz);
    r5.xyz = normalize(eye135.xyz);
    r11.yz = const_2.yz;
    r1.w = (ToggleNumLights.x <= 0.0 ? r11.y : r11.z);

    if (0 != r1.w) {
      l70.xyz = mul(TanSpaceProj, LightData[1].xyz);
      l4.xyz = pow(abs(shades(normalize(r5.xyz + l70.xyz), r3.xyz)), ToggleNumLights.z) * LightData[0].xyz;
      r3.w = 1;
      q3.xyz = GetLightAmount(IN.LTEXCOORD_1);
      r0.xyz = q3.xyz * l4.xyz;
      r2.xyz = q3.xyz * (shade(r3.xyz, l70.xyz) * LightData[0].xyz);
    }
    else {
      r3.w = 0;
      r2.xyz = 0;
      r0.xyz = 0;
    }

    q5.x = min(ToggleNumLights.y, 4 - ToggleNumLights.x);
    r2.w = ((q5.x >= 0.0 ? 0 : 1) * (frac(q5.x) <= 0.0 ? 0 : 1)) + (q5.x - frac(q5.x));
    r1.w = (r2.w <= 0.0 ? 0 : 1);

    if (0 != r1.w) {
      r4.x = 2 * r3.w;
      r4.yz = r4.x + const_4.yz;
      q7.xyz = r4.x + const_4.wyz;
      r3.w = r3.w + 1;
      r9.xyz = (q7.xyz >= 0.0 ? q7.xyz : -r4.xyz);
      r1.xyzw = (r9.z <= 0.0 ? LightData[3].xyzw : (r9.y <= 0.0 ? LightData[2].xyzw : (r9.x <= 0.0 ? LightData[1].xyzw : r11.y)));
      q26.xyz = r1.xyz - IN.LTEXCOORD_6.xyz;
      m80.xyz = mul(TanSpaceProj, q26.xyz);
      q29.xyz = normalize(m80.xyz);
      q9.x = 1.0 - sqr(saturate(length(q26.xyz) / r1.w));
      l51.xyz = (r9.z <= 0.0 ? LightData[2].xyz : (r9.y <= 0.0 ? LightData[1].xyz : (r9.x <= 0.0 ? LightData[0].xyz : r11.y)));
      r0.xyz = (q9.x * (l51.xyz * pow(abs(shades(normalize(r5.xyz + q29.xyz), r3.xyz)), ToggleNumLights.z))) + r0.xyz;
      r2.xyz = (max(q9.x * dot(r3.xyz, q29.xyz), 0) * l51.xyz) + r2.xyz;
    }


    if (1 != r2.w) {
      r9.xyz = (2 * r3.w) + const_17.yzw;
      r3.w = r3.w + 1;
      r1.xyzw = (r9.z == 0.0 ? LightData[5].xyzw : (r9.y == 0.0 ? LightData[4].xyzw : (r9.x == 0.0 ? LightData[3].xyzw : r11.y)));
      q30.xyz = r1.xyz - IN.LTEXCOORD_6.xyz;
      m88.xyz = mul(TanSpaceProj, q30.xyz);
      q33.xyz = normalize(m88.xyz);
      q11.x = 1.0 - sqr(saturate(length(q30.xyz) / r1.w));
      l55.xyz = (r9.z == 0.0 ? LightData[4].xyz : (r9.y == 0.0 ? LightData[3].xyz : (r9.x == 0.0 ? LightData[2].xyz : r11.y)));
      r0.xyz = (q11.x * (l55.xyz * pow(abs(shades(normalize(r5.xyz + q33.xyz), r3.xyz)), ToggleNumLights.z))) + r0.xyz;
      r2.xyz = (max(q11.x * dot(r3.xyz, q33.xyz), 0) * l55.xyz) + r2.xyz;
    }


    if (2 != r2.w) {
      r9.xyz = (2 * r3.w) + const_7.yzw;
      r3.w = r3.w + 1;
      r1.xyzw = (r9.z == 0.0 ? LightData[7].xyzw : (r9.y == 0.0 ? LightData[6].xyzw : (r9.x == 0.0 ? LightData[5].xyzw : r11.y)));
      q34.xyz = r1.xyz - IN.LTEXCOORD_6.xyz;
      m94.xyz = mul(TanSpaceProj, q34.xyz);
      q37.xyz = normalize(m94.xyz);
      q13.x = 1.0 - sqr(saturate(length(q34.xyz) / r1.w));
      l59.xyz = (r9.z == 0.0 ? LightData[6].xyz : (r9.y == 0.0 ? LightData[5].xyz : (r9.x == 0.0 ? LightData[4].xyz : r11.y)));
      r0.xyz = (q13.x * (l59.xyz * pow(abs(shades(normalize(r5.xyz + q37.xyz), r3.xyz)), ToggleNumLights.z))) + r0.xyz;
      r2.xyz = (max(q13.x * dot(r3.xyz, q37.xyz), 0) * l59.xyz) + r2.xyz;
    }


    if (3 != r2.w) {
      l14.xyz = LightData[7].xyz - IN.LTEXCOORD_6.xyz;
      m98.xyz = mul(TanSpaceProj, l14.xyz);
      r5.xyz = r5.xyz + normalize(m98.xyz);
      r1.w = pow(abs(shades(normalize(r5.xyz), r3.xyz)), ToggleNumLights.z);
      l289.x = 1.0 - sqr(saturate(length(l14.xyz) / LightData[7].w));
      r5.xy = (2 * r3.w) + const_8.yz;
      l17.xyz = (r5.y == 0.0 ? LightData[7].xyz : (r5.x == 0.0 ? LightData[6].xyz : r11.y));
      r2.xyz = (max(l289.x * dot(r3.xyz, normalize(m98.xyz)), 0) * l17.xyz) + r2.xyz;
      r0.xyz = (l289.x * (r1.w * l17.xyz)) + r0.xyz;
    }

    r1.xyz = r2.xyz + ((ToggleADTS.x * AmbientColor.rgb) + (r11.z - ToggleADTS.x));
    r2.xyz = r0.w * r0.xyz;
    r0.xyzw = tex2D(BaseMap, IN.LTEXCOORD_0);
    q42.xyz = ((r0.xyz * IN.LCOLOR_0.xyz) * r1.xyz) + r2.xyz;
    OUT.color_0.a = r0.w * MatAlpha.x;
    OUT.color_0.rgb = (IN.LTEXCOORD_7.w * (IN.LTEXCOORD_7.xyz - q42.xyz)) + q42.xyz;

    return OUT;
};

// approximately 219 instruction slots used (4 texture, 215 arithmetic)
