// PreFix Shadows

cbuffer FrameConstants : register(b0)
{
  float4x4 g_xView : packoffset(c0);
  float4x4 g_xProj : packoffset(c4);
  float4x4 g_xViewProj : packoffset(c8);
  float4x4 g_xInvView : packoffset(c12);
  float4x4 g_xInvProj : packoffset(c16);
  float4x4 g_xInvViewProj : packoffset(c20);
  float3 g_xCamPos : packoffset(c24);
  float2 g_xRcpScreenDims : packoffset(c25);
  float2 g_xDepthProjViewUnpack : packoffset(c25.z);
  float4 g_axViewFrustumPlanes[6] : packoffset(c26);
}

cbuffer ShadowReadConstants : register(b5)
{
  float g_f2DFilterSize : packoffset(c0);
  float g_fCubeFilterSize : packoffset(c0.y);
  float g_fCubeClampWidth : packoffset(c0.z);
  float g_fSunWidth : packoffset(c0.w);
}

cbuffer ProjectorParams : register(b4)
{
  float2 g_xCameraTanHalfFOV : packoffset(c0);
  float2 g_xTwoOverScreenDims : packoffset(c0.z);
  float4x4 g_xProjectorMatrix : packoffset(c1);
  float4 g_xProjectionDirection : packoffset(c5);
  float4 g_xDetailOffsetScale : packoffset(c6);
  float3 g_xProjectorPos : packoffset(c7);
  bool g_bUseTexture : packoffset(c7.w);
  float3 g_xLightColour : packoffset(c8);
  float g_fDistanceFade : packoffset(c8.w);
  float g_fLightFalloffScale : packoffset(c9);
  float g_fLightFalloffPower : packoffset(c9.y);
  float g_fAngularFalloffOfs : packoffset(c9.z);
  float g_fAngularFalloffScale : packoffset(c9.w);
  float g_fMinRange : packoffset(c10);
  float g_fRcpRange : packoffset(c10.y);
  float g_fShadowStrength : packoffset(c10.z);
  bool g_bUseDetailTexture : packoffset(c10.w);
}

SamplerState g_xPointClamp_s : register(s1);
SamplerState g_xTrilinearWrap_s : register(s2);
SamplerState g_xTrilinearClamp_s : register(s3);
SamplerComparisonState g_xShadowCmpSamplerLessEqual_s : register(s9);
Texture2D<float4> g_xMaterialsTexture : register(t0);
Texture2D<float4> g_xProjectedTexture : register(t1);
Texture2D<float4> g_xProjectedDetailTexture : register(t2);
Texture2D<float4> g_xShadowTexture : register(t3);
Texture2D<float4> g_xNormalBuffer : register(t24);
Texture2D<float4> g_xAlbedoBuffer : register(t25);


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


