//light shafts
// ---- Created with 3Dmigoto v1.2.39 on Tue Jun 21 11:56:02 2016

cbuffer _Globals : register(b0)
{
  float4x4 ScreenToWorldMatrix : packoffset(c0);
  bool bDecompressSceneColor : packoffset(c4);
  float4x4 ScreenToWorld : packoffset(c5);
  float4x4 ScreenToViewport : packoffset(c9);
  float2 TextureSpaceBlurOrigin : packoffset(c13);
  float4 WorldSpaceBlurOriginAndRadius : packoffset(c14);
  float3 WorldSpaceSpotDirection : packoffset(c15);
  float2 SpotAngles : packoffset(c16);
  float4 WorldSpaceCameraPositionAndDistance : packoffset(c17);
  float4 UVMinMax : packoffset(c18);
  float4 AspectRatioAndInvAspectRatio : packoffset(c19);
  float4 LightShaftParameters : packoffset(c20);
  float4 BloomTintAndThreshold : packoffset(c21);
  float DistanceFade : packoffset(c22);
  float4 SampleOffsets[2] : packoffset(c23);
  float BlurPassIndex : packoffset(c25);
  float4 SourceTextureScaleBias : packoffset(c26);
  float4 SceneColorScaleBias : packoffset(c27);
  float BloomScreenBlendThreshold : packoffset(c28);
}

SamplerState SourceTextureSampler_s : register(s0);
Texture2D<float4> SourceTexture : register(t0);


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


