//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   psa shaderdump19/SM3LL008.pso /Fcshaderdump19/SM3LL008.pso.dis
//
//
// Parameters:
//
float4 AmbientColor : register(c0);
sampler2D BaseMap : register(s0);
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
//   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 float4 const_1 = {-0.5, 0, 1, 4};
    const int4 const_17 = {2, -2, -3, -4};
    const int4 const_2 = {2, -4, -5, -6};
    const int4 const_7 = {2, -6, -7, 0};
    const int4 const_8 = {-1, -2, 0, 2};

    float3 l11;
    float3 l12;
    float3 l5;
    float3 l78;
    float3 l8;
    float3 m49;
    float3 m52;
    float3 m56;
    float3 m59;
    float1 q0;
    float1 q10;
    float3 q2;
    float3 q28;
    float3 q3;
    float1 q4;
    float3 q6;
    float1 q7;
    float3 q9;
    float4 r0;
    float4 r1;
    float4 r2;
    float3 r3;
    float3 r4;
    float3 r5;
    float3 r6;
    float3 r7;
    float1 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);
    l78.xyz = mul(TanSpaceProj, LightData[1].xyz);
    r0.xyz = shade(r3.xyz, l78.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_8.xy;
      q2.xyz = r7.x + const_8.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);
      m49.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(m49.xyz)) * (1.0 - sqr(q4.x)), 0) * l5.xyz) + r0.xyz;
    }


    if (1 < r2.w) {
      r7.xyz = (2 * r0.w) + const_17.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;
      m52.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(m52.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_2.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);
      m56.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(m56.xyz)) * (1.0 - sqr(q10.x)), 0) * l11.xyz) + r1.xyz;
    }


    if (3 < r2.w) {
      l12.xyz = LightData[7].xyz - IN.texcoord_6.xyz;
      m59.xyz = mul(TanSpaceProj, l12.xyz);
      r0.w = dot(r3.xyz, normalize(m59.xyz));
      r3.xy = (2 * r1.w) + const_7.yz;
      r1.xyz = (max(r0.w * (1.0 - sqr(saturate(length(l12.xyz) / LightData[7].w))), 0) * (r3.y == 0.0 ? LightData[7].xyz : (r3.x == 0.0 ? LightData[6].xyz : r2.y))) + r1.xyz;
    }                                
    
    
                                  shadow = GetLightAmount(IN.texcoord_1, IN.texcoord_2);
         r1 *= shadow;
    
    

    r0.xyzw = tex2D(GlowMap, IN.BaseUV.xy);
    r1.xyz = r1.xyz + ((ToggleADTS.x * ((r0.xyz * MatEmit.rgb) + AmbientColor.rgb)) + (r2.z - ToggleADTS.x));
    r0.xyzw = tex2D(BaseMap, IN.BaseUV.xy);
    q28.xyz = r1.xyz * (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 - q28.xyz)) + q28.xyz;

    return OUT;
};

// approximately 153 instruction slots used (3 texture, 150 arithmetic)
