// cockpit PS3 for masking

cbuffer _Globals : register(b0)
{

  struct
  {
    float4 vPlane;
    float4 vSettings;
  } g_ClipPlane : packoffset(c0);

  float4x4 g_mCloudsShadowsSpace : packoffset(c2);
  float4 g_vCloudsShadowDesc : packoffset(c6);
  float4 g_vKSettings : packoffset(c7);
  float4x4 g_mPrevObjViewProj : packoffset(c8);
  float4 specColor : packoffset(c12);
  float4 ControlData : packoffset(c13);
  float4 difColor : packoffset(c14);
  float4 ambient : packoffset(c15);
  float4 g_vDefLightDir : packoffset(c16);
  float4 g_vDefLightColor : packoffset(c17);
  float4 g_vDefSpecColor : packoffset(c18);
  // uint CS_FRONT : packoffset(c19) = {  Unknown bad code for initializer (needs manual fix):
  //      = 0x00000000 
    // uint CS_RIGHT : packoffset(c19) = {    Unknown bad code for initializer (needs manual fix):
    //      = 0x00000001 
      // uint CS_BACK : packoffset(c19) = {      Unknown bad code for initializer (needs manual fix):
      //      = 0x00000002 
        // uint CS_LEFT : packoffset(c19) = {        Unknown bad code for initializer (needs manual fix):
        //      = 0x00000003 
          // uint CS_TOP : packoffset(c20) = {          Unknown bad code for initializer (needs manual fix):
          //      = 0x00000004 
            // uint CS_BOTTOM : packoffset(c20) = {            Unknown bad code for initializer (needs manual fix):
            //      = 0x00000005 
  float4 g_vAmbientSettings : packoffset(c21);

  struct
  {
    float4 vDesc;
    float4 vFogLayerPlane;
    float4 vFogLayerColor;
    float4 vFogLayerSettings;
    float4 vFogColor;
    float4 vFogDistance;
  } g_FogDesc : packoffset(c22);

  float4 g_vScreenDepthRect : packoffset(c28);
  float4x4 g_mViewProj : packoffset(c29);
  float4x4 g_mView : packoffset(c33);
  float3 g_vCamPos : packoffset(c37);
  float4 g_vSkyColor : packoffset(c38);
  float4 g_vFogK : packoffset(c39);

  struct
  {
    float4x4 mLightSpaceInverse;
    float4x4 mLightSpace;
    float4 vShadowBias;
    float4 vBiasDir;
    float4 vSmoothOffs;
    float4 vShadowsDesc;
    float4 avCPlane[8];
    float4 avCascadeZ[2];
    float4 avUVTransform[8];
    float4 avZTransformZF[8];
  } g_ShadSettings : packoffset(c40);

}

cbuffer CBLightSettings : register(b1)
{

  struct
  {
    float4 vLightsListSettings2;
    float4 vShadowLODYPos;
    float4 vShadowLODXSZ;
    float4 vShadowLODYSZ;
    float4 vShadowTexRes;
  } g_LightListSettings : packoffset(c0);

  float4 g_avLODMask[4] : packoffset(c5);
  float4 g_avRot[6] : packoffset(c9);
  float4 g_avLightsInfo[2048] : packoffset(c15);
}

SamplerState CloudsShadowsSampler_s : register(s0);
SamplerState AmbientSampler_s : register(s2);
SamplerState DPattern0Sampler_s : register(s3);
SamplerState DPattern1Sampler_s : register(s4);
SamplerState DPattern2Sampler_s : register(s5);
SamplerState DamageSampler_s : register(s6);
SamplerState SSAOSampler_s : register(s7);
SamplerState AlphaSampler_s : register(s8);
SamplerState DiffuseSampler_s : register(s9);
SamplerState SelfIllumSampler_s : register(s10);
SamplerComparisonState LightsShadowsSampler_s : register(s1);
SamplerComparisonState shadowSamplerF_s : register(s11);
Texture2D<float4> DamageSampler : register(t0);
Texture2D<float4> DPattern0Sampler : register(t1);
Texture2D<float4> DPattern2Sampler : register(t2);
Texture2D<float4> DPattern1Sampler : register(t3);
Texture2D<float4> DiffuseSampler : register(t4);
Texture2D<float4> AlphaSampler : register(t5);
Texture2D<float4> SelfIllumSampler : register(t6);
Texture2D<float4> CloudsShadowsSampler : register(t7);
Texture2D<float4> SSAOSampler : register(t8);
TextureCube<float4> AmbientSampler : register(t9);
Texture2D<float4> g_tLightsShadows : register(t10);
Texture3D<uint2> g_tLightsList : register(t11);
Texture2DArray<float4> g_tDepthTexture : register(t12);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);

  uint CS_FRONT = 0x00000000; 
  uint CS_RIGHT = 0x00000001;
  uint CS_BACK  =  0x00000002;
  uint CS_LEFT  = 0x00000003;
  uint CS_TOP  =  0x00000004; 
  uint CS_BOTTOM  =  0x00000005;

