#line 2 "E:\Program Files\Dead Steel\Data\Shaders\Generated\NiTerrainMaterial\Shader0002-P.hlsl"
/*
Shader description:
WORLDNBT = 1
NUM_TEXCOORDS = 1
NUM_LAYERS = 4
LAYER0_NORMAL_ENABLED = 1
LAYER0_PARALLAX_ENABLED = 0
LAYER0_DISTMASK_ENABLED = 0
LAYER0_DETAIL_ENABLED = 0
LAYER0_UVINDEX = 0
LAYER1_NORMAL_ENABLED = 1
LAYER1_PARALLAX_ENABLED = 0
LAYER1_DISTMASK_ENABLED = 1
LAYER1_DETAIL_ENABLED = 0
LAYER1_UVINDEX = 0
LAYER2_NORMAL_ENABLED = 1
LAYER2_PARALLAX_ENABLED = 0
LAYER2_DISTMASK_ENABLED = 0
LAYER2_DETAIL_ENABLED = 0
LAYER2_UVINDEX = 0
LAYER3_NORMAL_ENABLED = 1
LAYER3_PARALLAX_ENABLED = 0
LAYER3_DISTMASK_ENABLED = 1
LAYER3_DETAIL_ENABLED = 0
LAYER3_UVINDEX = 0
LAYER4_NORMAL_ENABLED = 0
LAYER4_PARALLAX_ENABLED = 0
LAYER4_DISTMASK_ENABLED = 0
LAYER4_DETAIL_ENABLED = 0
LAYER4_UVINDEX = 0
LAYER5_NORMAL_ENABLED = 0
LAYER5_PARALLAX_ENABLED = 0
LAYER5_DISTMASK_ENABLED = 0
LAYER5_DETAIL_ENABLED = 0
LAYER5_UVINDEX = 0
LAYER6_NORMAL_ENABLED = 0
LAYER6_PARALLAX_ENABLED = 0
LAYER6_DISTMASK_ENABLED = 0
LAYER6_DETAIL_ENABLED = 0
LAYER6_UVINDEX = 0
LAYER7_NORMAL_ENABLED = 0
LAYER7_PARALLAX_ENABLED = 0
LAYER7_DISTMASK_ENABLED = 0
LAYER7_DETAIL_ENABLED = 0
LAYER7_UVINDEX = 0
PSSMSLICETRANSITIONSENABLED = 0
PSSMSLICECOUNT = 0
PSSMWHICHLIGHT = 0
*/

//---------------------------------------------------------------------------
// Types:
#if defined(DIRECT3D)
#define BONEMATRIX_TYPE float4x3
#else
#define BONEMATRIX_TYPE float3x4
#endif
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Constant variables:
//---------------------------------------------------------------------------

float4 g_AmbientLight;
float4 g_MaterialEmissive;
float4 g_MaterialDiffuse;
float4 g_MaterialAmbient;
sampler2D BlendMap0;
float4 g_SurfaceUVModifierArray[4];
sampler2D DistributionMap0;
float4 g_DistMaskStrength;
sampler2D BaseMap0;
sampler2D NormalMap0;
sampler2D BaseMap1;
sampler2D NormalMap1;
sampler2D BaseMap2;
sampler2D NormalMap2;
sampler2D BaseMap3;
sampler2D NormalMap3;
float4 g_PointAmbient0;
float4 g_PointDiffuse0;
float4 g_PointSpecular0;
float4 g_PointWorldPosition0;
float4 g_PointAttenuation0;
float2 g_ShadowDirTexSizeShadow0;
float g_ShadowDirShadowBias0;
sampler2D DirShadow;
float4x4 g_ShadowDirWorldToShadowMapMatrix0;
float4 g_ShadowDirAmbient0;
float4 g_ShadowDirDiffuse0;
float4 g_ShadowDirSpecular0;
float4 g_ShadowDirWorldPosition0;
float4 g_ShadowDirWorldDirection0;
float4 g_SpotAmbient0;
float4 g_SpotDiffuse0;
float4 g_SpotSpecular0;
float4 g_SpotWorldPosition0;
float4 g_SpotAttenuation0;
float4 g_SpotWorldDirection0;
float4 g_SpotSpotAttenuation0;
//---------------------------------------------------------------------------
// Functions:
//---------------------------------------------------------------------------

/*

    This fragment is responsible for normalizing a float3.
    
*/

void NormalizeFloat3(float3 VectorIn,
    out float3 VectorOut)
{

    VectorOut = normalize(VectorIn);
    
}
//---------------------------------------------------------------------------
/*

    Separate a float4 into a float3 and a float.   
    
*/

