// Some God Rays!
// ---- Created with 3Dmigoto v1.2.56 on Thu Mar 23 12:38:41 2017

cbuffer SceneBuffer : register(b0)
{
  float4x4 g_View : packoffset(c0);
  float4x4 g_Proj : packoffset(c4);
  float4x4 g_ViewProjection : packoffset(c8);
  float4x4 g_ViewInverseMatrix : packoffset(c12);
}

cbuffer HPixel_Buffer : register(b12)
{
  float4 g_TargetUvParam : packoffset(c0);
}

cbuffer CamParam_HPixel_Buffer : register(b13)
{
  float4 g_CameraParam : packoffset(c0);
  float4 g_CameraVec : packoffset(c1);
}

cbuffer ShadowView_Buffer : register(b10)
{
  float4 g_ShadowFarInv : packoffset(c0);
  float4 g_DepthOffset : packoffset(c1);
  float4 g_BokeOffset : packoffset(c2);
  float4x4 g_ShadowView : packoffset(c3);
  float4x4 g_ShadowViewProj[4] : packoffset(c7);
}

cbuffer CB : register(b8)
{
  float4 Near_Far_Stepnum[4] : packoffset(c0);
  float4 LightColor[4] : packoffset(c4);
  float4 LightDirView_Range15 : packoffset(c8);
  float4 ScatterParam_Range7 : packoffset(c9);
}

SamplerState g_Z_TexSampler_s : register(s6);
SamplerState g_Shadow_TexSampler_s : register(s11);
SamplerState g_Particle_TexSampler_s : register(s12);
Texture2D<float4> g_Z_Tex : register(t6);
Texture2D<float4> g_Shadow_Tex : register(t11);
Texture2D<float4> g_Particle_Tex : register(t12);


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