void main( 
  float2 v0 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r16;
  uint4 bitmask, uiDest;
  float4 fDest;


float4 stereo = StereoParams.Load(0);
r16.xy = TextureSpaceBlurOrigin.xy;
r16.x += stereo.x * 0.5;

  r0.xyzw = AspectRatioAndInvAspectRatio.zwzw * v0.xyxy;
 r1.xyzw = -v0.xyxy * AspectRatioAndInvAspectRatio.zwzw + r16.xyxy;
  r2.x = dot(r1.zw, r1.zw);
  r2.x = sqrt(r2.x);
  r2.x = 0.5 * r2.x;
  r1.xyzw = r1.xyzw / r2.xxxx;
  r2.y = sqrt(r2.x);
  r2.y = 0.5 * r2.y;
  r2.x = min(r2.y, r2.x);
  r1.xyzw = r2.xxxx * r1.xyzw;
  r2.x = 0.015625 * LightShaftParameters.z;
  r1.xyzw = r2.xxxx * r1.xyzw;
  r0.xyzw = r1.zwzw * float4(0,0,1,1) + r0.xyzw;
  r1.xyzw = AspectRatioAndInvAspectRatio.xyxy * r1.xyzw;
  r0.xyzw = AspectRatioAndInvAspectRatio.xyxy * r0.xyzw;
  r2.xyzw = float4(0,0,0,0);
  r3.xyzw = r0.xyzw;
  r4.xw = float2(2,1.96875);
  r5.x = 0;
  while (true) {
    r5.y = (int)r5.x;
    r5.y = cmp(r5.y >= 64);
    if (r5.y != 0) break;
    r4.zw = r4.xw;
    r5.yz = r4.zw * r4.zw;
    r5.yz = float2(4,4) * r5.yz;
    r4.xy = min(r5.yz, r4.zw);
    r6.xyzw = max(UVMinMax.xyxy, r3.xyzw);
    r6.xyzw = min(UVMinMax.zwzw, r6.xyzw);
    r7.xyzw = SourceTexture.Sample(SourceTextureSampler_s, r6.xy).xyzw;
    r7.xyzw = r7.xyzw * r4.xxxz + r2.xyzw;
    r6.xyzw = SourceTexture.Sample(SourceTextureSampler_s, r6.zw).xyzw;
    r2.xyzw = r6.xyzw * r4.yyyw + r7.xyzw;
    r4.xw = float2(-0.0625,-0.0625) + r4.zw;
    r3.xyzw = r1.xyzw * float4(2,2,2,2) + r3.xyzw;
    r5.x = (int)r5.x + 2;
  }
  o0.xyzw = float4(0.015625,0.015625,0.015625,0.015625) * r2.xyzw;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Tue Jun 21 11:56:02 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4x4 ScreenToWorldMatrix;      // Offset:    0 Size:    64 [unused]
//   bool bDecompressSceneColor;        // Offset:   64 Size:     4 [unused]
//   float4x4 ScreenToWorld;            // Offset:   80 Size:    64 [unused]
//   float4x4 ScreenToViewport;         // Offset:  144 Size:    64 [unused]
//   float2 TextureSpaceBlurOrigin;     // Offset:  208 Size:     8
//   float4 WorldSpaceBlurOriginAndRadius;// Offset:  224 Size:    16 [unused]
//   float3 WorldSpaceSpotDirection;    // Offset:  240 Size:    12 [unused]
//   float2 SpotAngles;                 // Offset:  256 Size:     8 [unused]
//   float4 WorldSpaceCameraPositionAndDistance;// Offset:  272 Size:    16 [unused]
//   float4 UVMinMax;                   // Offset:  288 Size:    16
//   float4 AspectRatioAndInvAspectRatio;// Offset:  304 Size:    16
//   float4 LightShaftParameters;       // Offset:  320 Size:    16
//   float4 BloomTintAndThreshold;      // Offset:  336 Size:    16 [unused]
//   float DistanceFade;                // Offset:  352 Size:     4 [unused]
//   float4 SampleOffsets[2];           // Offset:  368 Size:    32 [unused]
//   float BlurPassIndex;               // Offset:  400 Size:     4 [unused]
//   float4 SourceTextureScaleBias;     // Offset:  416 Size:    16 [unused]
//   float4 SceneColorScaleBias;        // Offset:  432 Size:    16 [unused]
//   float BloomScreenBlendThreshold;   // Offset:  448 Size:     4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SourceTextureSampler              sampler      NA          NA    0        1
// SourceTexture                     texture  float4          2d    0        1
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     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[21], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
dcl_temps 8
mul r0.xyzw, v0.xyxy, cb0[19].zwzw
mad r1.xyzw, -v0.xyxy, cb0[19].zwzw, cb0[13].xyxy
dp2 r2.x, r1.zwzz, r1.zwzz
sqrt r2.x, r2.x
mul r2.x, r2.x, l(0.500000)
div r1.xyzw, r1.xyzw, r2.xxxx
sqrt r2.y, r2.x
mul r2.y, r2.y, l(0.500000)
min r2.x, r2.x, r2.y
mul r1.xyzw, r1.xyzw, r2.xxxx
mul r2.x, cb0[20].z, l(0.015625)
mul r1.xyzw, r1.xyzw, r2.xxxx
mad r0.xyzw, r1.zwzw, l(0.000000, 0.000000, 1.000000, 1.000000), r0.xyzw
mul r1.xyzw, r1.xyzw, cb0[19].xyxy
mul r0.xyzw, r0.xyzw, cb0[19].xyxy
mov r2.xyzw, l(0,0,0,0)
mov r3.xyzw, r0.xyzw
mov r4.xw, l(2.000000,0,0,1.968750)
mov r5.x, l(0)
loop 
  itof r5.y, r5.x
  ge r5.y, r5.y, l(64.000000)
  breakc_nz r5.y
  mov r4.zw, r4.xxxw
  mul r5.yz, r4.zzwz, r4.zzwz
  mul r5.yz, r5.yyzy, l(0.000000, 4.000000, 4.000000, 0.000000)
  min r4.xy, r4.zwzz, r5.yzyy
  max r6.xyzw, r3.xyzw, cb0[18].xyxy
  min r6.xyzw, r6.xyzw, cb0[18].zwzw
  sample_indexable(texture2d)(float,float,float,float) r7.xyzw, r6.xyxx, t0.xyzw, s0
  mad r7.xyzw, r7.xyzw, r4.xxxz, r2.xyzw
  sample_indexable(texture2d)(float,float,float,float) r6.xyzw, r6.zwzz, t0.xyzw, s0
  mad r2.xyzw, r6.xyzw, r4.yyyw, r7.xyzw
  add r4.xw, r4.zzzw, l(-0.062500, 0.000000, 0.000000, -0.062500)
  mad r3.xyzw, r1.xyzw, l(2.000000, 2.000000, 2.000000, 2.000000), r3.xyzw
  iadd r5.x, r5.x, l(2)
endloop 
mul o0.xyzw, r2.xyzw, l(0.015625, 0.015625, 0.015625, 0.015625)
ret 
// Approximately 39 instruction slots used

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