void SplitColorAndOpacity(float4 ColorAndOpacity,
    out float3 Color,
    out float Opacity)
{

    Color.rgb = ColorAndOpacity.rgb;
    Opacity = ColorAndOpacity.a;
    
}
//---------------------------------------------------------------------------
/*

      This fragment extracts the scale and offset parameters for the specified
      surface from the UV Modifier arrays.
    
*/

void AccessSurfaceUVModifiersArray(float4 UVModifierArray[4],
    int Index,
    out float2 OutputScale,
    out float2 OutputOffset)
{

      OutputScale.xy = UVModifierArray[Index].xy;
      OutputOffset.xy = UVModifierArray[Index].zw;
    
}
//---------------------------------------------------------------------------
/*

    This fragment is responsible for calculating the Shadow coefficient.
    
*/

void PCFShadowMap(float4 WorldPos,
    int LightType,
    sampler2D ShadowMap,
    float2 ShadowMapSize,
    float4x4 WorldToLightProjMat,
    float4 ShadowMapViewport,
    float ShadowBias,
    out float ShadowOut)
{

    
    if ( LightType != 0)
    {
      // This fragment only supports directional lights.
        ShadowOut = 0.0;
    }
    else
    {
        float4 LightProjPos = mul(WorldPos, WorldToLightProjMat);
        float2 ShadowTexC = 0.5 * LightProjPos.xy / LightProjPos.w + 
                  float2( 0.5, 0.5 );
        
        ShadowTexC.y = 1.0f - ShadowTexC.y;
        
        float ShadowMapSizeInverse = 1.0f / ShadowMapSize;
        float LightSpaceDepth = saturate(LightProjPos.z / LightProjPos.w);        
        
        float2 ShadowTest = (ShadowTexC + ShadowMapViewport.zw) * ShadowMapViewport.xy;
        float2 borderTest = saturate(ShadowTest) - ShadowTest;
        if (dot(abs(borderTest.xy) > 0.00001f, float2(1.0f, 1.0f)) != 0)
        {
            ShadowOut = 1.0;
        }
        else
        {    
            LightSpaceDepth -= ShadowBias;
        
            ShadowOut = 0;
            float4 fOnes = float4(1.0, 1.0, 1.0, 1.0);
            float4 fKernels = float4(1.0, 1.0, 1.0, 1.0);
            float faKernels[4] = {1.0, 1.0, 1.0, 1.0};
            
            faKernels[0] = 1-frac(ShadowTexC.y * ShadowMapSize.y);
            faKernels[3]= frac(ShadowTexC.y  * ShadowMapSize.y); 
            
            fKernels.x = 1-frac(ShadowTexC.x * ShadowMapSize.x);
            fKernels.w = frac(ShadowTexC.x  * ShadowMapSize.x);
                      
            float fTotalPercent = 0;
            
            // This loop is manually unrolled here to avoid long
            // shader compilation times.
            //for (int i=0; i < 4; i++)
            // i == 0
            {
                float4 shadowMapDepth = 0;
                float2 pos = ShadowTexC;                
                shadowMapDepth.x = tex2D(ShadowMap, pos).x; 
                pos.x += ShadowMapSizeInverse;
                shadowMapDepth.y = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;        
                shadowMapDepth.z = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;                
                shadowMapDepth.w = tex2D(ShadowMap, pos).x;
                
                float4 shad = (LightSpaceDepth <= shadowMapDepth);
    
                ShadowOut += dot(shad, fKernels) * faKernels[0];
                fTotalPercent += dot(fOnes, fKernels) * faKernels[0];
            }
            // i == 1
            {
                float4 shadowMapDepth = 0;
                float2 pos = ShadowTexC;                
                pos.y += ShadowMapSizeInverse;
                shadowMapDepth.x = tex2D(ShadowMap, pos).x; 
                pos.x += ShadowMapSizeInverse;
                shadowMapDepth.y = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;        
                shadowMapDepth.z = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;                
                shadowMapDepth.w = tex2D(ShadowMap, pos).x;
                
                float4 shad = (LightSpaceDepth <= shadowMapDepth);
    
                ShadowOut += dot(shad, fKernels) * faKernels[1];
                fTotalPercent += dot(fOnes, fKernels) * faKernels[1];
            }
            // i == 2
            {
                float4 shadowMapDepth = 0;
                float2 pos = ShadowTexC;                
                pos.y += 2 * ShadowMapSizeInverse;
                shadowMapDepth.x = tex2D(ShadowMap, pos).x; 
                pos.x += ShadowMapSizeInverse;
                shadowMapDepth.y = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;        
                shadowMapDepth.z = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;                
                shadowMapDepth.w = tex2D(ShadowMap, pos).x;
                
                float4 shad = (LightSpaceDepth <= shadowMapDepth);
    
                ShadowOut += dot(shad, fKernels) * faKernels[2];
                fTotalPercent += dot(fOnes, fKernels) * faKernels[2];
            }
            // i == 3
            {
                float4 shadowMapDepth = 0;
                float2 pos = ShadowTexC;                
                pos.y += 3 * ShadowMapSizeInverse;
                shadowMapDepth.x = tex2D(ShadowMap, pos).x; 
                pos.x += ShadowMapSizeInverse;
                shadowMapDepth.y = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;        
                shadowMapDepth.z = tex2D(ShadowMap, pos).x;
                pos.x += ShadowMapSizeInverse;                
                shadowMapDepth.w = tex2D(ShadowMap, pos).x;
                
                float4 shad = (LightSpaceDepth <= shadowMapDepth);
    
                ShadowOut += dot(shad, fKernels) * faKernels[3];
                fTotalPercent += dot(fOnes, fKernels) * faKernels[3];
            }
            
            ShadowOut = ShadowOut / fTotalPercent;         
        }
    }
    
}
//---------------------------------------------------------------------------
/*

      This fragment samples an RGBA texture and returns each component where 
      each component contains a mask for a given texture layer.
    
*/

