
cbuffer PER_FRAME : register(b0)
{
  float3 light_hemispheric_color_top : packoffset(c0);
  float3 light_hemispheric_color_bottom : packoffset(c1);
  float3 light_hemispheric_color_xn : packoffset(c2);
  float3 light_hemispheric_color_xp : packoffset(c3);
  float3 light_hemispheric_color_zn : packoffset(c4);
  float3 light_hemispheric_color_zp : packoffset(c5);
  float4 ssao_parameters : packoffset(c6);
  float4 shadowmap_texture_size : packoffset(c7);
  float4 backbuffer_size : packoffset(c8);
}

cbuffer PER_STAGE : register(b1)
{
  float4 camera_position_viewspace : packoffset(c0);
  float3 camera_upvector : packoffset(c1);
  float4x4 inverse_view_matrix : packoffset(c2);
  float4x4 projection_matrix : packoffset(c6);
  float4 camera_clip_distances : packoffset(c10);
}

cbuffer PER_LIGHT : register(b2)
{
  float4 light_position_viewspace : packoffset(c0);
  float4x4 light_viewprojection_matrix_viewspace : packoffset(c1);
  float4 light_color_diffuse : packoffset(c5);
  float4 light_color_specular : packoffset(c6);
  float4 light_color_diffuse_back : packoffset(c7);
  float4 light_ies_parameters : packoffset(c8);
  float4 light_specular_parameters : packoffset(c9);
  float3 light_direction_viewspace : packoffset(c10);
  float3 light_direction_worldspace : packoffset(c11);
  float4 light_subsurface_scattering_parameters : packoffset(c12);
  float4 light_subsurface_scattering_color : packoffset(c13);
  float4 light_color_diffuse0 : packoffset(c14);
  float4 light_color_specular0 : packoffset(c15);
  float4 light_specular_parameters0 : packoffset(c16);
  float3 light_direction_viewspace0 : packoffset(c17);
  float4 light_color_diffuse_back0 : packoffset(c18);
  float4 light_rimlight_color : packoffset(c19);
  float4 light_rimlight_parameters : packoffset(c20);
  float4 light_parameters : packoffset(c21);
  float4 shadow_parameters : packoffset(c22);
  float4 light_projector_parameters : packoffset(c23);
  float4 light_attenuation_parameters : packoffset(c24);
  float4 light_screenspace_shadows_parameters : packoffset(c25);
  float4 genericparam_shadowmask_channelmask : packoffset(c26);
}
SamplerState sampler_point_clamp_s : register(s1);
SamplerState sampler_bilinear_wrap_mipBiasNeg2_s : register(s10);
SamplerComparisonState cmpSampler_less_trilinear_border_s : register(s13);
Texture2D<float4> depthSampler : register(t0);
Texture2D<float4> shadowMapSampler : register(t1);
Texture2D<float4> transparentShadowSampler : register(t2);

Texture2D<float4> StereoParams : register(t125);
Texture1D<float4> IniParams : register(t120);