void main( 
  float4 v0 : SV_Position0,
  float3 v1 : CamDir0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = (int2)v0.xy;
  r0.zw = float2(0,0);
  r1.xyzw = g_xNormalBuffer.Load(r0.xyw).xyzw;
  r0.xyzw = g_xAlbedoBuffer.Load(r0.xyz).xyzw;
  r2.x = dot(r1.xy, r1.xy);
  r3.z = r2.x * 2 + -1;
  r2.x = rsqrt(r2.x);
  r1.xy = r2.xx * r1.xy;
  r2.x = -r3.z * r3.z + 1;
  r2.x = sqrt(r2.x);
  r3.xy = r2.xx * r1.xy;
  r1.xy = g_xCameraTanHalfFOV.xy * r1.ww;
  r2.xy = v0.xy * g_xTwoOverScreenDims.xy + float2(-1,-1);
  r1.xy = r2.xy * r1.xy;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r1.x -= stereo.x * (r1.w - stereo.y)*g_xInvProj._m00;
  r2.xyzw = g_xProjectorMatrix._m01_m11_m21_m31 * r1.yyyy;
  r2.xyzw = g_xProjectorMatrix._m00_m10_m20_m30 * r1.xxxx + r2.xyzw;
  r2.xyzw = g_xProjectorMatrix._m02_m12_m22_m32 * r1.wwww + r2.xyzw;
  r2.xyzw = g_xProjectorMatrix._m03_m13_m23_m33 + r2.xyzw;
  r3.w = cmp(r2.z < 0);
  if (r3.w != 0) discard;
  r4.xyz = r2.xyz / r2.www;
  r5.xy = float2(-0.5,-0.5) + r4.xy;
  r5.xy = float2(0.5,0.5) + -abs(r5.xy);
  r5.xy = cmp(r5.xy < float2(0,0));
  r2.z = (int)r5.y | (int)r5.x;
  if (r2.z != 0) discard;
  r2.z = cmp(0 < g_fShadowStrength);
  if (r2.z != 0) {
    r2.z = 1 / g_f2DFilterSize;
    r5.xy = r2.zz * r4.xy + float2(0.5,0.5);
    r5.zw = floor(r5.xy);
    r5.xy = r5.xy + -r5.zw;
    r6.yz = -r5.xy * g_f2DFilterSize + r4.xy;
    r6.w = r4.z;
    r7.y = -3 * g_f2DFilterSize;
    r7.w = 0;
    r5.zw = float2(0,0);
    r2.z = -3;
    while (true) {
      r3.w = cmp(3 < (int)r2.z);
      if (r3.w != 0) break;
      r3.w = (int)r2.z;
      r7.z = g_f2DFilterSize * r3.w;
      r8.yzw = r7.yzw + r6.yzw;
      r9.xyzw = g_xShadowTexture.Gather(g_xPointClamp_s, r8.yz).xyzw;
      r10.xyzw = cmp(r9.xyzw >= r8.wwww);
      r10.xyzw = r10.xyzw ? float4(0,0,0,0) : float4(1,1,1,1);
      r3.w = dot(r10.xyzw, float4(1,1,1,1));
      r4.w = dot(r9.xyzw, r10.xyzw);
      r8.x = g_f2DFilterSize * 2 + r8.y;
      r9.xyzw = g_xShadowTexture.Gather(g_xPointClamp_s, r8.xz).xyzw;
      r10.xyzw = cmp(r9.xyzw >= r8.wwww);
      r10.xyzw = r10.xyzw ? float4(0,0,0,0) : float4(1,1,1,1);
      r6.x = dot(r10.xyzw, float4(1,1,1,1));
      r3.w = r6.x + r3.w;
      r6.x = dot(r9.xyzw, r10.xyzw);
      r4.w = r6.x + r4.w;
      r8.y = g_f2DFilterSize * 2 + r8.x;
      r9.xyzw = g_xShadowTexture.Gather(g_xPointClamp_s, r8.yz).xyzw;
      r10.xyzw = cmp(r9.xyzw >= r8.wwww);
      r10.xyzw = r10.xyzw ? float4(0,0,0,0) : float4(1,1,1,1);
      r6.x = dot(r10.xyzw, float4(1,1,1,1));
      r3.w = r6.x + r3.w;
      r6.x = dot(r9.xyzw, r10.xyzw);
      r4.w = r6.x + r4.w;
      r8.x = g_f2DFilterSize * 2 + r8.y;
      r9.xyzw = g_xShadowTexture.Gather(g_xPointClamp_s, r8.xz).xyzw;
      r8.xyzw = cmp(r9.xyzw >= r8.wwww);
      r8.xyzw = r8.xyzw ? float4(0,0,0,0) : float4(1,1,1,1);
      r6.x = dot(r8.xyzw, float4(1,1,1,1));
      r3.w = r6.x + r3.w;
      r6.x = dot(r9.xyzw, r8.xyzw);
      r4.w = r6.x + r4.w;
      r5.w = r5.w + r3.w;
      r5.z = r5.z + r4.w;
      r2.z = (int)r2.z + 2;
    }
    r2.z = cmp(0 < r5.w);
    if (r2.z != 0) {
      r2.z = cmp(r5.w >= 64);
      if (r2.z == 0) {
        r3.w = r5.z / r5.w;
        r4.w = r4.z + -r3.w;
        r4.w = g_fSunWidth * r4.w;
        r3.w = saturate(r4.w / r3.w);
        r4.w = r3.w * r3.w;
        r5.z = r4.w * r4.w;
        r5.w = r5.z * r4.w;
        r6.x = 3 * r5.z;
        r3.w = -r3.w * r3.w + 1;
        r6.w = r6.x * r3.w;
        r7.xyzw = r6.wwww * float4(0.00999999978,0.0299999993,0.0599999987,0.0700000003) + r5.wwww;
        r8.x = r7.x + r7.y;
        r8.x = r8.x + r7.z;
        r8.x = r8.x + r7.w;
        r8.x = r8.x + r7.z;
        r8.x = r8.x + r7.y;
        r8.x = r8.x + r7.x;
        r8.x = r8.x + r7.y;
        r8.y = r3.w * r3.w;
        r8.z = r8.y * r4.w;
        r9.xyz = float3(0.1875,0.5625,0.75) * r8.zzz;
        r9.xyzw = r5.zzzz * r4.wwww + r9.yyzx;
        r9.xyzw = r6.wwww * float4(0.280000001,0.280000001,0.360000014,0.129999995) + r9.xyzw;
        r4.w = r9.w + r8.x;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r9.z;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r9.w;
        r4.w = r4.w + r7.y;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r9.y;
        r10.xyz = r8.zzz * float3(1.6875,2.25,2.26200008) + r5.www;
        r5.z = r6.w * 0.620000005 + r10.x;
        r4.w = r5.z + r4.w;
        r8.xw = r6.ww * float2(0.790000021,0.790000021) + r10.yz;
        r4.w = r8.x + r4.w;
        r4.w = r4.w + r5.z;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r7.w;
        r4.w = r4.w + r9.z;
        r4.w = r4.w + r8.x;
        r5.w = r8.y * r3.w + r5.w;
        r5.w = r8.z * 3 + r5.w;
        r3.w = r6.x * r3.w + r5.w;
        r4.w = r4.w + r3.w;
        r4.w = r4.w + r8.x;
        r4.w = r4.w + r9.z;
        r4.w = r4.w + r7.w;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r5.z;
        r4.w = r4.w + r8.w;
        r4.w = r4.w + r5.z;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r7.y;
        r4.w = r4.w + r9.w;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r9.z;
        r4.w = r4.w + r9.y;
        r4.w = r4.w + r9.w;
        r4.w = r4.w + r7.y;
        r4.w = r4.w + r7.x;
        r4.w = r4.w + r7.y;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r7.w;
        r4.w = r4.w + r7.z;
        r4.w = r4.w + r7.y;
        r4.w = r4.w + r7.x;
        r10.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-3,-3)).xyzw;
        r5.w = 1 + -r5.y;
        r11.xyzw = -r7.xzyw * r5.xxxx + r7.xzyw;
        r12.xyz = r11.xxz * r10.wxx;
        r13.xyzw = r7.xyzw + -r7.yzwz;
        r13.xyzw = r5.xxxx * r13.xyzw + r7.yzwz;
        r6.xw = r10.zy * r13.xx + r12.xy;
        r6.w = r6.w * r5.y;
        r6.x = r5.w * r6.x + r6.w;
        r14.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-1,-3)).xyzw;
        r15.xyzw = r14.wzxy * r13.yzyz;
        r8.yz = r15.xz + r15.yw;
        r6.x = r5.w * r8.y + r6.x;
        r6.x = r5.y * r8.z + r6.x;
        r15.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(1,-3)).xyzw;
        r8.yz = r7.zy + -r7.yx;
        r8.yz = r5.xx * r8.yz + r7.yx;
        r10.xz = r15.zy * r8.yy;
        r10.xz = r15.wx * r13.ww + r10.xz;
        r6.x = r5.w * r10.x + r6.x;
        r6.x = r5.y * r10.z + r6.x;
        r16.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(3,-3)).xyzw;
        r10.xzw = r16.zyy * r5.xxx;
        r10.xzw = r10.xzw * r7.xxy;
        r10.xz = r16.wx * r8.zz + r10.xz;
        r6.x = r5.w * r10.x + r6.x;
        r6.x = r5.y * r10.z + r6.x;
        r17.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-3,-1)).xyzw;
        r18.xyzw = -r9.yyzw + r7.zzwy;
        r18.xyzw = r5.xxxx * r18.xyzw + r9.xyzw;
        r19.xyzw = r18.yywz * r17.zyzy;
        r17.xyzw = r17.wxwx * r11.yyzw + r19.xyzw;
        r6.x = r5.w * r17.x + r6.x;
        r6.x = r5.y * r17.y + r6.x;
        r6.w = r10.y * r18.w + r12.z;
        r6.x = r5.w * r6.w + r6.x;
        r6.x = r5.y * r17.z + r6.x;
        r12.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-1,-1)).xyzw;
        r6.w = r9.y + -r5.z;
        r6.w = r5.x * r6.w + r5.z;
        r10.xy = -r8.xw + r5.zz;
        r10.xy = r5.xx * r10.xy + r8.xw;
        r10.xz = r12.zy * r10.xx;
        r10.xz = r12.wx * r6.ww + r10.xz;
        r6.x = r5.w * r10.x + r6.x;
        r6.x = r5.y * r10.z + r6.x;
        r19.xyzw = r9.wyzy + -r9.yzyw;
        r19.xyzw = r5.xxxx * r19.xyzw + r9.xzyw;
        r10.xz = r19.xy * r14.xy;
        r10.x = r10.x + r10.z;
        r6.x = r5.w * r10.x + r6.x;
        r10.xz = r19.xy * r12.wz;
        r10.x = r10.x + r10.z;
        r6.x = r5.y * r10.x + r6.x;
        r14.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(1,-1)).xyzw;
        r10.xz = r8.xw + -r5.zz;
        r10.xz = r5.xx * r10.xz + r5.zz;
        r5.z = r5.z + -r9.y;
        r5.z = r5.x * r5.z + r9.y;
        r12.zw = r14.zy * r5.zz;
        r12.zw = r14.wx * r10.xx + r12.zw;
        r6.x = r5.w * r12.z + r6.x;
        r6.x = r5.y * r12.w + r6.x;
        r12.zw = r19.zw * r15.xy;
        r8.w = r12.z + r12.w;
        r6.x = r5.w * r8.w + r6.x;
        r12.zw = r14.wz * r19.zw;
        r8.w = r12.z + r12.w;
        r6.x = r5.y * r8.w + r6.x;
        r15.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(3,-1)).xyzw;
        r20.xyzw = r9.xyzw + -r7.zzwy;
        r20.xyzw = r5.xxxx * r20.xyzw + r7.zzwy;
        r21.xyzw = r15.zyzy * r5.xxxx;
        r21.xyzw = r21.xyzw * r7.zzyw;
        r15.xyzw = r15.wxwx * r20.yywz + r21.xyzw;
        r6.x = r5.w * r15.x + r6.x;
        r6.x = r5.y * r15.y + r6.x;
        r8.w = r16.x * r20.w + r10.w;
        r6.x = r5.w * r8.w + r6.x;
        r6.x = r5.y * r15.z + r6.x;
        r16.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-3,1)).xyzw;
        r21.xyzw = r16.zyzy * r18.xyzw;
        r16.xyzw = r16.wxwx * r11.yywz + r21.xyzw;
        r6.x = r5.w * r16.x + r6.x;
        r6.x = r5.y * r16.y + r6.x;
        r6.x = r5.w * r17.w + r6.x;
        r6.x = r5.y * r16.z + r6.x;
        r17.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-1,1)).xyzw;
        r9.xy = r17.zy * r10.yy;
        r9.xy = r17.wx * r6.ww + r9.xy;
        r6.x = r5.w * r9.x + r6.x;
        r6.x = r5.y * r9.y + r6.x;
        r6.w = r9.z + -r8.x;
        r6.w = r5.x * r6.w + r8.x;
        r8.w = r8.x + -r3.w;
        r8.w = r5.x * r8.w + r3.w;
        r9.x = r12.y * r8.w;
        r9.x = r12.x * r6.w + r9.x;
        r6.x = r5.w * r9.x + r6.x;
        r8.w = r17.z * r8.w;
        r6.w = r17.w * r6.w + r8.w;
        r6.x = r5.y * r6.w + r6.x;
        r12.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(1,1)).xyzw;
        r9.xy = r12.zy * r5.zz;
        r9.xy = r12.wx * r10.zz + r9.xy;
        r5.z = r5.w * r9.x + r6.x;
        r5.z = r5.y * r9.y + r5.z;
        r3.w = r3.w + -r8.x;
        r3.w = r5.x * r3.w + r8.x;
        r6.x = r8.x + -r9.z;
        r6.x = r5.x * r6.x + r9.z;
        r6.w = r14.y * r6.x;
        r6.w = r14.x * r3.w + r6.w;
        r5.z = r5.w * r6.w + r5.z;
        r6.x = r12.z * r6.x;
        r3.w = r12.w * r3.w + r6.x;
        r3.w = r5.y * r3.w + r5.z;
        r9.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(3,1)).xyzw;
        r10.xyzw = r9.zyzy * r5.xxxx;
        r10.xyzw = r10.xyzw * r7.zzwy;
        r9.xyzw = r9.wxwx * r20.xyzw + r10.xyzw;
        r3.w = r5.w * r9.x + r3.w;
        r3.w = r5.y * r9.y + r3.w;
        r3.w = r5.w * r15.w + r3.w;
        r3.w = r5.y * r9.z + r3.w;
        r10.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-3,3)).xyzw;
        r9.xyz = r10.wxw * r11.xxz;
        r6.xw = r10.zy * r13.xx + r9.xy;
        r3.w = r5.w * r6.x + r3.w;
        r3.w = r5.y * r6.w + r3.w;
        r3.w = r5.w * r16.w + r3.w;
        r5.z = r10.z * r18.w + r9.z;
        r3.w = r5.y * r5.z + r3.w;
        r10.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(-1,3)).xyzw;
        r11.xyzw = r10.wzxy * r13.yzyz;
        r6.xw = r11.xz + r11.yw;
        r3.w = r5.w * r6.x + r3.w;
        r3.w = r5.y * r6.w + r3.w;
        r6.xw = r17.xy * r19.xy;
        r5.z = r6.x + r6.w;
        r3.w = r5.w * r5.z + r3.w;
        r6.xw = r10.wz * r19.xy;
        r5.z = r6.x + r6.w;
        r3.w = r5.y * r5.z + r3.w;
        r10.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(1,3)).xyzw;
        r6.xw = r10.zy * r8.yy;
        r6.xw = r10.wx * r13.ww + r6.xw;
        r3.w = r5.w * r6.x + r3.w;
        r3.w = r5.y * r6.w + r3.w;
        r6.xw = r12.xy * r19.zw;
        r5.z = r6.x + r6.w;
        r3.w = r5.w * r5.z + r3.w;
        r6.xw = r10.wz * r19.zw;
        r5.z = r6.x + r6.w;
        r3.w = r5.y * r5.z + r3.w;
        r6.xyzw = g_xShadowTexture.GatherCmp(g_xShadowCmpSamplerLessEqual_s, r6.yz, r4.z, int2(3,3)).xyzw;
        r8.xyw = r6.zyz * r5.xxx;
        r7.xyz = r8.xyw * r7.xxy;
        r5.xz = r6.wx * r8.zz + r7.xy;
        r3.w = r5.w * r5.x + r3.w;
        r3.w = r5.y * r5.z + r3.w;
        r3.w = r5.w * r9.w + r3.w;
        r4.z = r6.w * r20.w + r7.z;
        r3.w = r5.y * r4.z + r3.w;
        r3.w = r3.w / r4.w;
      } else {
        r3.w = r2.z ? 0 : 1;
      }
    } else {
      r3.w = 1;
    }
    r2.z = 1 + -r3.w;
    o0.w = -g_fShadowStrength * r2.z + 1;
  } else {
    o0.w = 1;
  }
  r5.xyz = g_xInvView._m01_m11_m21 * r1.yyy;
  r5.xyz = g_xInvView._m00_m10_m20 * r1.xxx + r5.xyz;
  r1.xyw = g_xInvView._m02_m12_m22 * r1.www + r5.xyz;
  r1.xyw = g_xInvView._m03_m13_m23 + r1.xyw;
  r1.xyw = g_xProjectorPos.xyz + -r1.xyw;
  r2.z = dot(r1.xyw, r1.xyw);
  r2.z = sqrt(r2.z);
  r1.xyw = r1.xyw / r2.zzz;
  r2.z = -g_fMinRange + r2.z;
  r3.w = r2.z * g_fRcpRange + -0.5;
  r3.w = 0.5 + -abs(r3.w);
  r3.w = cmp(r3.w < 0);
  if (r3.w != 0) discard;
  r2.z = -r2.z * g_fRcpRange + 1;
  r2.z = saturate(g_fLightFalloffScale * r2.z);
  r2.z = log2(r2.z);
  r2.z = g_fLightFalloffPower * r2.z;
  r2.z = exp2(r2.z);
  r2.z = g_fDistanceFade * r2.z;
  if (g_bUseTexture != 0) {
    r4.xyz = g_xProjectedTexture.SampleLevel(g_xTrilinearClamp_s, r4.xy, 0).xyz;
  } else {
    r4.xyz = float3(1,1,1);
  }
  if (g_bUseDetailTexture != 0) {
    r5.xy = g_xDetailOffsetScale.zw / r2.ww;
    r2.xy = r2.xy * r5.xy + g_xDetailOffsetScale.xy;
    r2.xyw = g_xProjectedDetailTexture.SampleLevel(g_xTrilinearWrap_s, r2.xy, 0).xyz;
    r4.xyz = r4.xyz * r2.xyw;
  }
  r2.xyz = g_xLightColour.xyz * r2.zzz;
  r2.xyz = r2.xyz * r4.xyz;
  r2.w = dot(r2.xyz, float3(0.333000004,0.333000004,0.333000004));
  r3.w = dot(v1.xyz, v1.xyz);
  r3.w = rsqrt(r3.w);
  r4.xyz = v1.xyz * r3.www;
  r4.w = dot(r3.xyz, r1.xyw);
  r4.w = min(1, r4.w);
  r5.yw = float2(0.994140625,0.998046875);
  r5.z = r0.w;
  r0.w = g_xMaterialsTexture.Sample(g_xPointClamp_s, r5.yz).w;
  r0.w = r0.w + r0.w;
  r5.x = r4.w * 0.490234375 + 0.4921875;
  r5.x = g_xMaterialsTexture.Sample(g_xTrilinearClamp_s, r5.xz).x;
  r5.x = r5.x + r5.x;
  r6.xyz = r5.xxx * r2.xyz;
  r7.xyz = r0.xyz * r2.www + -r2.xyz;
  r2.xyz = r0.www * r7.xyz + r2.xyz;
  r5.xy = g_xMaterialsTexture.Sample(g_xTrilinearClamp_s, r5.wz).xw;
  r0.w = r5.y + r5.y;
  r2.w = 256 * r5.x;
  r2.w = r2.w * r2.w;
  r1.xyw = v1.xyz * r3.www + r1.xyw;
  r3.w = dot(r1.xyw, r1.xyw);
  r3.w = rsqrt(r3.w);
  r1.xyw = r3.www * r1.xyw;
  r1.x = dot(r3.xyz, r1.xyw);
  r1.x = max(9.99999997e-007, r1.x);
  r1.x = log2(r1.x);
  r1.x = r2.w * r1.x;
  r1.x = exp2(r1.x);
  r1.x = r2.w * r1.x;
  r1.x = 0.03125 * r1.x;
  r1.y = max(0, r4.w);
  r1.w = saturate(dot(r3.xyz, r4.xyz));
  r2.w = 0.5 + r4.w;
  r2.w = max(0, r2.w);
  r1.w = 1 + -r1.w;
  r3.x = r1.w * r1.w;
  r3.x = r3.x * r3.x;
  r1.w = r3.x * r1.w;
  r0.w = r1.w * r0.w;
  r0.w = r0.w * r2.w;
  r0.w = 2.5 * r0.w;
  r0.w = r1.x * r1.y + r0.w;
  r0.w = r0.w * r1.z;
  r1.xyz = r2.xyz * r0.www;
  r0.xyz = r6.xyz * r0.xyz + r1.xyz;
  o0.xyz = min(float3(31.875,31.875,31.875), r0.xyz);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// Buffer Definitions: 