void SampleBlendMap(float4 MapUV,
    sampler2D Sampler,
    out float OutputRed,
    out float OutputGreen,
    out float OutputBlue,
    out float OutputAlpha,
    out float TotalMask)
{

      float4 color = tex2D(Sampler, MapUV.zw);
      OutputRed = color.r;
      OutputGreen = color.g;
      OutputBlue = color.b;
      OutputAlpha = color.a;
      TotalMask = dot(color, float4(1,1,1,1));
    
}
//---------------------------------------------------------------------------
/*

      This fragment scales and offsets a uv texture coordinate value. 
      Usefull for linearly modifying a texture coordinate. Used by a surface
      to modify its texture coordinates independantly of the other surfaces.
    
*/

void CalcSurfaceUVSet_ScaleAndOffset(float4 InputUV,
    float2 Scale,
    float2 Offset,
    out float4 OutputUV)
{

      OutputUV.x = InputUV.x * Scale.x + Offset.x;
      OutputUV.y = InputUV.y * Scale.y + Offset.y;
      OutputUV.z = InputUV.z * Scale.x + Offset.x;
      OutputUV.w = InputUV.w * Scale.y + Offset.y;
    
}
//---------------------------------------------------------------------------
/*

      This fragment samples an RGB texture for a given terrain layer and
      returns the float3 value.
    
*/

void SampleLayerTextureRGB(float4 MapUV,
    sampler2D Sampler,
    out float3 OutputColor)
{

      OutputColor = tex2D(Sampler, MapUV.xy).rgb;
    
}
//---------------------------------------------------------------------------
/*

      This fragment multiplies a single floating point value by a mask value from 0.0 - 1.0 and
      adds the result to the additional input.
    
*/

void CalcBlendFloatAndAccumulate(float Mask,
    float Input,
    float AccumValue,
    out float Output)
{

      Output = AccumValue + (Mask * Input);
    
}
//---------------------------------------------------------------------------
/*

      This sample samples a channel based on the specified index (0 - 3).
    
*/

void SampleSingleChannel(float4 MapUV,
    sampler2D Sampler,
    int ChannelIndex,
    out float Output)
{

      if (ChannelIndex == 0)
        Output = tex2D(Sampler, MapUV.xy).r;
      else if (ChannelIndex == 1)
        Output =  tex2D(Sampler, MapUV.xy).g;
      else if (ChannelIndex == 2)
        Output =  tex2D(Sampler, MapUV.xy).b;
      else if (ChannelIndex == 3)
        Output =  tex2D(Sampler, MapUV.xy).a;
      
    
}
//---------------------------------------------------------------------------
/*

      This fragment is responsible for sampling a normal map to generate a
      world-space normal. Note, compressed normal maps are not supported.
    
*/

void CalculateNormalFromColor(float3 NormalMap,
    float3 WorldNormal,
    float3 WorldBinormal,
    float3 WorldTangent,
    out float3 WorldNormalOut)
{

      NormalMap = NormalMap * 2.0 - 1.0;

      float3x3 xForm = float3x3(WorldTangent, WorldBinormal, WorldNormal);
      xForm = transpose(xForm);
      WorldNormalOut = mul(xForm, NormalMap.rgb);
    
}
//---------------------------------------------------------------------------
/*

    This fragment is responsible for linearly interpolating two float3's. 
    
*/

void InverseRatio(float Ratio,
    out float Output)
{

    Output = 1.0 - Ratio;
    
}
//---------------------------------------------------------------------------
/*

      This fragment combines mask values from the "global" mask with per layer 
      mask to produce a final composited mask.
    
*/