void main(
  float4 v0 : SV_Position0,
  float4 v1 : Texcoord0,
  float2 v2 : Texcoord1,
  float4 v3 : Texcoord3, 
  out float4 o0 : SV_Target0)
{
  const float4 icb[] = { { -0.942016, -0.399062, 0, 0},
                              { 0.945586, -0.768907, 0, 0},
                              { -0.094184, -0.929389, 0, 0},
                              { 0.344959, 0.293878, 0, 0},
                              { -0.915886, 0.457714, 0, 0},
                              { -0.815442, -0.879125, 0, 0},
                              { -0.382775, 0.276768, 0, 0},
                              { 0.974844, 0.756484, 0, 0},
                              { 0.443233, -0.975116, 0, 0},
                              { 0.537430, -0.473734, 0, 0},
                              { -0.264969, -0.418930, 0, 0},
                              { 0.791975, 0.190902, 0, 0},
                              { -0.241888, 0.997065, 0, 0},
                              { -0.814100, 0.914376, 0, 0},
                              { 0.199841, 0.786414, 0, 0},
                              { 0.143832, -0.141008, 0, 0} };
  float4 r0,r1,r2;
  uint4 bitmask;
  r0.x = depthSampler.SampleLevel(sampler_point_clamp_s, v2.xy, 0.000000000e+000).x;
  r0.x = -camera_clip_distances.z + r0.x;
  r0.x = camera_clip_distances.w / r0.x;
  
float4 stereo = StereoParams.Load(0);
float4 iniParams = IniParams.Load(0);
float4 r25;
r25.xyz = v1.xyz * r0.xxx;

// Surround fix
float fac;
fac = 0.83; //1/v3.x; //0.82; 
if (iniParams.y == 1)
{
  fac *= 3;
}

r25.x -= stereo.x*(-r25.z - stereo.y)*fac; // /v3.x; ; 

r0.xyz = r25.xyz;
  // r0.xyz = v1.xyz * r0.xxx;
  r0.w = 1.000000000e+000;
  r1.x = dot(r0.xyzw, light_viewprojection_matrix_viewspace._m00_m10_m20_m30);
  r1.y = dot(r0.xyzw, light_viewprojection_matrix_viewspace._m01_m11_m21_m31);
  r1.z = dot(r0.xyzw, light_viewprojection_matrix_viewspace._m02_m12_m22_m32);
  r0.x = dot(r0.xyzw, light_viewprojection_matrix_viewspace._m03_m13_m23_m33);
  r0.xyz = r1.zxy / r0.xxx;
  r0.x = saturate(r0.x);
  r0.x = -9.999999747e-006 + r0.x;
  r1.xy = shadow_parameters.xx * shadowmap_texture_size.zw;
  r0.w = 0.000000000e+000;
  r1.z = 0.000000000e+000;
  while (true) {
  r1.w = (int)r1.z >= (int)16;
  if (r1.w != 0) break;
  r2.xy = icb[r1.z].xy * r1.xy + r0.yz;
  r1.w = shadowMapSampler.SampleCmpLevelZero(cmpSampler_less_trilinear_border_s, r2.xy, r0.x).x;
  r0.w = r1.w + r0.w;
  r1.z = (int)r1.z + 1;
  }
  r0.x = 6.250000000e-002 * r0.w;
  r0.yzw = transparentShadowSampler.SampleLevel(sampler_bilinear_wrap_mipBiasNeg2_s, r0.yz, 0.000000000e+000).xyz;
  o0.yzw = r0.xxx * r0.yzw;
  o0.x = r0.x;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20499
//
//
// Buffer Definitions: 
//
// cbuffer PER_FRAME
// {
//
//   float3 light_hemispheric_color_top;// Offset:    0 Size:    12 [unused]
//   float3 light_hemispheric_color_bottom;// Offset:   16 Size:    12 [unused]
//   float3 light_hemispheric_color_xn; // Offset:   32 Size:    12 [unused]
//   float3 light_hemispheric_color_xp; // Offset:   48 Size:    12 [unused]
//   float3 light_hemispheric_color_zn; // Offset:   64 Size:    12 [unused]
//   float3 light_hemispheric_color_zp; // Offset:   80 Size:    12 [unused]
//   float4 ssao_parameters;            // Offset:   96 Size:    16 [unused]
//   float4 shadowmap_texture_size;     // Offset:  112 Size:    16
//   float4 backbuffer_size;            // Offset:  128 Size:    16 [unused]
//
// }
//
// cbuffer PER_STAGE
// {
//
//   float4 camera_position_viewspace;  // Offset:    0 Size:    16 [unused]
//   float3 camera_upvector;            // Offset:   16 Size:    12 [unused]
//   float4x4 inverse_view_matrix;      // Offset:   32 Size:    64 [unused]
//   float4x4 projection_matrix;        // Offset:   96 Size:    64 [unused]
//   float4 camera_clip_distances;      // Offset:  160 Size:    16
//
// }
//
// cbuffer PER_LIGHT
// {
//
//   float4 light_position_viewspace;   // Offset:    0 Size:    16 [unused]
//   float4x4 light_viewprojection_matrix_viewspace;// Offset:   16 Size:    64
//   float4 light_color_diffuse;        // Offset:   80 Size:    16 [unused]
//   float4 light_color_specular;       // Offset:   96 Size:    16 [unused]
//   float4 light_color_diffuse_back;   // Offset:  112 Size:    16 [unused]
//   float4 light_ies_parameters;       // Offset:  128 Size:    16 [unused]
//   float4 light_specular_parameters;  // Offset:  144 Size:    16 [unused]
//   float3 light_direction_viewspace;  // Offset:  160 Size:    12 [unused]
//   float3 light_direction_worldspace; // Offset:  176 Size:    12 [unused]
//   float4 light_subsurface_scattering_parameters;// Offset:  192 Size:    16 [unused]
//   float4 light_subsurface_scattering_color;// Offset:  208 Size:    16 [unused]
//   float4 light_color_diffuse0;       // Offset:  224 Size:    16 [unused]
//   float4 light_color_specular0;      // Offset:  240 Size:    16 [unused]
//   float4 light_specular_parameters0; // Offset:  256 Size:    16 [unused]
//   float3 light_direction_viewspace0; // Offset:  272 Size:    12 [unused]
//   float4 light_color_diffuse_back0;  // Offset:  288 Size:    16 [unused]
//   float4 light_rimlight_color;       // Offset:  304 Size:    16 [unused]
//   float4 light_rimlight_parameters;  // Offset:  320 Size:    16 [unused]
//   float4 light_parameters;           // Offset:  336 Size:    16 [unused]
//   float4 shadow_parameters;          // Offset:  352 Size:    16
//   float4 light_projector_parameters; // Offset:  368 Size:    16 [unused]
//   float4 light_attenuation_parameters;// Offset:  384 Size:    16 [unused]
//   float4 light_screenspace_shadows_parameters;// Offset:  400 Size:    16 [unused]
//   float4 genericparam_shadowmask_channelmask;// Offset:  416 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sampler_point_clamp               sampler      NA          NA    1        1
// sampler_bilinear_wrap_mipBiasNeg2    sampler      NA          NA   10        1
// cmpSampler_less_trilinear_border  sampler_c      NA          NA   13        1
// depthSampler                      texture  float4          2d    0        1
// shadowMapSampler                  texture  float4          2d    1        1
// transparentShadowSampler          texture  float4          2d    2        1
// PER_FRAME                         cbuffer      NA          NA    0        1
// PER_STAGE                         cbuffer      NA          NA    1        1
// PER_LIGHT                         cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float       
// Texcoord                 0   xyzw        1     NONE   float   xyz 
// Texcoord                 1   xy          2     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_immediateConstantBuffer { { -0.942016, -0.399062, 0, 0},
                              { 0.945586, -0.768907, 0, 0},
                              { -0.094184, -0.929389, 0, 0},
                              { 0.344959, 0.293878, 0, 0},
                              { -0.915886, 0.457714, 0, 0},
                              { -0.815442, -0.879125, 0, 0},
                              { -0.382775, 0.276768, 0, 0},
                              { 0.974844, 0.756484, 0, 0},
                              { 0.443233, -0.975116, 0, 0},
                              { 0.537430, -0.473734, 0, 0},
                              { -0.264969, -0.418930, 0, 0},
                              { 0.791975, 0.190902, 0, 0},
                              { -0.241888, 0.997065, 0, 0},
                              { -0.814100, 0.914376, 0, 0},
                              { 0.199841, 0.786414, 0, 0},
                              { 0.143832, -0.141008, 0, 0} }
