//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   psa shaderdump19/SM3LL009.pso /Fcshaderdump19/SM3LL009.pso.dis
//
//
// Parameters:
//
float4 AmbientColor : register(c0);
sampler2D BaseMap : register(s0);
float3 EyePosition : register(c1);
sampler2D GlowMap : register(s6);
float4 LightData[8] : register(c9);
float3 MatAlpha : register(c3);
float3 MatEmit : register(c4);
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
//   EyePosition     const_1       1
//   MatAlpha        const_3       1
//   MatEmit         const_4       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
//   GlowMap         texture_6       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 int4 const_17 = {-1, -2, 0, 2};
    const int4 const_18 = {2, -2, -3, -4};
    const float4 const_2 = {-0.5, 0, 1, 4};
    const int4 const_7 = {2, -4, -5, -6};
    const int4 const_8 = {2, -6, -7, 0};

    float3 eye126;
    float3 l13;
    float3 l16;
    float1 l260;
    float3 l45;
    float3 l50;
    float3 l55;
    float3 l66;
    float3 m72;
    float3 m79;
    float3 m87;
    float3 m93;
    float1 q1;
    float3 q11;
    float1 q12;
    float3 q21;
    float3 q26;
    float3 q3;
    float3 q31;
    float3 q40;
    float3 q5;
    float1 q6;
    float3 q8;
    float1 q9;
    float4 r0;
    float4 r1;
    float3 r10;
    float4 r2;
    float4 r3;
    float3 r4;
    float3 r5;
    float3 r6;
    float3 r7;
    float3 r8;
    float3 r9;    
    float1 shadow;

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

    r0.xyzw = tex2D(NormalMap, IN.BaseUV.xy);
    r4.xyz = normalize(expand(r0.xyz));
    r7.xyz = normalize(IN.texcoord_5.xyz);
    r8.xyz = normalize(IN.texcoord_4.xyz);
    r9.xyz = normalize(IN.texcoord_3.xyz);
    eye126.xyz = mul(TanSpaceProj, EyePosition.xyz - IN.texcoord_6.xyz);
    r6.xyz = normalize(eye126.xyz);
    r3.yzw = const_2.yzw;
    r1.w = (ToggleNumLights.x <= 0.0 ? r3.y : r3.z);

    if (0 != r1.w
) {
      l66.xyz = mul(TanSpaceProj, LightData[1].xyz);
      r2.xyz = shade(r4.xyz, l66.xyz) * LightData[0].xyz;
      r0.xyz = pow(abs(shades(normalize(r6.xyz + l66.xyz), r4.xyz)), ToggleNumLights.z) * LightData[0].xyz;
      r2.w = 1;
    }
    else {
      r2.yzw = 0;
      r2.xyz = r2.wyz;
      r0.xyz = r2.w;
    }

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

    if (0 != r1.w
) {
      r3.w = r2.w + 1;
      r5.x = 2 * r2.w;
      r5.yz = r5.x + const_17.xy;
      q3.xyz = r5.x + const_17.zxy;
      r10.xyz = (q3.xyz >= 0.0 ? q3.xyz : -r5.xyz);
      r1.xyzw = (r10.z <= 0.0 ? LightData[3].xyzw : (r10.y <= 0.0 ? LightData[2].xyzw : (r10.x <= 0.0 ? LightData[1].xyzw : r3.y)));
      q21.xyz = r1.xyz - IN.texcoord_6.xyz;
      m72.xyz = mul(TanSpaceProj, q21.xyz);
      q6.x = 1.0 - sqr(saturate(length(q21.xyz) / r1.w));
      l45.xyz = (r10.z <= 0.0 ? LightData[2].xyz : (r10.y <= 0.0 ? LightData[1].xyz : (r10.x <= 0.0 ? LightData[0].xyz : r3.y)));
      q5.xyz = l45.xyz * pow(abs(shades(normalize(r6.xyz + normalize(m72.xyz)), r4.xyz)), ToggleNumLights.z);
      r0.xyz = (q6.x * q5.xyz) + r0.xyz;
      r2.xyz = (max(q6.x * dot(r4.xyz, normalize(m72.xyz)), 0) * l45.xyz) + r2.xyz;
    }
    else {
      r3.w = r2.w;
    }


    if (1 < r3.x
) {
      r10.xyz = (2 * r3.w) + const_18.yzw;
      r3.w = r3.w + 1;
      r1.xyzw = (r10.z == 0.0 ? LightData[5].xyzw : (r10.y == 0.0 ? LightData[4].xyzw : (r10.x == 0.0 ? LightData[3].xyzw : r3.y)));
      q26.xyz = r1.xyz - IN.texcoord_6.xyz;
      m79.xyz = mul(TanSpaceProj, q26.xyz);
      q9.x = 1.0 - sqr(saturate(length(q26.xyz) / r1.w));
      l50.xyz = (r10.z == 0.0 ? LightData[4].xyz : (r10.y == 0.0 ? LightData[3].xyz : (r10.x == 0.0 ? LightData[2].xyz : r3.y)));
      q8.xyz = l50.xyz * pow(abs(shades(normalize(r6.xyz + normalize(m79.xyz)), r4.xyz)), ToggleNumLights.z);
      r0.xyz = (q9.x * q8.xyz) + r0.xyz;
      r2.xyz = (max(q9.x * dot(r4.xyz, normalize(m79.xyz)), 0) * l50.xyz) + r2.xyz;
    }


    if (2 < r3.x
) {
      r10.xyz = (2 * r3.w) + const_7.yzw;
      r3.w = r3.w + 1;
      r1.xyzw = (r10.z == 0.0 ? LightData[7].xyzw : (r10.y == 0.0 ? LightData[6].xyzw : (r10.x == 0.0 ? LightData[5].xyzw : r3.y)));
      q31.xyz = r1.xyz - IN.texcoord_6.xyz;
      m87.xyz = mul(TanSpaceProj, q31.xyz);
      q12.x = 1.0 - sqr(saturate(length(q31.xyz) / r1.w));
      l55.xyz = (r10.z == 0.0 ? LightData[6].xyz : (r10.y == 0.0 ? LightData[5].xyz : (r10.x == 0.0 ? LightData[4].xyz : r3.y)));
      q11.xyz = l55.xyz * pow(abs(shades(normalize(r6.xyz + normalize(m87.xyz)), r4.xyz)), ToggleNumLights.z);
      r0.xyz = (q12.x * q11.xyz) + r0.xyz;
      r2.xyz = (max(q12.x * dot(r4.xyz, normalize(m87.xyz)), 0) * l55.xyz) + r2.xyz;
    }


    if (3 < r3.x) {
      l13.xyz = LightData[7].xyz - IN.texcoord_6.xyz;
      m93.xyz = mul(TanSpaceProj, l13.xyz);
      r6.xyz = r6.xyz + normalize(m93.xyz);
      r1.xyz = normalize(r6.xyz);
      l260.x = 1.0 - sqr(saturate(length(l13.xyz) / LightData[7].w));
      r6.xy = (2 * r3.w) + const_8.yz;
      l16.xyz = (r6.y == 0.0 ? LightData[7].xyz : (r6.x == 0.0 ? LightData[6].xyz : r3.y));
      r2.xyz = (max(l260.x * dot(r4.xyz, normalize(m93.xyz)), 0) * l16.xyz) + r2.xyz;
      r0.xyz = (l260.x * (pow(abs(shades(r1.xyz, r4.xyz)), ToggleNumLights.z) * l16.xyz)) + r0.xyz;
    }
                                          
    
                                shadow = GetLightAmount(IN.texcoord_1, IN.texcoord_2);
         r2 *= shadow;
    
    r1.xyzw = tex2D(GlowMap, IN.BaseUV.xy);
    r1.xyz = r2.xyz + ((ToggleADTS.x * ((r1.xyz * MatEmit.rgb) + AmbientColor.rgb)) + (r3.z - ToggleADTS.x));
    r2.xyz = r0.w * r0.xyz;
    r0.xyzw = tex2D(BaseMap, IN.BaseUV.xy);
    q40.xyz = ((r0.xyz * IN.color_0.rgb) * r1.xyz) + r2.xyz;
    OUT.color_0.a = r0.w * MatAlpha.x;
    OUT.color_0.rgb = (IN.texcoord_7.w * (IN.texcoord_7.xyz - q40.xyz)) + q40.xyz;

    return OUT;
};

// approximately 215 instruction slots used (3 texture, 212 arithmetic)