void ComputeTotalMaskValue(float lMask0,
    float lMask1,
    float lMask2,
    float lMask3,
    float gMask0,
    float gMask1,
    float gMask2,
    float gMask3,
    float4 DistStrength,
    out float gMask0_Out,
    out float gMask1_Out,
    out float gMask2_Out,
    out float gMask3_Out)
{


      half4 gMaskTotal = float4(gMask0, gMask1, gMask2, gMask3);
      half4 lMaskTotal = float4(lMask0, lMask1, lMask2, lMask3);
      half4 value = gMaskTotal * lMaskTotal * DistStrength;
      half4 result = normalize(gMaskTotal + lerp(half4(0.0f, 0.0f, 0.0f, 0.0f), 
            lMaskTotal, value));


      gMask0_Out = result.x;
      gMask1_Out = result.y;
      gMask2_Out = result.z;
      gMask3_Out = result.w;

    
}
//---------------------------------------------------------------------------
/*

      This fragment multiplies an RGB color by a mask value from 0.0 - 1.0 and
      adds the result to the additional input.
    
*/

void CalcBlendRGBAndAccumulate(float Mask,
    float3 InputColor,
    float3 AccumColor,
    out float3 OutputColor)
{

      OutputColor = AccumColor + (InputColor * Mask);
    
}
//---------------------------------------------------------------------------
/*

    This fragment is responsible for accumulating the effect of a light
    on the current pixel.
    
    LightType can be one of three values:
        0 - Directional
        1 - Point 
        2 - Spot
        
    Note that the LightType must be a compile-time variable,
    not a runtime constant/uniform variable on most Shader Model 2.0 cards.
    
    The compiler will optimize out any constants that aren't used.
    
    Attenuation is defined as (const, linear, quad, range).
    Range is not implemented at this time.
    
    SpotAttenuation is stored as (cos(theta/2), cos(phi/2), falloff)
    theta is the angle of the inner cone and phi is the angle of the outer
    cone in the traditional DX manner. Gamebryo only allows setting of
    phi, so cos(theta/2) will typically be cos(0) or 1. To disable spot
    effects entirely, set cos(theta/2) and cos(phi/2) to -1 or lower.
    
*/

void Light(float4 WorldPos,
    float3 WorldNrm,
    int LightType,
    bool SpecularEnable,
    float Shadow,
    float3 WorldViewVector,
    float4 LightPos,
    float3 LightAmbient,
    float3 LightDiffuse,
    float3 LightSpecular,
    float3 LightAttenuation,
    float3 LightSpotAttenuation,
    float3 LightDirection,
    float4 SpecularPower,
    float3 AmbientAccum,
    float3 DiffuseAccum,
    float3 SpecularAccum,
    out float3 AmbientAccumOut,
    out float3 DiffuseAccumOut,
    out float3 SpecularAccumOut)
{
   
    // Get the world space light vector.
    float3 LightVector;
    float DistanceToLight;
    float DistanceToLightSquared;
        
    if (LightType == 0)
    {
        LightVector = -LightDirection;
    }
    else
    {
        LightVector = LightPos - WorldPos;
        DistanceToLightSquared = dot(LightVector, LightVector);
        DistanceToLight = length(LightVector);
        LightVector = normalize(LightVector);
    }
    
    // Take N dot L as intensity.
    float LightNDotL = dot(LightVector, WorldNrm);
    float LightIntensity = max(0, LightNDotL);

    float Attenuate = Shadow;
    
    if (LightType != 0)
    {
        // Attenuate Here
        Attenuate = LightAttenuation.x +
            LightAttenuation.y * DistanceToLight +
            LightAttenuation.z * DistanceToLightSquared;
        Attenuate = max(1.0, Attenuate);
        Attenuate = 1.0 / Attenuate;
        Attenuate *= Shadow;

        if (LightType == 2)
        {
            // Get intensity as cosine of light vector and direction.
            float CosAlpha = dot(-LightVector, LightDirection);

            // Factor in inner and outer cone angles.
            float AttenDiff = LightSpotAttenuation.x - LightSpotAttenuation.y;
            CosAlpha = saturate((CosAlpha - LightSpotAttenuation.y) / 
                AttenDiff);

            // Power to falloff.
            // The pow() here can create a NaN if CosAlpha is 0 or less.
            // On some cards (GeForce 6800), the NaN will propagate through
            // a ternary instruction, so we need two to be safe.
            float origCosAlpha = CosAlpha;
            CosAlpha = origCosAlpha <= 0.0 ? 1.0 : CosAlpha;
            CosAlpha = pow(CosAlpha, LightSpotAttenuation.z);
            CosAlpha = origCosAlpha <= 0.0 ? 0.0 : CosAlpha;

            // Multiply the spot attenuation into the overall attenuation.
            Attenuate *= CosAlpha;
        }
    }
    // Determine the interaction of diffuse color of light and material.
    // Scale by the attenuated intensity.
    DiffuseAccumOut = DiffuseAccum;
    DiffuseAccumOut.rgb += LightDiffuse.rgb * LightIntensity * Attenuate;

    // Determine ambient contribution - Is affected by shadow
    AmbientAccumOut = AmbientAccum;
    AmbientAccumOut.rgb += LightAmbient.rgb * Attenuate;

    SpecularAccumOut = SpecularAccum;
    if (SpecularEnable)
    {
        // Get the half vector.
        float3 LightHalfVector = LightVector + WorldViewVector;
        LightHalfVector = normalize(LightHalfVector);

        // Determine specular intensity.
        float LightNDotH = max(0.00001f, dot(WorldNrm, LightHalfVector));
        float LightSpecIntensity = pow(LightNDotH, SpecularPower.x);
        
        //if (LightNDotL < 0.0)
        //    LightSpecIntensity = 0.0;
        // Must use the code below rather than code above.
        // Using previous lines will cause the compiler to generate incorrect
        // output.
        float SpecularMultiplier = LightNDotL > 0.0 ? 1.0 : 0.0;
        
        // Attenuate Here
        LightSpecIntensity = LightSpecIntensity * Attenuate * 
            SpecularMultiplier;
        
        // Determine the interaction of specular color of light and material.
        // Scale by the attenuated intensity.
        SpecularAccumOut.rgb += LightSpecIntensity * LightSpecular;
    }       

    
    
}
//---------------------------------------------------------------------------
/*

    This fragment is responsible for computing the coefficients for the 
    following equations:
    
    Kdiffuse = MatEmissive + 
        MatAmbient * Summation(0...N){LightAmbientContribution[N]} + 
        MatDiffuse * Summation(0..N){LightDiffuseContribution[N]}
        
    Kspecular = MatSpecular * Summation(0..N){LightSpecularContribution[N]}
    
    
*/