void main( 
  float4 v0 : SV_POSITION0,
  float2 v1 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 x0[16];
  r0.xy = float2(0.25,0.25) / g_TargetUvParam.zw;
  r0.xy = v1.xy + -r0.xy;
  r0.z = g_Z_Tex.Sample(g_Z_TexSampler_s, r0.xy).x;
  r0.z = r0.z * g_CameraParam.y + g_CameraParam.x;
  r0.w = (uint)LightColor[0].w;
  r1.x = r0.x * 2 + -1;
  r1.x = r1.x / g_Proj._m00;
  r1.w = r0.y * -2 + 1;
  r1.y = r1.w / g_Proj._m11;
  x0[0].x = 0;
  x0[1].x = 0.5;
  x0[2].x = 0.125;
  x0[3].x = 0.625;
  x0[4].x = 0.75;
  x0[5].x = 0.25;
  x0[6].x = 0.875;
  x0[7].x = 0.375;
  x0[8].x = 0.1875;
  x0[9].x = 0.6875;
  x0[10].x = 0.0625;
  x0[11].x = 0.5625;
  x0[12].x = 0.9375;
  x0[13].x = 0.4375;
  x0[14].x = 0.8125;
  x0[15].x = 0.3125;
  r0.xy = g_TargetUvParam.zw * r0.xy;
  r0.xy = (int2)r0.xy;
  bitmask.y = ((~(-1 << 2)) << 2) & 0xffffffff;  r0.y = (((uint)r0.y << 2) & bitmask.y) | ((uint)0 & ~bitmask.y);
  bitmask.x = ((~(-1 << 2)) << 0) & 0xffffffff;  r0.x = (((uint)r0.x << 0) & bitmask.x) | ((uint)r0.y & ~bitmask.x);
  r0.x = x0[r0.x+0].x;
  r1.z = -1;
  r0.y = dot(r1.xyz, r1.xyz);
  r0.y = rsqrt(r0.y);
  r2.xyz = r1.xyz * r0.yyy;
  r0.y = dot(r2.xyz, LightDirView_Range15.xyz);
  r0.y = ScatterParam_Range7.z * r0.y + ScatterParam_Range7.y;
  r0.y = log2(abs(r0.y));
  r0.y = 1.5 * r0.y;
  r0.y = exp2(r0.y);
  r0.y = ScatterParam_Range7.x / r0.y;
  r2.w = 1;
  r3.w = 1;
  r4.w = 1;
  r5.w = 1;
  r6.yw = float2(0,0);
  r7.y = 0;
  r8.xyz = float3(0,0,0);
  r1.z = 0;
  while (true) {
    r1.w = cmp((uint)r1.z >= (uint)r0.w);
    if (r1.w != 0) break;
    r2.xy = Near_Far_Stepnum[r1.z].xx * r1.xy;
    r2.z = -Near_Far_Stepnum[r1.z].x;




    r3.x = dot(r2.xyzw, g_ViewInverseMatrix._m00_m10_m20_m30);
    r3.y = dot(r2.xyzw, g_ViewInverseMatrix._m01_m11_m21_m31);
    r3.z = dot(r2.xyzw, g_ViewInverseMatrix._m02_m12_m22_m32);
    r1.w = (uint)r1.z << 2;
    r2.x = dot(r3.xyzw, g_ShadowViewProj[r1.w/4]._m00_m10_m20_m30);
    r2.y = dot(r3.xyzw, g_ShadowViewProj[r1.w/4]._m01_m11_m21_m31);
    r9.z = dot(r3.xyzw, g_ShadowViewProj[r1.w/4]._m02_m12_m22_m32);
    r9.xy = r2.xy * float2(0.5,-0.5) + float2(0.5,0.5);
    r4.xy = Near_Far_Stepnum[r1.z].yy * r1.xy;
    r4.z = -Near_Far_Stepnum[r1.z].y;
	
float4 stereo = StereoParams.Load(0);
r4.x += stereo.x * (r4.z + stereo.y)/g_Proj._m00;	
	
    r5.x = dot(r4.xyzw, g_ViewInverseMatrix._m00_m10_m20_m30);
    r5.y = dot(r4.xyzw, g_ViewInverseMatrix._m01_m11_m21_m31);
    r5.z = dot(r4.xyzw, g_ViewInverseMatrix._m02_m12_m22_m32);
    r2.x = dot(r5.xyzw, g_ShadowViewProj[r1.w/4]._m00_m10_m20_m30);
    r2.y = dot(r5.xyzw, g_ShadowViewProj[r1.w/4]._m01_m11_m21_m31);
    r10.z = dot(r5.xyzw, g_ShadowViewProj[r1.w/4]._m02_m12_m22_m32);
    r10.xy = r2.xy * float2(0.5,-0.5) + float2(0.5,0.5);
    r9.w = Near_Far_Stepnum[r1.z].x;
    r10.w = Near_Far_Stepnum[r1.z].y;
    r10.xyzw = r10.xyzw + -r9.xyzw;
    r10.xyzw = r10.xyzw / Near_Far_Stepnum[r1.z].zzzz;
    r1.w = min(Near_Far_Stepnum[r1.z].y, r0.z);
    r1.w = -0.100000001 + r1.w;
    r9.xyzw = r0.xxxx * r10.xyzw + r9.xyzw;
    r2.x = cmp(r9.w < r1.w);
    if (r2.x != 0) {
      r2.x = (int)r1.z & 1;
      r2.y = (uint)r1.z >> 1;
      r3.xy = (uint2)r2.xy;
      r2.xy = float2(0.5,0.5) * r3.xy;
      r3.xy = cmp(r9.xy < float2(0,0));
      r4.xy = cmp(float2(1,1) < r9.xy);
      r2.z = (int)r3.x | (int)r4.x;
      r2.z = (int)r3.y | (int)r2.z;
      r2.z = (int)r4.y | (int)r2.z;
      if (r2.z == 0) {
        r3.xy = r9.xy * float2(0.5,0.5) + r2.xy;
        r2.z = g_Shadow_Tex.SampleLevel(g_Shadow_TexSampler_s, r3.xy, 0).x;
        r2.z = cmp(r9.z < r2.z);
        if (r2.z != 0) {
          r6.x = LightDirView_Range15.w * r9.w;
          r2.z = g_Particle_Tex.SampleLevel(g_Particle_TexSampler_s, r6.xy, 0).x;
        } else {
          r2.z = 0;
        }
        r9.xyzw = r9.xyzw + r10.xyzw;
      } else {
        r2.z = 0;
      }
      r11.xyzw = r9.xyzw;
      r3.x = r2.z;
      while (true) {
        r3.y = cmp(r11.w >= r1.w);
        if (r3.y != 0) break;
        r3.yz = cmp(r11.xy < float2(0,0));
        r4.xy = cmp(float2(1,1) < r11.xy);
        r3.y = (int)r3.y | (int)r4.x;
        r3.y = (int)r3.z | (int)r3.y;
        r3.y = (int)r4.y | (int)r3.y;
        if (r3.y != 0) {
          break;
        }
        r3.yz = r11.xy * float2(0.5,0.5) + r2.xy;
        r3.y = g_Shadow_Tex.SampleLevel(g_Shadow_TexSampler_s, r3.yz, 0).x;
        r3.y = cmp(r11.z < r3.y);
        if (r3.y != 0) {
          r7.x = LightDirView_Range15.w * r11.w;
          r3.y = g_Particle_Tex.SampleLevel(g_Particle_TexSampler_s, r7.xy, 0).x;
          r3.x = r3.x + r3.y;
        }
        r11.xyzw = r11.xyzw + r10.xyzw;
      }
      r2.y = r11.w;
      r2.x = r3.x;
      while (true) {
        r2.z = cmp(r2.y >= r1.w);
        if (r2.z != 0) break;
        r6.z = LightDirView_Range15.w * r2.y;
        r2.z = g_Particle_Tex.SampleLevel(g_Particle_TexSampler_s, r6.zw, 0).x;
        r2.x = r2.x + r2.z;
        r2.y = r2.y + r10.w;
      }
    } else {
      r2.x = 0;
    }
    r4.xyz = LightColor[r1.z].xyz * r0.yyy;
    r8.xyz = r2.xxx * r4.xyz + r8.xyz;
    r1.z = (int)r1.z + 1;
  }
  o0.xyz = r8.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// Buffer Definitions: 
//
// cbuffer SceneBuffer
// {
//
//   float4x4 g_View;                   // Offset:    0 Size:    64 [unused]
//   float4x4 g_Proj;                   // Offset:   64 Size:    64
//   float4x4 g_ViewProjection;         // Offset:  128 Size:    64 [unused]
//   float4x4 g_ViewInverseMatrix;      // Offset:  192 Size:    64
//
// }
//
// cbuffer HPixel_Buffer
// {
//
//   float4 g_TargetUvParam;            // Offset:    0 Size:    16
//
// }
//
// cbuffer CamParam_HPixel_Buffer
// {
//
//   float4 g_CameraParam;              // Offset:    0 Size:    16
//   float4 g_CameraVec;                // Offset:   16 Size:    16 [unused]
//
// }
//
// cbuffer ShadowView_Buffer
// {
//
//   float4 g_ShadowFarInv;             // Offset:    0 Size:    16 [unused]
//   float4 g_DepthOffset;              // Offset:   16 Size:    16 [unused]
//   float4 g_BokeOffset;               // Offset:   32 Size:    16 [unused]
//   float4x4 g_ShadowView;             // Offset:   48 Size:    64 [unused]
//   float4x4 g_ShadowViewProj[4];      // Offset:  112 Size:   256
//
// }
//
// cbuffer CB
// {
//
//   float4 Near_Far_Stepnum[4];        // Offset:    0 Size:    64
//   float4 LightColor[4];              // Offset:   64 Size:    64
//   float4 LightDirView_Range15;       // Offset:  128 Size:    16
//   float4 ScatterParam_Range7;        // Offset:  144 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_Z_TexSampler                    sampler      NA          NA    6        1
// g_Shadow_TexSampler               sampler      NA          NA   11        1
// g_Particle_TexSampler             sampler      NA          NA   12        1
// g_Z_Tex                           texture  float4          2d    6        1
// g_Shadow_Tex                      texture  float4          2d   11        1
// g_Particle_Tex                    texture  float4          2d   12        1
// SceneBuffer                       cbuffer      NA          NA    0        1
// CB                                cbuffer      NA          NA    8        1
// ShadowView_Buffer                 cbuffer      NA          NA   10        1
// HPixel_Buffer                     cbuffer      NA          NA   12        1
// CamParam_HPixel_Buffer            cbuffer      NA          NA   13        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xy          1     NONE   float   xy  
//
//
// 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[15], immediateIndexed
dcl_constantbuffer cb12[1], immediateIndexed
dcl_constantbuffer cb13[1], immediateIndexed
dcl_constantbuffer cb10[22], dynamicIndexed
dcl_constantbuffer cb8[10], dynamicIndexed
dcl_sampler s6, mode_default
dcl_sampler s11, mode_default
dcl_sampler s12, mode_default
dcl_resource_texture2d (float,float,float,float) t6
dcl_resource_texture2d (float,float,float,float) t11
dcl_resource_texture2d (float,float,float,float) t12
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 12
dcl_indexableTemp x0[16], 4
div r0.xy, l(0.250000, 0.250000, 0.000000, 0.000000), cb12[0].zwzz
add r0.xy, -r0.xyxx, v1.xyxx
sample_indexable(texture2d)(float,float,float,float) r0.z, r0.xyxx, t6.yzxw, s6
mad r0.z, r0.z, cb13[0].y, cb13[0].x
ftou r0.w, cb8[4].w
mad r1.x, r0.x, l(2.000000), l(-1.000000)
div r1.x, r1.x, cb0[4].x
mad r1.w, r0.y, l(-2.000000), l(1.000000)
div r1.y, r1.w, cb0[5].y
mov x0[0].x, l(0)
mov x0[1].x, l(0.500000)
mov x0[2].x, l(0.125000)
mov x0[3].x, l(0.625000)
mov x0[4].x, l(0.750000)
mov x0[5].x, l(0.250000)
mov x0[6].x, l(0.875000)
mov x0[7].x, l(0.375000)
mov x0[8].x, l(0.187500)
mov x0[9].x, l(0.687500)
mov x0[10].x, l(0.062500)
mov x0[11].x, l(0.562500)
mov x0[12].x, l(0.937500)
mov x0[13].x, l(0.437500)
mov x0[14].x, l(0.812500)
mov x0[15].x, l(0.312500)
mul r0.xy, r0.xyxx, cb12[0].zwzz
ftoi r0.xy, r0.xyxx
bfi r0.y, l(2), l(2), r0.y, l(0)
bfi r0.x, l(2), l(0), r0.x, r0.y
mov r0.x, x0[r0.x + 0].x
mov r1.z, l(-1.000000)
dp3 r0.y, r1.xyzx, r1.xyzx
rsq r0.y, r0.y
mul r2.xyz, r0.yyyy, r1.xyzx
dp3 r0.y, r2.xyzx, cb8[8].xyzx
mad r0.y, cb8[9].z, r0.y, cb8[9].y
log r0.y, |r0.y|
mul r0.y, r0.y, l(1.500000)
exp r0.y, r0.y
div r0.y, cb8[9].x, r0.y
mov r2.w, l(1.000000)
mov r3.w, l(1.000000)
mov r4.w, l(1.000000)
mov r5.w, l(1.000000)
mov r6.yw, l(0,0,0,0)
mov r7.y, l(0)
mov r8.xyz, l(0,0,0,0)
mov r1.z, l(0)
loop 
  uge r1.w, r1.z, r0.w
  breakc_nz r1.w
  mul r2.xy, r1.xyxx, cb8[r1.z + 0].xxxx
  mov r2.z, -cb8[r1.z + 0].x
  dp4 r3.x, r2.xyzw, cb0[12].xyzw
  dp4 r3.y, r2.xyzw, cb0[13].xyzw
  dp4 r3.z, r2.xyzw, cb0[14].xyzw
  ishl r1.w, r1.z, l(2)
  dp4 r2.x, r3.xyzw, cb10[r1.w + 7].xyzw
  dp4 r2.y, r3.xyzw, cb10[r1.w + 8].xyzw
  dp4 r9.z, r3.xyzw, cb10[r1.w + 9].xyzw
  mad r9.xy, r2.xyxx, l(0.500000, -0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
  mul r4.xy, r1.xyxx, cb8[r1.z + 0].yyyy
  mov r4.z, -cb8[r1.z + 0].y
  dp4 r5.x, r4.xyzw, cb0[12].xyzw
  dp4 r5.y, r4.xyzw, cb0[13].xyzw
  dp4 r5.z, r4.xyzw, cb0[14].xyzw
  dp4 r2.x, r5.xyzw, cb10[r1.w + 7].xyzw
  dp4 r2.y, r5.xyzw, cb10[r1.w + 8].xyzw
  dp4 r10.z, r5.xyzw, cb10[r1.w + 9].xyzw
  mad r10.xy, r2.xyxx, l(0.500000, -0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
  mov r9.w, cb8[r1.z + 0].x
  mov r10.w, cb8[r1.z + 0].y
  add r10.xyzw, -r9.xyzw, r10.xyzw
  div r10.xyzw, r10.xyzw, cb8[r1.z + 0].zzzz
  min r1.w, r0.z, cb8[r1.z + 0].y
  add r1.w, r1.w, l(-0.100000)
  mad r9.xyzw, r0.xxxx, r10.xyzw, r9.xyzw
  lt r2.x, r9.w, r1.w
  if_nz r2.x
    and r2.x, r1.z, l(1)
    ushr r2.y, r1.z, l(1)
    utof r3.xy, r2.xyxx
    mul r2.xy, r3.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
    lt r3.xy, r9.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
    lt r4.xy, l(1.000000, 1.000000, 0.000000, 0.000000), r9.xyxx
    or r2.z, r3.x, r4.x
    or r2.z, r3.y, r2.z
    or r2.z, r4.y, r2.z
    if_z r2.z
      mad r3.xy, r9.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000), r2.xyxx
      sample_l_indexable(texture2d)(float,float,float,float) r2.z, r3.xyxx, t11.yzxw, s11, l(0.000000)
      lt r2.z, r9.z, r2.z
      if_nz r2.z
        mul r6.x, r9.w, cb8[8].w
        sample_l_indexable(texture2d)(float,float,float,float) r2.z, r6.xyxx, t12.yzxw, s12, l(0.000000)
      else 
        mov r2.z, l(0)
      endif 
      add r9.xyzw, r10.xyzw, r9.xyzw
    else 
      mov r2.z, l(0)
    endif 
    mov r11.xyzw, r9.xyzw
    mov r3.x, r2.z
    loop 
      ge r3.y, r11.w, r1.w
      breakc_nz r3.y
      lt r3.yz, r11.xxyx, l(0.000000, 0.000000, 0.000000, 0.000000)
      lt r4.xy, l(1.000000, 1.000000, 0.000000, 0.000000), r11.xyxx
      or r3.y, r3.y, r4.x
      or r3.y, r3.z, r3.y
      or r3.y, r4.y, r3.y
      if_nz r3.y
        break 
      endif 
      mad r3.yz, r11.xxyx, l(0.000000, 0.500000, 0.500000, 0.000000), r2.xxyx
      sample_l_indexable(texture2d)(float,float,float,float) r3.y, r3.yzyy, t11.yxzw, s11, l(0.000000)
      lt r3.y, r11.z, r3.y
      if_nz r3.y
        mul r7.x, r11.w, cb8[8].w
        sample_l_indexable(texture2d)(float,float,float,float) r3.y, r7.xyxx, t12.yxzw, s12, l(0.000000)
        add r3.x, r3.y, r3.x
      endif 
      add r11.xyzw, r10.xyzw, r11.xyzw
    endloop 
    mov r2.y, r11.w
    mov r2.x, r3.x
    loop 
      ge r2.z, r2.y, r1.w
      breakc_nz r2.z
      mul r6.z, r2.y, cb8[8].w
      sample_l_indexable(texture2d)(float,float,float,float) r2.z, r6.zwzz, t12.yzxw, s12, l(0.000000)
      add r2.x, r2.z, r2.x
      add r2.y, r10.w, r2.y
    endloop 
  else 
    mov r2.x, l(0)
  endif 
  mul r4.xyz, r0.yyyy, cb8[r1.z + 4].xyzx
  mad r8.xyz, r2.xxxx, r4.xyzx, r8.xyzx
  iadd r1.z, r1.z, l(1)
endloop 
mov o0.xyz, r8.xyzx
mov o0.w, l(0)
ret 
// Approximately 145 instruction slots used

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