//
// cbuffer FrameConstants
// {
//
//   float4x4 g_xView;                  // Offset:    0 Size:    64 [unused]
//   float4x4 g_xProj;                  // Offset:   64 Size:    64 [unused]
//   float4x4 g_xViewProj;              // Offset:  128 Size:    64 [unused]
//   float4x4 g_xInvView;               // Offset:  192 Size:    64
//   float4x4 g_xInvProj;               // Offset:  256 Size:    64 [unused]
//   float4x4 g_xInvViewProj;           // Offset:  320 Size:    64 [unused]
//   float3 g_xCamPos;                  // Offset:  384 Size:    12 [unused]
//   float2 g_xRcpScreenDims;           // Offset:  400 Size:     8 [unused]
//   float2 g_xDepthProjViewUnpack;     // Offset:  408 Size:     8 [unused]
//   float4 g_axViewFrustumPlanes[6];   // Offset:  416 Size:    96 [unused]
//
// }
//
// cbuffer ShadowReadConstants
// {
//
//   float g_f2DFilterSize;             // Offset:    0 Size:     4
//   float g_fCubeFilterSize;           // Offset:    4 Size:     4 [unused]
//   float g_fCubeClampWidth;           // Offset:    8 Size:     4 [unused]
//   float g_fSunWidth;                 // Offset:   12 Size:     4
//
// }
//
// cbuffer ProjectorParams
// {
//
//   float2 g_xCameraTanHalfFOV;        // Offset:    0 Size:     8
//   float2 g_xTwoOverScreenDims;       // Offset:    8 Size:     8
//   float4x4 g_xProjectorMatrix;       // Offset:   16 Size:    64
//   float4 g_xProjectionDirection;     // Offset:   80 Size:    16 [unused]
//   float4 g_xDetailOffsetScale;       // Offset:   96 Size:    16
//   float3 g_xProjectorPos;            // Offset:  112 Size:    12
//   bool g_bUseTexture;                // Offset:  124 Size:     4
//   float3 g_xLightColour;             // Offset:  128 Size:    12
//   float g_fDistanceFade;             // Offset:  140 Size:     4
//   float g_fLightFalloffScale;        // Offset:  144 Size:     4
//   float g_fLightFalloffPower;        // Offset:  148 Size:     4
//   float g_fAngularFalloffOfs;        // Offset:  152 Size:     4 [unused]
//   float g_fAngularFalloffScale;      // Offset:  156 Size:     4 [unused]
//   float g_fMinRange;                 // Offset:  160 Size:     4
//   float g_fRcpRange;                 // Offset:  164 Size:     4
//   float g_fShadowStrength;           // Offset:  168 Size:     4
//   bool g_bUseDetailTexture;          // Offset:  172 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_xPointClamp                     sampler      NA          NA    1        1
// g_xTrilinearWrap                  sampler      NA          NA    2        1
// g_xTrilinearClamp                 sampler      NA          NA    3        1
// g_xShadowCmpSamplerLessEqual    sampler_c      NA          NA    9        1
// g_xMaterialsTexture               texture  float4          2d    0        1
// g_xProjectedTexture               texture  float4          2d    1        1
// g_xProjectedDetailTexture         texture  float4          2d    2        1
// g_xShadowTexture                  texture  float4          2d    3        1
// g_xNormalBuffer                   texture  float4          2d   24        1
// g_xAlbedoBuffer                   texture  float4          2d   25        1
// FrameConstants                    cbuffer      NA          NA    0        1
// ProjectorParams                   cbuffer      NA          NA    4        1
// ShadowReadConstants               cbuffer      NA          NA    5        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xy  
// CamDir                   0   xyz         1     NONE   float   xyz 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[16], immediateIndexed
dcl_constantbuffer cb5[1], immediateIndexed
dcl_constantbuffer cb4[11], immediateIndexed
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_sampler s9, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t24
dcl_resource_texture2d (float,float,float,float) t25
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 22
ftoi r0.xy, v0.xyxx
mov r0.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.xyww, t24.xyzw
ld_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyzw, t25.xyzw
dp2 r2.x, r1.xyxx, r1.xyxx
mad r3.z, r2.x, l(2.000000), l(-1.000000)
rsq r2.x, r2.x
mul r1.xy, r1.xyxx, r2.xxxx
mad r2.x, -r3.z, r3.z, l(1.000000)
sqrt r2.x, r2.x
mul r3.xy, r1.xyxx, r2.xxxx
mul r1.xy, r1.wwww, cb4[0].xyxx
mad r2.xy, v0.xyxx, cb4[0].zwzz, l(-1.000000, -1.000000, 0.000000, 0.000000)
mul r1.xy, r1.xyxx, r2.xyxx
mul r2.xyzw, r1.yyyy, cb4[2].xyzw
mad r2.xyzw, cb4[1].xyzw, r1.xxxx, r2.xyzw
mad r2.xyzw, cb4[3].xyzw, r1.wwww, r2.xyzw
add r2.xyzw, r2.xyzw, cb4[4].xyzw
lt r3.w, r2.z, l(0.000000)
discard_nz r3.w
div r4.xyz, r2.xyzx, r2.wwww
add r5.xy, r4.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
add r5.xy, -|r5.xyxx|, l(0.500000, 0.500000, 0.000000, 0.000000)
lt r5.xy, r5.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
or r2.z, r5.y, r5.x
discard_nz r2.z
lt r2.z, l(0.000000), cb4[10].z
if_nz r2.z
  div r2.z, l(1.000000, 1.000000, 1.000000, 1.000000), cb5[0].x
  mad r5.xy, r2.zzzz, r4.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
  round_ni r5.zw, r5.xxxy
  add r5.xy, -r5.zwzz, r5.xyxx
  mad r6.yz, -r5.xxyx, cb5[0].xxxx, r4.xxyx
  mov r6.w, r4.z
  mul r7.y, cb5[0].x, l(-3.000000)
  mov r7.w, l(0)
  mov r5.zw, l(0,0,0,0)
  mov r2.z, l(-3)
  loop 
    ilt r3.w, l(3), r2.z
    breakc_nz r3.w
    itof r3.w, r2.z
    mul r7.z, r3.w, cb5[0].x
    add r8.yzw, r6.yyzw, r7.yyzw
    gather4_indexable(texture2d)(float,float,float,float) r9.xyzw, r8.yzyy, t3.xyzw, s1.x
    ge r10.xyzw, r9.xyzw, r8.wwww
    movc r10.xyzw, r10.xyzw, l(0,0,0,0), l(1.000000,1.000000,1.000000,1.000000)
    dp4 r3.w, r10.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
    dp4 r4.w, r9.xyzw, r10.xyzw
    mad r8.x, cb5[0].x, l(2.000000), r8.y
    gather4_indexable(texture2d)(float,float,float,float) r9.xyzw, r8.xzxx, t3.xyzw, s1.x
    ge r10.xyzw, r9.xyzw, r8.wwww
    movc r10.xyzw, r10.xyzw, l(0,0,0,0), l(1.000000,1.000000,1.000000,1.000000)
    dp4 r6.x, r10.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
    add r3.w, r3.w, r6.x
    dp4 r6.x, r9.xyzw, r10.xyzw
    add r4.w, r4.w, r6.x
    mad r8.y, cb5[0].x, l(2.000000), r8.x
    gather4_indexable(texture2d)(float,float,float,float) r9.xyzw, r8.yzyy, t3.xyzw, s1.x
    ge r10.xyzw, r9.xyzw, r8.wwww
    movc r10.xyzw, r10.xyzw, l(0,0,0,0), l(1.000000,1.000000,1.000000,1.000000)
    dp4 r6.x, r10.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
    add r3.w, r3.w, r6.x
    dp4 r6.x, r9.xyzw, r10.xyzw
    add r4.w, r4.w, r6.x
    mad r8.x, cb5[0].x, l(2.000000), r8.y
    gather4_indexable(texture2d)(float,float,float,float) r9.xyzw, r8.xzxx, t3.xyzw, s1.x
    ge r8.xyzw, r9.xyzw, r8.wwww
    movc r8.xyzw, r8.xyzw, l(0,0,0,0), l(1.000000,1.000000,1.000000,1.000000)
    dp4 r6.x, r8.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
    add r3.w, r3.w, r6.x
    dp4 r6.x, r9.xyzw, r8.xyzw
    add r4.w, r4.w, r6.x
    add r5.w, r3.w, r5.w
    add r5.z, r4.w, r5.z
    iadd r2.z, r2.z, l(2)
  endloop 
  lt r2.z, l(0.000000), r5.w
  if_nz r2.z
    ge r2.z, r5.w, l(64.000000)
    if_z r2.z
      div r3.w, r5.z, r5.w
      add r4.w, -r3.w, r4.z
      mul r4.w, r4.w, cb5[0].w
      div_sat r3.w, r4.w, r3.w
      mul r4.w, r3.w, r3.w
      mul r5.z, r4.w, r4.w
      mul r5.w, r4.w, r5.z
      mul r6.x, r5.z, l(3.000000)
      mad r3.w, -r3.w, r3.w, l(1.000000)
      mul r6.w, r3.w, r6.x
      mad r7.xyzw, r6.wwww, l(0.010000, 0.030000, 0.060000, 0.070000), r5.wwww
      add r8.x, r7.y, r7.x
      add r8.x, r7.z, r8.x
      add r8.x, r7.w, r8.x
      add r8.x, r7.z, r8.x
      add r8.x, r7.y, r8.x
      add r8.x, r7.x, r8.x
      add r8.x, r7.y, r8.x
      mul r8.y, r3.w, r3.w
      mul r8.z, r4.w, r8.y
      mul r9.xyz, r8.zzzz, l(0.187500, 0.562500, 0.750000, 0.000000)
      mad r9.xyzw, r5.zzzz, r4.wwww, r9.yyzx
      mad r9.xyzw, r6.wwww, l(0.280000, 0.280000, 0.360000, 0.130000), r9.xyzw
      add r4.w, r8.x, r9.w
      add r4.w, r9.y, r4.w
      add r4.w, r9.z, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r9.w, r4.w
      add r4.w, r7.y, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r9.y, r4.w
      mad r10.xyz, r8.zzzz, l(1.687500, 2.250000, 2.262000, 0.000000), r5.wwww
      mad r5.z, r6.w, l(0.620000), r10.x
      add r4.w, r4.w, r5.z
      mad r8.xw, r6.wwww, l(0.790000, 0.000000, 0.000000, 0.790000), r10.yyyz
      add r4.w, r4.w, r8.x
      add r4.w, r5.z, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r7.w, r4.w
      add r4.w, r9.z, r4.w
      add r4.w, r8.x, r4.w
      mad r5.w, r8.y, r3.w, r5.w
      mad r5.w, r8.z, l(3.000000), r5.w
      mad r3.w, r6.x, r3.w, r5.w
      add r4.w, r3.w, r4.w
      add r4.w, r8.x, r4.w
      add r4.w, r9.z, r4.w
      add r4.w, r7.w, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r5.z, r4.w
      add r4.w, r8.w, r4.w
      add r4.w, r5.z, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r7.y, r4.w
      add r4.w, r9.w, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r9.z, r4.w
      add r4.w, r9.y, r4.w
      add r4.w, r9.w, r4.w
      add r4.w, r7.y, r4.w
      add r4.w, r7.x, r4.w
      add r4.w, r7.y, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r7.w, r4.w
      add r4.w, r7.z, r4.w
      add r4.w, r7.y, r4.w
      add r4.w, r7.x, r4.w
      gather4_c_aoffimmi_indexable(-3,-3,0)(texture2d)(float,float,float,float) r10.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r5.w, -r5.y, l(1.000000)
      mad r11.xyzw, -r7.xzyw, r5.xxxx, r7.xzyw
      mul r12.xyz, r10.wxxw, r11.xxzx
      add r13.xyzw, -r7.yzwz, r7.xyzw
      mad r13.xyzw, r5.xxxx, r13.xyzw, r7.yzwz
      mad r6.xw, r10.zzzy, r13.xxxx, r12.xxxy
      mul r6.w, r5.y, r6.w
      mad r6.x, r5.w, r6.x, r6.w
      gather4_c_aoffimmi_indexable(-1,-3,0)(texture2d)(float,float,float,float) r14.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r15.xyzw, r13.yzyz, r14.wzxy
      add r8.yz, r15.yywy, r15.xxzx
      mad r6.x, r5.w, r8.y, r6.x
      mad r6.x, r5.y, r8.z, r6.x
      gather4_c_aoffimmi_indexable(1,-3,0)(texture2d)(float,float,float,float) r15.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r8.yz, -r7.yyxy, r7.zzyz
      mad r8.yz, r5.xxxx, r8.yyzy, r7.yyxy
      mul r10.xz, r8.yyyy, r15.zzyz
      mad r10.xz, r15.wwxw, r13.wwww, r10.xxzx
      mad r6.x, r5.w, r10.x, r6.x
      mad r6.x, r5.y, r10.z, r6.x
      gather4_c_aoffimmi_indexable(3,-3,0)(texture2d)(float,float,float,float) r16.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r10.xzw, r5.xxxx, r16.zzyy
      mul r10.xzw, r7.xxxy, r10.xxzw
      mad r10.xz, r16.wwxw, r8.zzzz, r10.xxzx
      mad r6.x, r5.w, r10.x, r6.x
      mad r6.x, r5.y, r10.z, r6.x
      gather4_c_aoffimmi_indexable(-3,-1,0)(texture2d)(float,float,float,float) r17.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r18.xyzw, r7.zzwy, -r9.yyzw
      mad r18.xyzw, r5.xxxx, r18.xyzw, r9.xyzw
      mul r19.xyzw, r17.zyzy, r18.yywz
      mad r17.xyzw, r17.wxwx, r11.yyzw, r19.xyzw
      mad r6.x, r5.w, r17.x, r6.x
      mad r6.x, r5.y, r17.y, r6.x
      mad r6.w, r10.y, r18.w, r12.z
      mad r6.x, r5.w, r6.w, r6.x
      mad r6.x, r5.y, r17.z, r6.x
      gather4_c_aoffimmi_indexable(-1,-1,0)(texture2d)(float,float,float,float) r12.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r6.w, -r5.z, r9.y
      mad r6.w, r5.x, r6.w, r5.z
      add r10.xy, r5.zzzz, -r8.xwxx
      mad r10.xy, r5.xxxx, r10.xyxx, r8.xwxx
      mul r10.xz, r10.xxxx, r12.zzyz
      mad r10.xz, r12.wwxw, r6.wwww, r10.xxzx
      mad r6.x, r5.w, r10.x, r6.x
      mad r6.x, r5.y, r10.z, r6.x
      add r19.xyzw, -r9.yzyw, r9.wyzy
      mad r19.xyzw, r5.xxxx, r19.xyzw, r9.xzyw
      mul r10.xz, r14.xxyx, r19.xxyx
      add r10.x, r10.z, r10.x
      mad r6.x, r5.w, r10.x, r6.x
      mul r10.xz, r12.wwzw, r19.xxyx
      add r10.x, r10.z, r10.x
      mad r6.x, r5.y, r10.x, r6.x
      gather4_c_aoffimmi_indexable(1,-1,0)(texture2d)(float,float,float,float) r14.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r10.xz, -r5.zzzz, r8.xxwx
      mad r10.xz, r5.xxxx, r10.xxzx, r5.zzzz
      add r5.z, -r9.y, r5.z
      mad r5.z, r5.x, r5.z, r9.y
      mul r12.zw, r5.zzzz, r14.zzzy
      mad r12.zw, r14.wwwx, r10.xxxx, r12.zzzw
      mad r6.x, r5.w, r12.z, r6.x
      mad r6.x, r5.y, r12.w, r6.x
      mul r12.zw, r15.xxxy, r19.zzzw
      add r8.w, r12.w, r12.z
      mad r6.x, r5.w, r8.w, r6.x
      mul r12.zw, r19.zzzw, r14.wwwz
      add r8.w, r12.w, r12.z
      mad r6.x, r5.y, r8.w, r6.x
      gather4_c_aoffimmi_indexable(3,-1,0)(texture2d)(float,float,float,float) r15.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      add r20.xyzw, -r7.zzwy, r9.xyzw
      mad r20.xyzw, r5.xxxx, r20.xyzw, r7.zzwy
      mul r21.xyzw, r5.xxxx, r15.zyzy
      mul r21.xyzw, r7.zzyw, r21.xyzw
      mad r15.xyzw, r15.wxwx, r20.yywz, r21.xyzw
      mad r6.x, r5.w, r15.x, r6.x
      mad r6.x, r5.y, r15.y, r6.x
      mad r8.w, r16.x, r20.w, r10.w
      mad r6.x, r5.w, r8.w, r6.x
      mad r6.x, r5.y, r15.z, r6.x
      gather4_c_aoffimmi_indexable(-3,1,0)(texture2d)(float,float,float,float) r16.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r21.xyzw, r18.xyzw, r16.zyzy
      mad r16.xyzw, r16.wxwx, r11.yywz, r21.xyzw
      mad r6.x, r5.w, r16.x, r6.x
      mad r6.x, r5.y, r16.y, r6.x
      mad r6.x, r5.w, r17.w, r6.x
      mad r6.x, r5.y, r16.z, r6.x
      gather4_c_aoffimmi_indexable(-1,1,0)(texture2d)(float,float,float,float) r17.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r9.xy, r10.yyyy, r17.zyzz
      mad r9.xy, r17.wxww, r6.wwww, r9.xyxx
      mad r6.x, r5.w, r9.x, r6.x
      mad r6.x, r5.y, r9.y, r6.x
      add r6.w, -r8.x, r9.z
      mad r6.w, r5.x, r6.w, r8.x
      add r8.w, -r3.w, r8.x
      mad r8.w, r5.x, r8.w, r3.w
      mul r9.x, r8.w, r12.y
      mad r9.x, r12.x, r6.w, r9.x
      mad r6.x, r5.w, r9.x, r6.x
      mul r8.w, r8.w, r17.z
      mad r6.w, r17.w, r6.w, r8.w
      mad r6.x, r5.y, r6.w, r6.x
      gather4_c_aoffimmi_indexable(1,1,0)(texture2d)(float,float,float,float) r12.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r9.xy, r5.zzzz, r12.zyzz
      mad r9.xy, r12.wxww, r10.zzzz, r9.xyxx
      mad r5.z, r5.w, r9.x, r6.x
      mad r5.z, r5.y, r9.y, r5.z
      add r3.w, -r8.x, r3.w
      mad r3.w, r5.x, r3.w, r8.x
      add r6.x, -r9.z, r8.x
      mad r6.x, r5.x, r6.x, r9.z
      mul r6.w, r6.x, r14.y
      mad r6.w, r14.x, r3.w, r6.w
      mad r5.z, r5.w, r6.w, r5.z
      mul r6.x, r6.x, r12.z
      mad r3.w, r12.w, r3.w, r6.x
      mad r3.w, r5.y, r3.w, r5.z
      gather4_c_aoffimmi_indexable(3,1,0)(texture2d)(float,float,float,float) r9.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r10.xyzw, r5.xxxx, r9.zyzy
      mul r10.xyzw, r7.zzwy, r10.xyzw
      mad r9.xyzw, r9.wxwx, r20.xyzw, r10.xyzw
      mad r3.w, r5.w, r9.x, r3.w
      mad r3.w, r5.y, r9.y, r3.w
      mad r3.w, r5.w, r15.w, r3.w
      mad r3.w, r5.y, r9.z, r3.w
      gather4_c_aoffimmi_indexable(-3,3,0)(texture2d)(float,float,float,float) r10.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r9.xyz, r11.xxzx, r10.wxww
      mad r6.xw, r10.zzzy, r13.xxxx, r9.xxxy
      mad r3.w, r5.w, r6.x, r3.w
      mad r3.w, r5.y, r6.w, r3.w
      mad r3.w, r5.w, r16.w, r3.w
      mad r5.z, r10.z, r18.w, r9.z
      mad r3.w, r5.y, r5.z, r3.w
      gather4_c_aoffimmi_indexable(-1,3,0)(texture2d)(float,float,float,float) r10.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r11.xyzw, r13.yzyz, r10.wzxy
      add r6.xw, r11.yyyw, r11.xxxz
      mad r3.w, r5.w, r6.x, r3.w
      mad r3.w, r5.y, r6.w, r3.w
      mul r6.xw, r19.xxxy, r17.xxxy
      add r5.z, r6.w, r6.x
      mad r3.w, r5.w, r5.z, r3.w
      mul r6.xw, r19.xxxy, r10.wwwz
      add r5.z, r6.w, r6.x
      mad r3.w, r5.y, r5.z, r3.w
      gather4_c_aoffimmi_indexable(1,3,0)(texture2d)(float,float,float,float) r10.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r6.xw, r8.yyyy, r10.zzzy
      mad r6.xw, r10.wwwx, r13.wwww, r6.xxxw
      mad r3.w, r5.w, r6.x, r3.w
      mad r3.w, r5.y, r6.w, r3.w
      mul r6.xw, r19.zzzw, r12.xxxy
      add r5.z, r6.w, r6.x
      mad r3.w, r5.w, r5.z, r3.w
      mul r6.xw, r19.zzzw, r10.wwwz
      add r5.z, r6.w, r6.x
      mad r3.w, r5.y, r5.z, r3.w
      gather4_c_aoffimmi_indexable(3,3,0)(texture2d)(float,float,float,float) r6.xyzw, r6.yzyy, t3.xyzw, s9.x, r4.z
      mul r8.xyw, r5.xxxx, r6.zyzz
      mul r7.xyz, r7.xxyx, r8.xywx
      mad r5.xz, r6.wwxw, r8.zzzz, r7.xxyx
      mad r3.w, r5.w, r5.x, r3.w
      mad r3.w, r5.y, r5.z, r3.w
      mad r3.w, r5.w, r9.w, r3.w
      mad r4.z, r6.w, r20.w, r7.z
      mad r3.w, r5.y, r4.z, r3.w
      div r3.w, r3.w, r4.w
    else 
      movc r3.w, r2.z, l(0), l(1.000000)
    endif 
  else 
    mov r3.w, l(1.000000)
  endif 
  add r2.z, -r3.w, l(1.000000)
  mad o0.w, -cb4[10].z, r2.z, l(1.000000)
