//light shafts
// ---- Created with 3Dmigoto v1.2.39 on Tue Jun 21 11:55:43 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);
}

cbuffer PSOffsetConstants : register(b2)
{
  float4 ScreenPositionScaleBias : packoffset(c0);
  float4 MinZ_MaxZRatio : packoffset(c1);
  float NvStereoEnabled : packoffset(c2);
  float4 DiffuseOverrideParameter : packoffset(c3);
  float4 SpecularOverrideParameter : packoffset(c4);
  float4 CameraPositionPS : packoffset(c5);
  float4 ScreenAndTexelSize : packoffset(c6);
}

SamplerState SceneDepthTextureSampler_s : register(s0);
SamplerState SceneColorTextureSampler_s : register(s1);
Texture2D<float4> SceneDepthTexture : register(t0);
Texture2D<float4> SceneColorTexture : register(t1);


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


void main( 
  float4 v0 : TEXCOORD0,
  float3 v1 : TEXCOORD1,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r16;
  uint4 bitmask, uiDest;
  float4 fDest;

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

  r0.xyz = SceneColorTexture.Sample(SceneColorTextureSampler_s, v0.xy).xyz;
  r1.xy = -SampleOffsets[0].zw + v0.xy;
  r2.xyz = SceneColorTexture.Sample(SceneColorTextureSampler_s, r1.xy).xyz;
  r0.w = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r1.xy, 0).x;
  r0.w = min(0.999000013, r0.w);
  r0.w = r0.w * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r1.y = 1 / r0.w;
  r0.xyz = r2.xyz + r0.xyz;
  r2.xyzw = -SampleOffsets[1].xyzw + v0.xyxy;
  r3.xyz = SceneColorTexture.Sample(SceneColorTextureSampler_s, r2.xy).xyz;
  r0.xyz = r3.xyz + r0.xyz;
  r3.xyz = SceneColorTexture.Sample(SceneColorTextureSampler_s, r2.zw).xyz;
  r0.xyz = r3.xyz + r0.xyz;
  r0.xyz = float3(0.25,0.25,0.25) * r0.xyz;
  r3.xyz = LightShaftParameters.yyy * r0.xyz;
  r0.x = dot(r0.xyz, float3(0.300000012,0.589999974,0.109999999));
  r0.x = max(6.10351999e-005, r0.x);
  r0.yzw = r3.xyz / r0.xxx;
  r0.x = -BloomTintAndThreshold.w + r0.x;
  r0.x = max(0, r0.x);
  r0.xyz = r0.yzw * r0.xxx;
  r0.xyz = r0.xyz + r0.xyz;
  r0.w = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r2.xy, 0).x;
  r2.x = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r2.zw, 0).x;
  r2.x = min(0.999000013, r2.x);
  r2.x = r2.x * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r1.w = 1 / r2.x;
  r0.w = min(0.999000013, r0.w);
  r0.w = r0.w * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r1.z = 1 / r0.w;
  r0.w = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, v0.xy, 0).x;
  r0.w = min(0.999000013, r0.w);
  r0.w = r0.w * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r1.x = 1 / r0.w;
  r0.w = 0.5 / LightShaftParameters.x;
  r2.xyzw = r1.xyzw + -r0.wwww;
  r1.xyzw = saturate(LightShaftParameters.xxxx * r1.xyzw);
  r0.w = dot(r1.xyzw, float4(0.25,0.25,0.25,0.25));
  r1.xyzw = saturate(LightShaftParameters.xxxx * r2.xyzw);
  r1.x = dot(r1.xyzw, float4(0.25,0.25,0.25,0.25));
  r0.xyz = r1.xxx * r0.xyz;
  r1.xy = -UVMinMax.xy + v0.xy;
  r1.xy = r1.xy / UVMinMax.zw;
  r1.zw = float2(1,1) + -r1.xy;
  r1.x = r1.x * r1.z;
  r1.x = r1.x * r1.y;
  r1.x = r1.x * r1.w;
  r1.x = -r1.x * 8 + 1;
  r1.x = r1.x * r1.x;
  r1.y = -r1.x * r1.x + 1;
  r1.x = r1.x * r1.x;
  o0.w = max(r1.x, r0.w);
  r0.xyz = r1.yyy * r0.xyz;
 r1.xy = -v0.xy * AspectRatioAndInvAspectRatio.zw + r16.xy;
  r0.w = dot(r1.xy, r1.xy);
  r0.w = sqrt(r0.w);
  r0.w = 5 * r0.w;
  r0.w = min(1, r0.w);
  r0.w = 1 + -r0.w;
  r0.w = r0.w * r0.w;
  r0.xyz = r0.www * r0.xyz;
  o0.xyz = float3(0.25,0.25,0.25) * r0.xyz;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Tue Jun 21 11:55:43 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