void main(
  float4 v0 : SV_Position0,
  float2 v1 : TEXCOORD0,
  float2 w1 : COLOR0,
  float4 v2 : TEXCOORD1,
  float4 v3 : TEXCOORD2,
  float4 v4 : TEXCOORD3,
  float4 v5 : TEXCOORD4,
  float4 v6 : TEXCOORD5,
  float4 v7 : TEXCOORD6,
  float4 v8 : TEXCOORD7,
  float v9 : SV_ClipDistance0,
  out float4 o0 : SV_Target0,
  out float4 o7 : SV_Target7)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15;
  uint4 bitmask, uiDest;
  float4 fDest;

              r0.xyzw = cmp(g_ShadSettings.avCascadeZ[0].xyzw < v3.wwww);
              r0.xyzw = r0.xyzw ? float4(1,1,1,1) : 0;
              r0.x = dot(float4(1,1,1,1), r0.xyzw);
              r1.xyzw = cmp(g_ShadSettings.avCascadeZ[1].xyzw < v3.wwww);
              r1.xyzw = r1.xyzw ? float4(1,1,1,1) : 0;
              r0.y = dot(float4(1,1,1,1), r1.xyzw);
              r0.z = r0.x + r0.y;
              r0.w = (uint)r0.z;
              r1.xy = v3.xy * g_ShadSettings.avUVTransform[r0.w].zw + g_ShadSettings.avUVTransform[r0.w].xy;
              r1.z = v3.z * g_ShadSettings.avZTransformZF[r0.w].y + g_ShadSettings.avZTransformZF[r0.w].x;
              r1.w = g_ShadSettings.vShadowsDesc.z * v3.w;
              r2.xyzw = cmp(g_ShadSettings.avCascadeZ[0].xyzw < r1.wwww);
              r2.xyzw = r2.xyzw ? float4(1,1,1,1) : 0;
              r2.x = dot(float4(1,1,1,1), r2.xyzw);
              r3.xyzw = cmp(g_ShadSettings.avCascadeZ[1].xyzw < r1.wwww);
              r3.xyzw = r3.xyzw ? float4(1,1,1,1) : 0;
              r1.w = dot(float4(1,1,1,1), r3.xyzw);
              r2.z = r2.x + r1.w;
              r1.w = cmp(r0.z < r2.z);
              if (r1.w != 0) {
                r1.w = (uint)r2.z;
                r3.xy = v3.xy * g_ShadSettings.avUVTransform[r1.w].zw + g_ShadSettings.avUVTransform[r1.w].xy;
                r1.w = v3.z * g_ShadSettings.avZTransformZF[r1.w].y + g_ShadSettings.avZTransformZF[r1.w].x;
                r2.w = -g_ShadSettings.avZTransformZF[r0.w].w * g_ShadSettings.vShadowsDesc.w + v3.w;
                r0.w = -g_ShadSettings.avZTransformZF[r0.w].w * g_ShadSettings.vShadowsDesc.w + g_ShadSettings.avZTransformZF[r0.w].w;
                r0.w = r2.w / r0.w;
              } else {
                r3.xy = r1.xy;
                r1.w = r1.z;
                r2.z = r0.z;
                r0.w = 0;
              }
              r2.w = cmp(0 < r0.w);
              r3.zw = float2(0,-1);
              while (true) {
                r4.x = cmp(1 < (int)r3.w);
                if (r4.x != 0) break;
                r4.y = (int)r3.w;
                r4.z = r3.z;
                r4.w = -1;
                while (true) {
                  r5.x = cmp(1 < (int)r4.w);
                  if (r5.x != 0) break;
                  r4.x = (int)r4.w;
                  r5.xy = g_ShadSettings.vSmoothOffs.xx * r4.xy;
                  r0.xy = r5.xy * float2(0.5,0.5) + r1.xy;
                  r0.x = g_tDepthTexture.SampleCmpLevelZero(shadowSamplerF_s, r0.xyz, r1.z).x;
                  if (r2.w != 0) {
                    r2.xy = r5.xy * float2(0.5,0.5) + r3.xy;
                    r0.y = g_tDepthTexture.SampleCmpLevelZero(shadowSamplerF_s, r2.xyz, r1.w).x;
                    r0.y = r0.y + -r0.x;
                    r0.x = r0.w * r0.y + r0.x;
                  }
                  r4.z = r4.z + r0.x;
                  r4.w = (int)r4.w + 1;
                }
                r3.z = r4.z;
                r3.w = (int)r3.w + 1;
              }
              r0.x = cmp(v2.z >= 0.25);
              if (r0.x != 0) {
                r0.xyzw = DamageSampler.Sample(DamageSampler_s, v1.xy).xyzw;
                r1.xy = cmp(v2.zz >= float2(0.5,0.75));
                if (r1.x != 0) {
                  r0.x = max(r0.x, r0.y);
                }
                if (r1.y != 0) {
                  r0.x = max(r0.x, r0.z);
                }
                r0.y = cmp(0.75 < r0.x);
                if (r0.y != 0) {
                  r0.z = -1;
                }
                if (r0.y == 0) {
                  r1.x = cmp(r0.w < 0.330000013);
                  if (r1.x != 0) {
                    r1.xyzw = DPattern0Sampler.Sample(DPattern0Sampler_s, v2.xy).wxyz;
                    r2.xyz = r1.yzw;
                  } else {
                    r0.w = cmp(0.660000026 < r0.w);
                    if (r0.w != 0) {
                      r1.xyzw = DPattern2Sampler.Sample(DPattern2Sampler_s, v2.xy).wxyz;
                      r2.xyz = r1.yzw;
                    } else {
                      r1.xyzw = DPattern1Sampler.Sample(DPattern1Sampler_s, v2.xy).wxyz;
                      r2.xyz = r1.yzw;
                    }
                  }
                  r0.w = r0.x + r0.x;
                  r0.x = min(1, r0.w);
                } else {
                  r2.xyz = float3(0,0,0);
                  r1.x = 0;
                }
              } else {
                r2.xyz = float3(0,0,0);
                r1.x = 0;
                r0.xy = float2(0,0);
              }
              if (r0.y == 0) {
                r0.z = r0.x;
              }
              r0.x = cmp(r0.z < -0.5);
              if (r0.x != 0) {
                if (-1 != 0) discard;
              }
              r4.xyzw = DiffuseSampler.Sample(DiffuseSampler_s, v1.xy).xyzw;
              r0.x = 0.5;
              r0.y = r4.w;
              r5.xw = AlphaSampler.Sample(AlphaSampler_s, r0.xy).xz;
              r0.x = cmp(r5.w < 0.5);
              if (r0.x != 0) {
                if (-1 != 0) discard;
              }
              r0.x = 0.111111112 * r3.z;
              r1.y = 0.5;
              r0.y = AlphaSampler.Sample(AlphaSampler_s, r1.yx).x;
              r0.w = dot(v7.xyz, v7.xyz);
              r0.w = rsqrt(r0.w);
              r1.xyz = v7.xyz * r0.www;
              r3.xy = cmp(float2(0.00999999978,0.00999999978) < w1.xy);
              r0.w = (int)r3.y | (int)r3.x;
              if (r0.w != 0) {
                r6.xyzw = SelfIllumSampler.Sample(SelfIllumSampler_s, v1.xy).xyzw;
                r0.w = w1.x + w1.x;
                r3.xyw = r6.xyz * r0.www;
                r0.w = w1.y * r6.w;
              } else {
                r3.xyw = float3(0,0,0);
                r0.w = 0;
              }
              r2.xyz = -r4.xyz + r2.xyz;
              r2.xyz = r0.zzz * r2.xyz + r4.xyz;
              r2.xyz = difColor.xyz * r2.xyz;
              r2.xyz = float3(1.70000005,1.70000005,1.70000005) * r2.xyz;
              r0.y = r0.y + -r5.x;
              r0.y = r0.z * r0.y + r5.x;
              r4.xyz = specColor.xyz * r0.yyy;
              r0.y = -r3.z * 0.111111112 + 1;
              r0.x = v4.w * r0.y + r0.x;
              r0.y = CloudsShadowsSampler.Sample(CloudsShadowsSampler_s, v4.xy).y;
              r0.z = g_vCloudsShadowDesc.z * v4.z;
              r0.y = -1 + r0.y;
              r0.y = r0.z * r0.y + 1;
              r0.x = r0.x * r0.y;
              r0.yz = v8.xy / v8.ww;
              r6.xy = g_LightListSettings.vLightsListSettings2.xy * r0.yz;
              r6.yz = (int2)r6.xy;
              r6.w = 0;
              r7.xy = g_tLightsList.Load(r6.yzww).xy;
              r1.w = min(17, (uint)r7.y);
              r2.w = cmp(0.5 < g_LightListSettings.vLightsListSettings2.w);
              r7.yzw = float3(0,0,0);
              r8.xyz = float3(0,0,0);
              r3.z = 1;
              r6.x = 0;
              r4.w = r7.x;
              while (true) {
                r8.w = cmp((int)r3.z >= (int)r1.w);
                if (r8.w != 0) break;
                if (r3.z != 0) {
                  r6.x = (int)r6.x + 1;
                  r4.w = g_tLightsList.Load(r6.yzxw).x;
                }
                r8.w = (uint)r4.w << 3;
                r9.x = (int)r8.w + 1;
                r9.yz = cmp(g_avLightsInfo[r9.x].xy >= float2(100,100));
                if (r9.y != 0) {
                  r10.x = g_avLightsInfo[r9.x].x + -100;
                } else {
                  r10.x = g_avLightsInfo[r9.x].x;
                }
                if (r9.z != 0) {
                  r10.y = g_avLightsInfo[r9.x].y + -100;
                } else {
                  r10.y = g_avLightsInfo[r9.x].y;
                }
                r9.w = cmp(1 < g_avLightsInfo[r8.w].w);
                if (r9.w != 0) {
                  r11.xyz = g_avLightsInfo[r8.w].xyz + -v6.xyz;
                  r9.w = dot(r11.xyz, r11.xyz);
                  r11.w = sqrt(r9.w);
                  r11.xyz = r11.xyz / r11.www;
                  r9.w = r9.w * g_avLightsInfo[r9.x].w + 1;
                  r9.w = 1 / r9.w;
                  r9.w = -0.100000001 + r9.w;
                  r9.w = saturate(1.11111116 * r9.w);
                  r11.w = (int)r9.x + 1;
                  r12.x = cmp(2 < g_avLightsInfo[r8.w].w);
                  if (r12.x != 0) {
                    r12.y = g_avLightsInfo[r8.w].w + -3;
                    r12.z = dot(r11.xyz, g_avLightsInfo[r11.w].xyz);
                    r12.w = 1 + -abs(r12.z);
                    r12.w = sqrt(r12.w);
                    r13.x = abs(r12.z) * -0.0187292993 + 0.0742610022;
                    r13.x = r13.x * abs(r12.z) + -0.212114394;
                    r13.x = r13.x * abs(r12.z) + 1.57072878;
                    r13.y = r13.x * r12.w;
                    r13.y = r13.y * -2 + 3.14159274;
                    r12.z = cmp(r12.z < -r12.z);
                    r12.z = r12.z ? r13.y : 0;
                    r12.z = r13.x * r12.w + r12.z;
                    r12.w = cmp(r12.z < r12.y);
                    if (r12.w != 0) {
                      r12.w = frac(g_avLightsInfo[r11.w].w);
                      r12.y = r12.z / r12.y;
                      r12.y = r12.y + -r12.w;
                      r12.z = 1 + -r12.w;
                      r12.y = saturate(r12.y / r12.z);
                      r12.y = 1 + -r12.y;
                    } else {
                      r12.y = 0;
                    }
                    r9.w = r12.y * r9.w;
                    r12.y = cmp(0 < r9.w);
                    r12.z = cmp(g_avLightsInfo[r11.w].w >= 1);
                    r12.y = r12.z ? r12.y : 0;
                    if (r12.y != 0) {
                      r12.y = (int)g_avLightsInfo[r11.w].w;
                      r12.y = (int)r12.y + -1;
                    } else {
                      r12.y = -1;
                    }
                    r13.xyz = v6.xyz;
                  } else {
                    r12.z = cmp(0 < r9.w);
                    r9.z = r9.z ? r12.z : 0;
                    if (r9.z != 0) {
                      r9.z = cmp(g_avLightsInfo[r11.w].w >= 1);
                      if (r9.z != 0) {
                        r9.z = (int)g_avLightsInfo[r11.w].w;
                        r9.z = (int)r9.z + -1;
                        r14.xyz = -g_avLightsInfo[r8.w].xyz + v6.xyz;
                        r12.zw = cmp(abs(r14.xz) < r14.yy);
                        r11.w = r12.w ? r12.z : 0;
                        if (r11.w != 0) {
                          r11.w = CS_TOP;
                        } else {
                          r12.zw = cmp(r14.yy < -abs(r14.xz));
                          r12.z = r12.w ? r12.z : 0;
                          if (r12.z != 0) {
                            r11.w = CS_BOTTOM;
                          } else {
                            r12.z = cmp(abs(r14.x) < r14.z);
                            if (r12.z != 0) {
                              r11.w = CS_FRONT;
                            } else {
                              r12.z = cmp(r14.z < -abs(r14.x));
                              if (r12.z != 0) {
                                r11.w = CS_BACK;
                              } else {
                                r12.z = cmp(r14.x >= 0);
                                if (r12.z != 0) {
                                  r11.w = CS_RIGHT;
                                } else {
                                  r11.w = CS_LEFT;
                                }
                              }
                            }
                          }
                        }
                        r12.z = cmp((uint)r11.w < CS_TOP);
                        if (r12.z != 0) {
                          r15.x = dot(r14.xz, g_avRot[r11.w].xy);
                          r15.z = dot(r14.xz, g_avRot[r11.w].zw);
                          r15.y = r14.y;
                        } else {
                          r15.y = dot(r14.yz, g_avRot[r11.w].xy);
                          r15.z = dot(r14.yz, g_avRot[r11.w].zw);
                          r15.x = r14.x;
                        }
                        r13.xyz = g_avLightsInfo[r8.w].xyz + r15.xyz;
                        r12.y = (int)r9.z + (int)r11.w;
                      } else {
                        r12.y = -1;
                        r13.xyz = v6.xyz;
                      }
                    } else {
                      r12.y = -1;
                      r13.xyz = v6.xyz;
                    }
                  }
                  r9.z = cmp((int)r12.y >= 0);
                  if (r9.z != 0) {
                    r9.z = (int)r9.x + 3;
                    r11.w = (int)r9.z | 5;
                    r12.z = (int)r11.w + 1;
                    r12.w = (int)r12.z | 7;
                    r14.xyzw = g_avLightsInfo[r11.w].xyzw * r13.yyyy;
                    r14.xyzw = r13.xxxx * g_avLightsInfo[r9.z].xyzw + r14.xyzw;
                    r13.xyzw = r13.zzzz * g_avLightsInfo[r12.z].xyzw + r14.xyzw;
                    r13.xyzw = g_avLightsInfo[r12.w].xyzw + r13.xyzw;
                    r13.xyz = r13.xyz / r13.www;
                    r12.zw = cmp(float2(1,1) < abs(r13.xy));
                    r9.z = (int)r12.w | (int)r12.z;
                    if (r9.z != 0) {
                      r11.w = 0;
                    }
                    if (r9.z == 0) {
                      r9.z = r13.x * 0.5 + 0.5;
                      r12.z = -r13.y * 0.5 + 0.5;
                      r12.w = (uint)r12.y >> 5;
                      r12.y = (int)r12.y & 31;
                      r13.x = dot(g_LightListSettings.vShadowLODXSZ.xyzw, g_avLODMask[r12.w].xyzw);
                      if (r12.x == 0) {
                        r13.y = g_LightListSettings.vShadowTexRes.x * r13.x;
                        r13.y = 0.5 / r13.y;
                        r13.w = 1 + -r13.y;
                        r14.x = max(r13.y, r9.z);
                        r9.z = min(r14.x, r13.w);
                        r13.y = max(r13.y, r12.z);
                        r12.z = min(r13.y, r13.w);
                      }
                      r12.y = (uint)r12.y;
                      r9.z = r12.y + r9.z;
                      r14.x = r9.z * r13.x;
                      r9.z = dot(g_LightListSettings.vShadowLODYPos.xyzw, g_avLODMask[r12.w].xyzw);
                      r12.y = dot(r12.zz, r13.xx);
                      r14.y = r12.y + r9.z;
                      r11.w = g_tLightsShadows.SampleCmpLevelZero(LightsShadowsSampler_s, r14.xy, r13.z).x;
                      r9.z = r2.w ? r12.x : 0;
                      if (r9.z != 0) {
                        r12.yz = -g_LightListSettings.vShadowTexRes.zw + r14.xy;
                        r9.z = g_tLightsShadows.SampleCmpLevelZero(LightsShadowsSampler_s, r12.yz, r13.z).x;
                        r9.z = r11.w + r9.z;
                        r12.xw = g_LightListSettings.vShadowTexRes.zw + r14.xy;
                        r12.z = g_tLightsShadows.SampleCmpLevelZero(LightsShadowsSampler_s, r12.xz, r13.z).x;
                        r9.z = r12.z + r9.z;
                        r12.y = g_tLightsShadows.SampleCmpLevelZero(LightsShadowsSampler_s, r12.yw, r13.z).x;
                        r9.z = r12.y + r9.z;
                        r12.x = g_tLightsShadows.SampleCmpLevelZero(LightsShadowsSampler_s, r12.xw, r13.z).x;
                        r9.z = r12.x + r9.z;
                        r11.w = 0.200000003 * r9.z;
                      }
                    }
                    r9.w = r11.w * r9.w;
                  }
                } else {
                  r11.xyz = -g_avLightsInfo[r8.w].xyz;
                  r9.w = 1;
                }
                r8.w = cmp(0 < r9.w);
                if (r8.w != 0) {
                  r8.w = dot(r11.xyz, r1.xyz);
                  r9.z = cmp(0 < r8.w);
                  if (r9.z != 0) {
                    r10.z = g_avLightsInfo[r9.x].z;
                    r12.xyz = r10.xyz * r8.www;
                    r12.xyz = r12.xyz * r9.www;
                  } else {
                    r12.xyz = float3(0,0,0);
                  }
                  if (r9.y == 0) {
                    r11.xyz = v5.xyz + r11.xyz;
                    r11.xyz = float3(0.5,0.5,0.5) * r11.xyz;
                    r8.w = dot(r11.xyz, r11.xyz);
                    r8.w = rsqrt(r8.w);
                    r11.xyz = r11.xyz * r8.www;
                    r8.w = dot(r11.xyz, r1.xyz);
                    r9.y = cmp(0 < r8.w);
                    if (r9.y != 0) {
                      r8.w = log2(r8.w);
                      r8.w = specColor.w * r8.w;
                      r8.w = exp2(r8.w);
                      r9.y = sqrt(r9.w);
                      r8.w = r9.y * r8.w;
                      r10.w = g_avLightsInfo[r9.x].z;
                      r9.xyz = r10.xyw * r8.www;
                      r9.xyz = r9.xyz * r4.xyz;
                    } else {
                      r9.xyz = float3(0,0,0);
                    }
                  } else {
                    r9.xyz = float3(0,0,0);
                  }
                  r7.yzw = r12.xyz + r7.yzw;
                  r8.xyz = r9.xyz + r8.xyz;
                }
                r3.z = (int)r3.z + 1;
              }
              r1.w = dot(g_vDefLightDir.xyz, r1.xyz);
              r1.w = max(0, -r1.w);
              r6.xyz = g_vDefLightColor.xyz * r1.www;
              r9.xyz = -g_vDefLightDir.xyz + v5.xyz;
              r9.xyz = float3(0.5,0.5,0.5) * r9.xyz;
              r1.w = dot(r9.xyz, r9.xyz);
              r1.w = rsqrt(r1.w);
              r9.xyz = r9.xyz * r1.www;
              r1.w = dot(r9.xyz, r1.xyz);
              r1.w = max(0, r1.w);
              r2.w = cmp(0.00400000019 < r1.w);
              if (r2.w != 0) {
                r1.w = log2(r1.w);
                r1.w = specColor.w * r1.w;
                r1.w = exp2(r1.w);
                r9.xyz = g_vDefSpecColor.xyz * r1.www;
                r4.xyz = r9.xyz * r4.xyz;
              } else {
                r4.xyz = float3(0,0,0);
              }
              r6.xyz = r6.xyz * r0.xxx + r7.yzw;
              r3.xyz = r6.xyz + r3.xyw;
              r1.w = dot(ambient.xyz, ambient.xyz);
              r1.w = sqrt(r1.w);
              r1.w = -0.800000012 + r1.w;
              r6.x = saturate(-r1.w * 5 + 1);
              r0.yz = r0.yz * g_vScreenDepthRect.zw + g_vScreenDepthRect.xy;
              r0.y = SSAOSampler.Sample(SSAOSampler_s, r0.yz).y;
              r0.z = cmp(0.5 < g_vAmbientSettings.x);
              if (r0.z != 0) {
                r1.xyz = AmbientSampler.Sample(AmbientSampler_s, r1.xyz).xyz;
                r0.z = max(ambient.y, ambient.z);
                r0.z = max(ambient.x, r0.z);
                r1.w = max(r1.y, r1.z);
                r1.w = max(r1.x, r1.w);
                r2.w = cmp(r1.w < r0.z);
                if (r2.w != 0) {
                  r0.z = r0.z / r1.w;
                  r1.xyz = r1.xyz * r0.zzz;
                }
              } else {
                r1.xyz = ambient.xyz;
              }
              r1.xyz = r0.yyy * r1.xyz + r3.xyz;
              r6.yzw = float3(1,0.400000006,0.800000012);
              r0.yzw = r6.xyx * r0.www;
              r0.yzw = r0.yzw * r6.zxw;
              r0.yzw = max(r1.xyz, r0.yzw);
              r1.xyz = r4.xyz * r0.xxx;
              r0.xyz = r0.yzw * r2.xyz + r1.xyz;
              r0.xyz = r0.xyz + r8.xyz;
              r1.xyz = saturate(g_vFogK.xyz);
              r0.w = cmp(g_FogDesc.vFogLayerSettings.w < 0.5);
              if (r0.w != 0) {
                r2.xyz = g_vSkyColor.xyz + -r0.xyz;
                r5.xyz = r1.xyz * r2.xyz + r0.xyz;
              }
              if (r0.w == 0) {
                r0.w = saturate(g_vFogK.w);
                r1.w = g_vSkyColor.w * g_vSkyColor.w;
                r2.xyz = g_vDefLightColor.xyz * r1.www + ambient.xyz;
                r1.w = cmp(g_FogDesc.vDesc.z >= 0);
                if (r1.w != 0) {
                  r3.xyz = g_FogDesc.vFogLayerColor.xyz * r2.xyz + -r0.xyz;
                  r3.xyz = r0.www * r3.xyz + r0.xyz;
                  r4.xyz = g_vSkyColor.xyz + -r3.xyz;
                  r5.xyz = r1.xyz * r4.xyz + r3.xyz;
                } else {
                  r1.w = g_FogDesc.vFogLayerSettings.z * -g_FogDesc.vFogLayerPlane.w;
                  r1.w = min(1, r1.w);
                  r2.w = cmp(r1.w < 0.999899983);
                  if (r2.w != 0) {
                    r1.w = r1.w * r1.w;
                    r3.xyz = g_FogDesc.vFogLayerColor.xyz * r2.xyz + -r0.xyz;
                    r3.xyz = r0.www * r3.xyz + r0.xyz;
                    r4.xyz = g_vSkyColor.xyz + -r3.xyz;
                    r3.xyz = r1.xyz * r4.xyz + r3.xyz;
                    r4.xyz = g_vSkyColor.xyz + -r0.xyz;
                    r4.xyz = r1.xyz * r4.xyz + r0.xyz;
                    r6.xyz = g_FogDesc.vFogLayerColor.xyz * r2.xyz + -r4.xyz;
                    r4.xyz = r0.www * r6.xyz + r4.xyz;
                    r4.xyz = r4.xyz + -r3.xyz;
                    r5.xyz = r1.www * r4.xyz + r3.xyz;
                  } else {
                    r3.xyz = g_vSkyColor.xyz + -r0.xyz;
                    r0.xyz = r1.xyz * r3.xyz + r0.xyz;
                    r1.xyz = g_FogDesc.vFogLayerColor.xyz * r2.xyz + -r0.xyz;
                    r5.xyz = r0.www * r1.xyz + r0.xyz;
                  }
                }
              }
              o0.xyzw = r5.xyzw;
			  o7 = float4(1,1,1,1);
              return;
}

 