// ---- Created with 3Dmigoto v1.2.34 on Fri Apr 29 16:51:23 2016

cbuffer PER_BATCH : register(b0)
{
  float4 g_LightPos : packoffset(c0);
  float4 g_LightDiffuse : packoffset(c1);
  row_major float4x4 g_mLightProj : packoffset(c2);
  float4 g_ScreenScale : packoffset(c6);
  float4 vWBasisX : packoffset(c7);
  float4 vWBasisY : packoffset(c8);
  float4 vWBasisZ : packoffset(c9);
  float4 irreg_kernel_2d[8] : packoffset(c10);
  float4 SSDOParams : packoffset(c18);
}

SamplerState _tex0_s : register(s0);
SamplerState _tex1_s : register(s1);
SamplerState _tex2_s : register(s2);
SamplerState _tex8_s : register(s8);
Texture2D<float4> _tex0 : register(t0);
Texture2D<float4> _tex1 : register(t1);
Texture2D<float4> _tex2 : register(t2);
Texture2D<float4> _tex8 : register(t8);


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


void main( 
  float4 v0 : SV_POSITION0,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1,
  
  float4 g_VS_NearFarClipDist : TEXCOORD2,
  float4 g_VS_ScreenSize : TEXCOORD3)
  
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

  r1.xy = v0.xy * g_ScreenScale.xy + g_ScreenScale.zw;
  r0.w = _tex0.Sample(_tex0_s, r1.xy).x;
  
  float4 stereo = StereoParams.Load(0);
  float depth = r0.w * g_VS_NearFarClipDist.y;
  v0.x -= stereo.x * (depth - stereo.y) / depth * g_VS_ScreenSize.x / 2;
  
  r0.xyz = vWBasisX.xyz * v0.xxx + vWBasisZ.xyz;
  r0.xyz = vWBasisY.xyz * v0.yyy + r0.xyz;
  
  
  r2.xyz = r0.xyz * r0.www;
  r0.xyz = -r0.xyz * r0.www + g_LightPos.xyz;
  r2.w = 1;
  r3.x = dot(g_mLightProj._m00_m01_m02_m03, r2.xyzw);
  r3.y = dot(g_mLightProj._m10_m11_m12_m13, r2.xyzw);
  r0.w = dot(g_mLightProj._m30_m31_m32_m33, r2.xyzw);
  r1.zw = r3.xy / r0.ww;
  r3.xyz = _tex2.SampleLevel(_tex2_s, r1.zw, 0).xyz;
  r4.xyzw = _tex1.Sample(_tex1_s, r1.xy).xyzw;
  r1.xyzw = _tex8.Sample(_tex8_s, r1.xy).xyzw;
  r4.xyz = r4.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r5.xy = r4.ww * float2(40.5845222,255) + float2(0.318309993,9.99999997e-007);
  r0.w = dot(r4.xyz, r4.xyz);
  r0.w = rsqrt(r0.w);
  r4.xyz = r4.xyz * r0.www;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r6.xyz = r0.xyz * r0.www;
  r0.xyz = g_LightPos.www * r0.xyz;
  r0.x = dot(r0.xyz, r0.xyz);
  r0.x = 1 + -r0.x;
  r0.x = max(0, r0.x);
  r0.y = saturate(dot(r6.xyz, r4.xyz));
  r3.xyz = r0.yyy * r3.xyz;
  r3.xyz = g_LightDiffuse.xyz * r3.xyz;
  r0.xzw = r3.xyz * r0.xxx;
  r1.xyz = r1.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r1.x = saturate(dot(r6.xyz, r1.xyz));
  r0.y = -r1.x + r0.y;
  r0.y = max(0, r0.y);
  r0.y = sqrt(r0.y);
  r0.y = r0.y * r1.w;
  r0.y = saturate(SSDOParams.x * r0.y);
  r0.y = 1 + -r0.y;
  r0.xyz = r0.xzw * r0.yyy;
  o0.xyz = r0.xyz;
  r0.xyz = g_LightDiffuse.www * r0.xyz;
  o0.w = 0;
  r0.w = dot(-r2.xyz, -r2.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = -r2.xyz * r0.www + r6.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = saturate(dot(r4.xyz, r1.xyz));
  r0.w = log2(r0.w);
  r0.w = r5.y * r0.w;
  r0.w = exp2(r0.w);
  r0.w = r5.x * r0.w;
  o1.xyz = r0.xyz * r0.www;
  o1.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.2.34 on Fri Apr 29 16:51:23 2016
//
//
// Buffer Definitions: 
//
// cbuffer PER_BATCH
// {
//
//   float4 g_LightPos;                 // Offset:    0 Size:    16
//   float4 g_LightDiffuse;             // Offset:   16 Size:    16
//   row_major float4x4 g_mLightProj;   // Offset:   32 Size:    64
//   float4 g_ScreenScale;              // Offset:   96 Size:    16
//   float4 vWBasisX;                   // Offset:  112 Size:    16
//   float4 vWBasisY;                   // Offset:  128 Size:    16
//   float4 vWBasisZ;                   // Offset:  144 Size:    16
//   float4 irreg_kernel_2d[8];         // Offset:  160 Size:   128 [unused]
//   float4 SSDOParams;                 // Offset:  288 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// _tex0                             sampler      NA          NA    0        1
// _tex1                             sampler      NA          NA    1        1
// _tex2                             sampler      NA          NA    2        1
// _tex8                             sampler      NA          NA    8        1
// _tex0                             texture  float4          2d    0        1
// _tex1                             texture  float4          2d    1        1
// _tex2                             texture  float4          2d    2        1
// _tex8                             texture  float4          2d    8        1
// PER_BATCH                         cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
// SV_Target                1   xyzw        1   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[19], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s8, mode_default
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) t8
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_temps 7
mad r0.xyz, cb0[7].xyzx, v0.xxxx, cb0[9].xyzx
mad r0.xyz, cb0[8].xyzx, v0.yyyy, r0.xyzx
mad r1.xy, v0.xyxx, cb0[6].xyxx, cb0[6].zwzz
sample_indexable(texture2d)(float,float,float,float) r0.w, r1.xyxx, t0.yzwx, s0
mul r2.xyz, r0.wwww, r0.xyzx
mad r0.xyz, -r0.xyzx, r0.wwww, cb0[0].xyzx
mov r2.w, l(1.000000)
dp4 r3.x, cb0[2].xyzw, r2.xyzw
dp4 r3.y, cb0[3].xyzw, r2.xyzw
dp4 r0.w, cb0[5].xyzw, r2.xyzw
div r1.zw, r3.xxxy, r0.wwww
sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r1.zwzz, t2.xyzw, s2, l(0.000000)
sample_indexable(texture2d)(float,float,float,float) r4.xyzw, r1.xyxx, t1.xyzw, s1
sample_indexable(texture2d)(float,float,float,float) r1.xyzw, r1.xyxx, t8.xyzw, s8
mad r4.xyz, r4.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
mad r5.xy, r4.wwww, l(40.584522, 255.000000, 0.000000, 0.000000), l(0.318310, 0.000001, 0.000000, 0.000000)
dp3 r0.w, r4.xyzx, r4.xyzx
rsq r0.w, r0.w
mul r4.xyz, r0.wwww, r4.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r6.xyz, r0.wwww, r0.xyzx
mul r0.xyz, r0.xyzx, cb0[0].wwww
dp3 r0.x, r0.xyzx, r0.xyzx
add r0.x, -r0.x, l(1.000000)
max r0.x, r0.x, l(0.000000)
dp3_sat r0.y, r6.xyzx, r4.xyzx
mul r3.xyz, r3.xyzx, r0.yyyy
mul r3.xyz, r3.xyzx, cb0[1].xyzx
mul r0.xzw, r0.xxxx, r3.xxyz
mad r1.xyz, r1.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3_sat r1.x, r6.xyzx, r1.xyzx
add r0.y, r0.y, -r1.x
max r0.y, r0.y, l(0.000000)
sqrt r0.y, r0.y
mul r0.y, r1.w, r0.y
mul_sat r0.y, r0.y, cb0[18].x
add r0.y, -r0.y, l(1.000000)
mul r0.xyz, r0.yyyy, r0.xzwx
mov o0.xyz, r0.xyzx
mul r0.xyz, r0.xyzx, cb0[1].wwww
mov o0.w, l(0)
dp3 r0.w, -r2.xyzx, -r2.xyzx
rsq r0.w, r0.w
mad r1.xyz, -r2.xyzx, r0.wwww, r6.xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, r1.xyzx
dp3_sat r0.w, r4.xyzx, r1.xyzx
log r0.w, r0.w
mul r0.w, r0.w, r5.y
exp r0.w, r0.w
mul r0.w, r0.w, r5.x
mul o1.xyz, r0.wwww, r0.xyzx
mov o1.w, l(0)
ret 
// Approximately 56 instruction slots used

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