//   float DistanceFade;                // Offset:  352 Size:     4 [unused]
//   float4 SampleOffsets[2];           // Offset:  368 Size:    32
//   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]
//
// }
//
// cbuffer PSOffsetConstants
// {
//
//   float4 ScreenPositionScaleBias;    // Offset:    0 Size:    16 [unused]
//   float4 MinZ_MaxZRatio;             // Offset:   16 Size:    16
//   float NvStereoEnabled;             // Offset:   32 Size:     4 [unused]
//   float4 DiffuseOverrideParameter;   // Offset:   48 Size:    16 [unused]
//   float4 SpecularOverrideParameter;  // Offset:   64 Size:    16 [unused]
//   float4 CameraPositionPS;           // Offset:   80 Size:    16 [unused]
//   float4 ScreenAndTexelSize;         // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SceneDepthTextureSampler          sampler      NA          NA    0        1
// SceneColorTextureSampler          sampler      NA          NA    1        1
// SceneDepthTexture                 texture  float4          2d    0        1
// SceneColorTexture                 texture  float4          2d    1        1
// $Globals                          cbuffer      NA          NA    0        1
// PSOffsetConstants                 cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float   xy  
// TEXCOORD                 1   xyz         1     NONE   float       
//
//
// 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[25], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
dcl_temps 4
sample_indexable(texture2d)(float,float,float,float) r0.xyz, v0.xyxx, t1.xyzw, s1
add r1.xy, v0.xyxx, -cb0[23].zwzz
sample_indexable(texture2d)(float,float,float,float) r2.xyz, r1.xyxx, t1.xyzw, s1
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r1.xyxx, t0.yzwx, s0, l(0.000000)
min r0.w, r0.w, l(0.999000)
mad r0.w, r0.w, cb2[1].z, -cb2[1].w
div r1.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
add r0.xyz, r0.xyzx, r2.xyzx
add r2.xyzw, v0.xyxy, -cb0[24].xyzw
sample_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyxx, t1.xyzw, s1
add r0.xyz, r0.xyzx, r3.xyzx
sample_indexable(texture2d)(float,float,float,float) r3.xyz, r2.zwzz, t1.xyzw, s1
add r0.xyz, r0.xyzx, r3.xyzx
mul r0.xyz, r0.xyzx, l(0.250000, 0.250000, 0.250000, 0.000000)
mul r3.xyz, r0.xyzx, cb0[20].yyyy
dp3 r0.x, r0.xyzx, l(0.300000, 0.590000, 0.110000, 0.000000)
max r0.x, r0.x, l(0.0000610351999)
div r0.yzw, r3.xxyz, r0.xxxx
add r0.x, r0.x, -cb0[21].w
max r0.x, r0.x, l(0.000000)
mul r0.xyz, r0.xxxx, r0.yzwy
add r0.xyz, r0.xyzx, r0.xyzx
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r2.xyxx, t0.yzwx, s0, l(0.000000)
sample_l_indexable(texture2d)(float,float,float,float) r2.x, r2.zwzz, t0.xyzw, s0, l(0.000000)
min r2.x, r2.x, l(0.999000)
mad r2.x, r2.x, cb2[1].z, -cb2[1].w
div r1.w, l(1.000000, 1.000000, 1.000000, 1.000000), r2.x
min r0.w, r0.w, l(0.999000)
mad r0.w, r0.w, cb2[1].z, -cb2[1].w
div r1.z, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
sample_l_indexable(texture2d)(float,float,float,float) r0.w, v0.xyxx, t0.yzwx, s0, l(0.000000)
min r0.w, r0.w, l(0.999000)
mad r0.w, r0.w, cb2[1].z, -cb2[1].w
div r1.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
div r0.w, l(0.500000), cb0[20].x
add r2.xyzw, -r0.wwww, r1.xyzw
mul_sat r1.xyzw, r1.xyzw, cb0[20].xxxx
dp4 r0.w, r1.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
mul_sat r1.xyzw, r2.xyzw, cb0[20].xxxx
dp4 r1.x, r1.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
mul r0.xyz, r0.xyzx, r1.xxxx
add r1.xy, v0.xyxx, -cb0[18].xyxx
div r1.xy, r1.xyxx, cb0[18].zwzz
add r1.zw, -r1.xxxy, l(0.000000, 0.000000, 1.000000, 1.000000)
mul r1.x, r1.z, r1.x
mul r1.x, r1.y, r1.x
mul r1.x, r1.w, r1.x
mad r1.x, -r1.x, l(8.000000), l(1.000000)
mul r1.x, r1.x, r1.x
mad r1.y, -r1.x, r1.x, l(1.000000)
mul r1.x, r1.x, r1.x
max o0.w, r0.w, r1.x
mul r0.xyz, r0.xyzx, r1.yyyy
mad r1.xy, -v0.xyxx, cb0[19].zwzz, cb0[13].xyxx
dp2 r0.w, r1.xyxx, r1.xyxx
sqrt r0.w, r0.w
mul r0.w, r0.w, l(5.000000)
min r0.w, r0.w, l(1.000000)
add r0.w, -r0.w, l(1.000000)
mul r0.w, r0.w, r0.w
mul r0.xyz, r0.xyzx, r0.wwww
mul o0.xyz, r0.xyzx, l(0.250000, 0.250000, 0.250000, 0.000000)
ret 
// Approximately 63 instruction slots used

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