dcl_constantbuffer cb0[8], immediateIndexed
dcl_constantbuffer cb1[11], immediateIndexed
dcl_constantbuffer cb2[23], immediateIndexed
dcl_sampler s1, mode_default
dcl_sampler s10, mode_default
dcl_sampler s13, 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_input_ps linear v1.xyz
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 3
sample_l_indexable(texture2d)(float,float,float,float) r0.x, v2.xyxx, t0.xyzw, s1, l(0.000000)
add r0.x, r0.x, -cb1[10].z
div r0.x, cb1[10].w, r0.x
mul r0.xyz, r0.xxxx, v1.xyzx
mov r0.w, l(1.000000)
dp4 r1.x, r0.xyzw, cb2[1].xyzw
dp4 r1.y, r0.xyzw, cb2[2].xyzw
dp4 r1.z, r0.xyzw, cb2[3].xyzw
dp4 r0.x, r0.xyzw, cb2[4].xyzw
div r0.xyz, r1.zxyz, r0.xxxx
mov_sat r0.x, r0.x
add r0.x, r0.x, l(-0.000010)
mul r1.xy, cb0[7].zwzz, cb2[22].xxxx
mov r0.w, l(0)
mov r1.z, l(0)
loop 
  ige r1.w, r1.z, l(16)
  breakc_nz r1.w
  mad r2.xy, icb[r1.z + 0].xyxx, r1.xyxx, r0.yzyy
  sample_c_lz_indexable(texture2d)(float,float,float,float) r1.w, r2.xyxx, t1.xxxx, s13, r0.x
  add r0.w, r0.w, r1.w
  iadd r1.z, r1.z, l(1)
endloop 
mul r0.x, r0.w, l(0.062500)
sample_l_indexable(texture2d)(float,float,float,float) r0.yzw, r0.yzyy, t2.wxyz, s10, l(0.000000)
mul o0.yzw, r0.yyzw, r0.xxxx
mov o0.x, r0.x
ret 
// Approximately 28 instruction slots used
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
   