//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   vsa shaderdump19/PAR2010.pso /Fcshaderdump19/PAR2010.pso.dis
//
//
// Parameters:
//
float4 AmbientColor : register(c1);
sampler2D TESR_samplerBaseMap : register(s0) = sampler_state { MINFILTER = LINEAR; };
sampler2D NormalMap : register(s1);
float4 PSLightColor[4] : register(c2);
sampler2D ShadowMap : register(s6);
sampler2D ShadowMaskMap : register(s7);
float4 Toggles : register(c7);
float4 TESR_ShadowData : register(c10);
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_1       1
//   PSLightColor[0]  const_2        1
//   Toggles       const_7       1
//   TESR_samplerBaseMap       texture_0       1
//   NormalMap     texture_1       1
//   ShadowMap     texture_6       1
//   ShadowMaskMap texture_7       1
//

// Structures:

struct VS_OUTPUT {
    // PAR2010.vso

    float2 BaseUV : TEXCOORD0;
    float3 Light0Dir : TEXCOORD1_centroid;
    float3 Light0Spc : TEXCOORD3_centroid;
    float3 CameraDir : TEXCOORD5_centroid;
	float4 ShadowUV0 : TEXCOORD6;
    float4 ShadowUV1 : TEXCOORD7;
    float3 Color : COLOR0;
    float4 Fog : COLOR1;
};

struct PS_OUTPUT {
    float4 Color : COLOR0;
};

// Code:

#include "Includes/PAR.hlsl"
#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	uvtile(w)		(((w) * 0.04) - 0.02)
#define	shade(n, l)		max(dot(n, l), 0)
#define	shades(n, l)		saturate(dot(n, l))

    float3 q17;
    float1 q4;
    float3 q5;
    float1 q6;
    float3 q7;
    float4 r0;
    float3 r1;
    float4 r3;
    float2 uv;
    float  ao;
    float  hg;
    float3 cm = normalize(IN.CameraDir);

    /* calculate parallaxed position */
    hg = tex2D(TESR_samplerBaseMap, IN.BaseUV.xy).a;
    uv.xy = (uvtile(hg) * (cm.xy / length(cm.xyz))) + IN.BaseUV.xy;
    ao = 1.0;

    /* modifying shader --------------------------------------- */

    psParallax(IN.BaseUV, IN.CameraDir, uv, ao);

    /* fetch Base/Normal+Diffuse from parallaxed position */
    r0.rgb = tex2D(TESR_samplerBaseMap, uv.xy).rgb;
    r3.xyzw = tex2D(NormalMap, uv.xy);

    q6.x = r3.w * pow(abs(shades(normalize(expand(r3.xyz)), IN.Light0Spc.xyz)), Toggles.z);
    q4.x = dot(normalize(expand(r3.xyz)), IN.Light0Dir.xyz);
    q7.xyz = saturate((0.2 >= q4.x ? (q6.x * max(q4.x + 0.5, 0)) : q6.x) * PSLightColor[0].rgb);
    q5.xyz = GetLightAmount(IN.ShadowUV0, IN.ShadowUV1);
    r1.xyz = (Toggles.x <= 0.0 ? r0.xyz : (r0.xyz * IN.Color.rgb));
    q17.xyz = (r1.xyz * max((q5.xyz * (saturate(q4.x) * PSLightColor[0].rgb)) + AmbientColor.rgb, 0)) + (q7.xyz * q5.xyz);
    q17.xyz = q17.xyz * ao;

    OUT.Color.a = AmbientColor.a;
    OUT.Color.rgb = (Toggles.y <= 0.0 ? q17.xyz : lerp(q17.xyz, IN.Fog.rgb, IN.Fog.a));

    return OUT;
};

// approximately 47 instruction slots used (5 texture, 42 arithmetic)