void ComputeShadingCoefficients(float3 MatEmissive,
    float3 MatDiffuse,
    float3 MatAmbient,
    float3 MatSpecular,
    float3 LightSpecularAccum,
    float3 LightDiffuseAccum,
    float3 LightAmbientAccum,
    bool Saturate,
    out float3 Diffuse,
    out float3 Specular)
{

    Diffuse = MatEmissive + MatAmbient * LightAmbientAccum + 
        MatDiffuse * LightDiffuseAccum;
    Specular = MatSpecular * LightSpecularAccum;
    
    if (Saturate)
    {
        Diffuse = saturate(Diffuse);
        Specular = saturate(Specular);
    }
    
}
//---------------------------------------------------------------------------
/*

    This fragment is responsible for multiplying two float3's. 
    
*/

void MultiplyFloat3(float3 V1,
    float3 V2,
    out float3 Output)
{

    Output = V1 * V2;
    
}
//---------------------------------------------------------------------------
/*

        This fragment is responsible for computing the final RGB color.
        
*/

void CompositeFinalRGBColor(float3 DiffuseColor,
    float3 SpecularColor,
    out float3 OutputColor)
{

        OutputColor.rgb = DiffuseColor.rgb + SpecularColor.rgb;
        
}
//---------------------------------------------------------------------------
/*

        This fragment is responsible for computing the final RGBA color.
        
*/