else 
  mov o0.w, l(1.000000)
endif 
mul r5.xyz, r1.yyyy, cb0[13].xyzx
mad r5.xyz, cb0[12].xyzx, r1.xxxx, r5.xyzx
mad r1.xyw, cb0[14].xyxz, r1.wwww, r5.xyxz
add r1.xyw, r1.xyxw, cb0[15].xyxz
add r1.xyw, -r1.xyxw, cb4[7].xyxz
dp3 r2.z, r1.xywx, r1.xywx
sqrt r2.z, r2.z
div r1.xyw, r1.xyxw, r2.zzzz
add r2.z, r2.z, -cb4[10].x
mad r3.w, r2.z, cb4[10].y, l(-0.500000)
add r3.w, -|r3.w|, l(0.500000)
lt r3.w, r3.w, l(0.000000)
discard_nz r3.w
mad r2.z, -r2.z, cb4[10].y, l(1.000000)
mul_sat r2.z, r2.z, cb4[9].x
log r2.z, r2.z
mul r2.z, r2.z, cb4[9].y
exp r2.z, r2.z
mul r2.z, r2.z, cb4[8].w
if_nz cb4[7].w
  sample_l_indexable(texture2d)(float,float,float,float) r4.xyz, r4.xyxx, t1.xyzw, s3, l(0.000000)
else 
  mov r4.xyz, l(1.000000,1.000000,1.000000,0)
endif 
if_nz cb4[10].w
  div r5.xy, cb4[6].zwzz, r2.wwww
  mad r2.xy, r2.xyxx, r5.xyxx, cb4[6].xyxx
  sample_l_indexable(texture2d)(float,float,float,float) r2.xyw, r2.xyxx, t2.xywz, s2, l(0.000000)
  mul r4.xyz, r2.xywx, r4.xyzx
endif 
mul r2.xyz, r2.zzzz, cb4[8].xyzx
mul r2.xyz, r4.xyzx, r2.xyzx
dp3 r2.w, r2.xyzx, l(0.333000, 0.333000, 0.333000, 0.000000)
dp3 r3.w, v1.xyzx, v1.xyzx
rsq r3.w, r3.w
mul r4.xyz, r3.wwww, v1.xyzx
dp3 r4.w, r3.xyzx, r1.xywx
min r4.w, r4.w, l(1.000000)
mov r5.yw, l(0,0.994141,0,0.998047)
mov r5.z, r0.w
sample_indexable(texture2d)(float,float,float,float) r0.w, r5.yzyy, t0.xyzw, s1
add r0.w, r0.w, r0.w
mad r5.x, r4.w, l(0.490234), l(0.492188)
sample_indexable(texture2d)(float,float,float,float) r5.x, r5.xzxx, t0.xyzw, s3
add r5.x, r5.x, r5.x
mul r6.xyz, r2.xyzx, r5.xxxx
mad r7.xyz, r0.xyzx, r2.wwww, -r2.xyzx
mad r2.xyz, r0.wwww, r7.xyzx, r2.xyzx
sample_indexable(texture2d)(float,float,float,float) r5.xy, r5.wzww, t0.xwyz, s3
add r0.w, r5.y, r5.y
mul r2.w, r5.x, l(256.000000)
mul r2.w, r2.w, r2.w
mad r1.xyw, v1.xyxz, r3.wwww, r1.xyxw
dp3 r3.w, r1.xywx, r1.xywx
rsq r3.w, r3.w
mul r1.xyw, r1.xyxw, r3.wwww
dp3 r1.x, r3.xyzx, r1.xywx
max r1.x, r1.x, l(0.000001)
log r1.x, r1.x
mul r1.x, r1.x, r2.w
exp r1.x, r1.x
mul r1.x, r1.x, r2.w
mul r1.x, r1.x, l(0.031250)
max r1.y, r4.w, l(0.000000)
dp3_sat r1.w, r3.xyzx, r4.xyzx
add r2.w, r4.w, l(0.500000)
max r2.w, r2.w, l(0.000000)
add r1.w, -r1.w, l(1.000000)
mul r3.x, r1.w, r1.w
mul r3.x, r3.x, r3.x
mul r1.w, r1.w, r3.x
mul r0.w, r0.w, r1.w
mul r0.w, r2.w, r0.w
mul r0.w, r0.w, l(2.500000)
mad r0.w, r1.x, r1.y, r0.w
mul r0.w, r1.z, r0.w
mul r1.xyz, r0.wwww, r2.xyzx
mad r0.xyz, r6.xyzx, r0.xyzx, r1.xyzx
min o0.xyz, r0.xyzx, l(31.875000, 31.875000, 31.875000, 0.000000)
ret 
// Approximately 407 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