void CompositeFinalRGBAColor(float3 FinalColor,
    float FinalOpacity,
    out float4 OutputColor)
{

        OutputColor.rgb = FinalColor.rgb;
        OutputColor.a = saturate(FinalOpacity);
        
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Input:
//---------------------------------------------------------------------------

struct Input
{
    float4 PosProjected : POSITION0;
    float4 UVSet0 : TEXCOORD0;
    float3 WorldNormal : TEXCOORD1;
    float3 WorldBinormal : TEXCOORD2;
    float3 WorldTangent : TEXCOORD3;
    float4 WorldPos : TEXCOORD4;

};

//---------------------------------------------------------------------------
// Output:
//---------------------------------------------------------------------------

struct Output
{
    float4 Color0 : COLOR0;

};

//---------------------------------------------------------------------------
// Main():
//---------------------------------------------------------------------------

Output Main(Input In)
{
    Output Out;
	// Function call #0
    float3 VectorOut_CallOut0;
    NormalizeFloat3(In.WorldNormal, VectorOut_CallOut0);

	// Function call #1
    float3 VectorOut_CallOut1;
    NormalizeFloat3(In.WorldTangent, VectorOut_CallOut1);

	// Function call #2
    float3 VectorOut_CallOut2;
    NormalizeFloat3(In.WorldTangent, VectorOut_CallOut2);

	// Function call #3
    float3 VectorOut_CallOut3;
    NormalizeFloat3(In.WorldTangent, VectorOut_CallOut3);

	// Function call #4
    float3 VectorOut_CallOut4;
    NormalizeFloat3(In.WorldTangent, VectorOut_CallOut4);

	// Function call #5
    float3 Color_CallOut5;
    float Opacity_CallOut5;
    SplitColorAndOpacity(g_MaterialDiffuse, Color_CallOut5, Opacity_CallOut5);

	// Function call #6
    float2 OutputScale_CallOut6;
    float2 OutputOffset_CallOut6;
    AccessSurfaceUVModifiersArray(g_SurfaceUVModifierArray, int(0), 
        OutputScale_CallOut6, OutputOffset_CallOut6);

	// Function call #7
    float2 OutputScale_CallOut7;
    float2 OutputOffset_CallOut7;
    AccessSurfaceUVModifiersArray(g_SurfaceUVModifierArray, int(1), 
        OutputScale_CallOut7, OutputOffset_CallOut7);

	// Function call #8
    float2 OutputScale_CallOut8;
    float2 OutputOffset_CallOut8;
    AccessSurfaceUVModifiersArray(g_SurfaceUVModifierArray, int(2), 
        OutputScale_CallOut8, OutputOffset_CallOut8);

	// Function call #9
    float2 OutputScale_CallOut9;
    float2 OutputOffset_CallOut9;
    AccessSurfaceUVModifiersArray(g_SurfaceUVModifierArray, int(3), 
        OutputScale_CallOut9, OutputOffset_CallOut9);

	// Function call #10
    float3 VectorOut_CallOut10;
    NormalizeFloat3(In.WorldBinormal, VectorOut_CallOut10);

	// Function call #11
    float3 VectorOut_CallOut11;
    NormalizeFloat3(In.WorldBinormal, VectorOut_CallOut11);

	// Function call #12
    float3 VectorOut_CallOut12;
    NormalizeFloat3(In.WorldBinormal, VectorOut_CallOut12);

	// Function call #13
    float3 VectorOut_CallOut13;
    NormalizeFloat3(In.WorldBinormal, VectorOut_CallOut13);

	// Function call #14
    float ShadowOut_CallOut14;
    PCFShadowMap(In.WorldPos, int(0), DirShadow, g_ShadowDirTexSizeShadow0, 
        g_ShadowDirWorldToShadowMapMatrix0, float4(1,1,0,0), 
        g_ShadowDirShadowBias0, ShadowOut_CallOut14);

	// Function call #15
    float OutputRed_CallOut15;
    float OutputGreen_CallOut15;
    float OutputBlue_CallOut15;
    float OutputAlpha_CallOut15;
    float TotalMask_CallOut15;
    SampleBlendMap(In.UVSet0, BlendMap0, OutputRed_CallOut15, 
        OutputGreen_CallOut15, OutputBlue_CallOut15, OutputAlpha_CallOut15, 
        TotalMask_CallOut15);

	// Function call #16
    float4 OutputUV_CallOut16;
    CalcSurfaceUVSet_ScaleAndOffset(In.UVSet0, OutputScale_CallOut6, 
        OutputOffset_CallOut6, OutputUV_CallOut16);

	// Function call #17
    float4 OutputUV_CallOut17;
    CalcSurfaceUVSet_ScaleAndOffset(In.UVSet0, OutputScale_CallOut8, 
        OutputOffset_CallOut8, OutputUV_CallOut17);

	// Function call #18
    float3 OutputColor_CallOut18;
    SampleLayerTextureRGB(OutputUV_CallOut16, BaseMap0, OutputColor_CallOut18);

	// Function call #19
    float3 OutputColor_CallOut19;
    SampleLayerTextureRGB(OutputUV_CallOut16, NormalMap0, OutputColor_CallOut19);

	// Function call #20
    float3 OutputColor_CallOut20;
    SampleLayerTextureRGB(OutputUV_CallOut17, BaseMap2, OutputColor_CallOut20);

	// Function call #21
    float3 OutputColor_CallOut21;
    SampleLayerTextureRGB(OutputUV_CallOut17, NormalMap2, OutputColor_CallOut21);

	// Function call #22
    float Output_CallOut22;
    CalcBlendFloatAndAccumulate(TotalMask_CallOut15, float(1), float(0), 
        Output_CallOut22);

	// Function call #23
    float4 OutputUV_CallOut23;
    CalcSurfaceUVSet_ScaleAndOffset(In.UVSet0, OutputScale_CallOut9, 
        OutputOffset_CallOut9, OutputUV_CallOut23);

	// Function call #24
    float Output_CallOut24;
    SampleSingleChannel(OutputUV_CallOut23, DistributionMap0, int(3), 
        Output_CallOut24);

	// Function call #25
    float3 WorldNormalOut_CallOut25;
    CalculateNormalFromColor(OutputColor_CallOut19, VectorOut_CallOut0, 
        VectorOut_CallOut10, VectorOut_CallOut1, WorldNormalOut_CallOut25);

	// Function call #26
    float3 WorldNormalOut_CallOut26;
    CalculateNormalFromColor(OutputColor_CallOut21, VectorOut_CallOut0, 
        VectorOut_CallOut12, VectorOut_CallOut3, WorldNormalOut_CallOut26);

	// Function call #27
    float3 OutputColor_CallOut27;
    SampleLayerTextureRGB(OutputUV_CallOut23, BaseMap3, OutputColor_CallOut27);

	// Function call #28
    float3 OutputColor_CallOut28;
    SampleLayerTextureRGB(OutputUV_CallOut23, NormalMap3, OutputColor_CallOut28);

	// Function call #29
    float Output_CallOut29;
    InverseRatio(Output_CallOut22, Output_CallOut29);

	// Function call #30
    float4 OutputUV_CallOut30;
    CalcSurfaceUVSet_ScaleAndOffset(In.UVSet0, OutputScale_CallOut7, 
        OutputOffset_CallOut7, OutputUV_CallOut30);

	// Function call #31
    float Output_CallOut31;
    SampleSingleChannel(OutputUV_CallOut30, DistributionMap0, int(1), 
        Output_CallOut31);

	// Function call #32
    float3 OutputColor_CallOut32;
    SampleLayerTextureRGB(OutputUV_CallOut30, BaseMap1, OutputColor_CallOut32);

	// Function call #33
    float3 OutputColor_CallOut33;
    SampleLayerTextureRGB(OutputUV_CallOut30, NormalMap1, OutputColor_CallOut33);

	// Function call #34
    float3 WorldNormalOut_CallOut34;
    CalculateNormalFromColor(OutputColor_CallOut28, VectorOut_CallOut0, 
        VectorOut_CallOut13, VectorOut_CallOut4, WorldNormalOut_CallOut34);

	// Function call #35
    float gMask0_Out_CallOut35;
    float gMask1_Out_CallOut35;
    float gMask2_Out_CallOut35;
    float gMask3_Out_CallOut35;
    ComputeTotalMaskValue(float(0.0f), Output_CallOut31, float(0.0f), 
        Output_CallOut24, OutputRed_CallOut15, OutputGreen_CallOut15, 
        OutputBlue_CallOut15, OutputAlpha_CallOut15, g_DistMaskStrength, 
        gMask0_Out_CallOut35, gMask1_Out_CallOut35, gMask2_Out_CallOut35, 
        gMask3_Out_CallOut35);

	// Function call #36
    float3 OutputColor_CallOut36;
    CalcBlendRGBAndAccumulate(gMask0_Out_CallOut35, WorldNormalOut_CallOut25, 
        float3(0,0,0), OutputColor_CallOut36);

	// Function call #37
    float3 WorldNormalOut_CallOut37;
    CalculateNormalFromColor(OutputColor_CallOut33, VectorOut_CallOut0, 
        VectorOut_CallOut11, VectorOut_CallOut2, WorldNormalOut_CallOut37);

	// Function call #38
    float3 OutputColor_CallOut38;
    CalcBlendRGBAndAccumulate(gMask0_Out_CallOut35, OutputColor_CallOut18, 
        float3(0,0,0), OutputColor_CallOut38);

	// Function call #39
    float3 OutputColor_CallOut39;
    CalcBlendRGBAndAccumulate(gMask1_Out_CallOut35, WorldNormalOut_CallOut37, 
        OutputColor_CallOut36, OutputColor_CallOut39);

	// Function call #40
    float3 OutputColor_CallOut40;
    CalcBlendRGBAndAccumulate(gMask2_Out_CallOut35, WorldNormalOut_CallOut26, 
        OutputColor_CallOut39, OutputColor_CallOut40);

	// Function call #41
    float3 OutputColor_CallOut41;
    CalcBlendRGBAndAccumulate(gMask3_Out_CallOut35, WorldNormalOut_CallOut34, 
        OutputColor_CallOut40, OutputColor_CallOut41);

	// Function call #42
    float3 OutputColor_CallOut42;
    CalcBlendRGBAndAccumulate(Output_CallOut29, VectorOut_CallOut0, 
        OutputColor_CallOut41, OutputColor_CallOut42);

	// Function call #43
    float3 OutputColor_CallOut43;
    CalcBlendRGBAndAccumulate(gMask1_Out_CallOut35, OutputColor_CallOut32, 
        OutputColor_CallOut38, OutputColor_CallOut43);

	// Function call #44
    float3 VectorOut_CallOut44;
    NormalizeFloat3(OutputColor_CallOut42, VectorOut_CallOut44);

	// Function call #45
    float3 OutputColor_CallOut45;
    CalcBlendRGBAndAccumulate(gMask2_Out_CallOut35, OutputColor_CallOut20, 
        OutputColor_CallOut43, OutputColor_CallOut45);

	// Function call #46
    float3 AmbientAccumOut_CallOut46;
    float3 DiffuseAccumOut_CallOut46;
    float3 SpecularAccumOut_CallOut46;
    Light(In.WorldPos, VectorOut_CallOut44, int(1), bool(false), float(1.0), 
        float3(0.0, 0.0, 0.0), g_PointWorldPosition0, g_PointAmbient0, 
        g_PointDiffuse0, g_PointSpecular0, g_PointAttenuation0, 
        float3(-1.0, -1.0, 0.0), float3(1.0, 0.0, 0.0), 
        float4(1.0, 1.0, 1.0, 1.0), g_AmbientLight, float3(0.0, 0.0, 0.0), 
        float3(0.0, 0.0, 0.0), AmbientAccumOut_CallOut46, 
        DiffuseAccumOut_CallOut46, SpecularAccumOut_CallOut46);

	// Function call #47
    float3 OutputColor_CallOut47;
    CalcBlendRGBAndAccumulate(gMask3_Out_CallOut35, OutputColor_CallOut27, 
        OutputColor_CallOut45, OutputColor_CallOut47);

	// Function call #48
    float3 AmbientAccumOut_CallOut48;
    float3 DiffuseAccumOut_CallOut48;
    float3 SpecularAccumOut_CallOut48;
    Light(In.WorldPos, VectorOut_CallOut44, int(0), bool(false), 
        ShadowOut_CallOut14, float3(0.0, 0.0, 0.0), g_ShadowDirWorldPosition0, 
        g_ShadowDirAmbient0, g_ShadowDirDiffuse0, g_ShadowDirSpecular0, 
        float3(0.0, 1.0, 0.0), float3(-1.0, -1.0, 0.0), 
        g_ShadowDirWorldDirection0, float4(1.0, 1.0, 1.0, 1.0), 
        AmbientAccumOut_CallOut46, DiffuseAccumOut_CallOut46, 
        float3(0.0, 0.0, 0.0), AmbientAccumOut_CallOut48, 
        DiffuseAccumOut_CallOut48, SpecularAccumOut_CallOut48);

	// Function call #49
    float3 OutputColor_CallOut49;
    CalcBlendRGBAndAccumulate(Output_CallOut29, float3(1,1,1), 
        OutputColor_CallOut47, OutputColor_CallOut49);

	// Function call #50
    float3 AmbientAccumOut_CallOut50;
    float3 DiffuseAccumOut_CallOut50;
    float3 SpecularAccumOut_CallOut50;
    Light(In.WorldPos, VectorOut_CallOut44, int(2), bool(false), float(1.0), 
        float3(0.0, 0.0, 0.0), g_SpotWorldPosition0, g_SpotAmbient0, 
        g_SpotDiffuse0, g_SpotSpecular0, g_SpotAttenuation0, 
        g_SpotSpotAttenuation0, g_SpotWorldDirection0, 
        float4(1.0, 1.0, 1.0, 1.0), AmbientAccumOut_CallOut48, 
        DiffuseAccumOut_CallOut48, float3(0.0, 0.0, 0.0), 
        AmbientAccumOut_CallOut50, DiffuseAccumOut_CallOut50, 
        SpecularAccumOut_CallOut50);

	// Function call #51
    float3 Diffuse_CallOut51;
    float3 Specular_CallOut51;
    ComputeShadingCoefficients(g_MaterialEmissive, Color_CallOut5, 
        g_MaterialAmbient, float3(1.0, 1.0, 1.0), float3(0.0, 0.0, 0.0), 
        DiffuseAccumOut_CallOut50, AmbientAccumOut_CallOut50, bool(false), 
        Diffuse_CallOut51, Specular_CallOut51);

	// Function call #52
    float3 Output_CallOut52;
    MultiplyFloat3(Diffuse_CallOut51, OutputColor_CallOut49, Output_CallOut52);

	// Function call #53
    float3 OutputColor_CallOut53;
    CompositeFinalRGBColor(Output_CallOut52, Specular_CallOut51, 
        OutputColor_CallOut53);

	// Function call #54
    CompositeFinalRGBAColor(OutputColor_CallOut53, Opacity_CallOut5, Out.Color0);

    return Out;
}

