// SCREEN SPACE REFLECTIONS -> DISABLED
// HAS 8 partner shaders: CS, DS, HS, VS - good luck

cbuffer cbMtdParam : register(b3)
{
  float4 FC_DifMapMulCol : packoffset(c0);
  float4 unused_FC_SpcMapMulCol : packoffset(c1);
  float4 unused_FC_SpcParam : packoffset(c2);
  float4 unused_FC_SSAOParam : packoffset(c3);
  float3 FC_CDRFParam : packoffset(c4);
  float4 FC_AlphaRef : packoffset(c5);
  float FC_BloodAmount : packoffset(c6);
  float4 old_FC_ParallaxParam : packoffset(c7);
  float FC_IOR : packoffset(c8);
  float4 FC_GlowScale : packoffset(c9);
  float4 FC_GhostEdgeColor : packoffset(c10);
  float4 FC_GhostEdgeParam : packoffset(c11);
  float4 FC_BmpBlendParam0 : packoffset(c12);
  float4 FC_BmpBlendParam1 : packoffset(c13);
  float FC_UNUSED_SSS_ID : packoffset(c14);
  float HC_BackFaceCull : packoffset(c15);
  float4 FC_HairSpecularParam0 : packoffset(c20);
  float4 FC_HairSpecularParam1 : packoffset(c21);
  float4 FC_HairSpecularParam2 : packoffset(c22);
  float4 FC_RimLightingParam : packoffset(c23);

  struct
  {
    float4 M_Interaction__Tessellation_Water_snp_0_color_0;
    float4 M_Interaction__Tessellation_Water_snp_0_color_1;
    float M_Interaction__Tessellation_Water_snp_0_float_0;
    float3 M_Interaction__Tessellation_Water_snp_0_float_0_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_1;
    float3 M_Interaction__Tessellation_Water_snp_0_float_1_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_15;
    float3 M_Interaction__Tessellation_Water_snp_0_float_15_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_17;
    float3 M_Interaction__Tessellation_Water_snp_0_float_17_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_18;
    float3 M_Interaction__Tessellation_Water_snp_0_float_18_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_2;
    float3 M_Interaction__Tessellation_Water_snp_0_float_2_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_21;
    float3 M_Interaction__Tessellation_Water_snp_0_float_21_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_22;
    float3 M_Interaction__Tessellation_Water_snp_0_float_22_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_23;
    float3 M_Interaction__Tessellation_Water_snp_0_float_23_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_25;
    float3 M_Interaction__Tessellation_Water_snp_0_float_25_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_26;
    float3 M_Interaction__Tessellation_Water_snp_0_float_26_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_27;
    float3 M_Interaction__Tessellation_Water_snp_0_float_27_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_28;
    float3 M_Interaction__Tessellation_Water_snp_0_float_28_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_29;
    float3 M_Interaction__Tessellation_Water_snp_0_float_29_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_3;
    float3 M_Interaction__Tessellation_Water_snp_0_float_3_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_30;
    float3 M_Interaction__Tessellation_Water_snp_0_float_30_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_31;
    float3 M_Interaction__Tessellation_Water_snp_0_float_31_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_32;
    float3 M_Interaction__Tessellation_Water_snp_0_float_32_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_33;
    float3 M_Interaction__Tessellation_Water_snp_0_float_33_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_35;
    float3 M_Interaction__Tessellation_Water_snp_0_float_35_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_36;
    float3 M_Interaction__Tessellation_Water_snp_0_float_36_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_37;
    float3 M_Interaction__Tessellation_Water_snp_0_float_37_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_38;
    float3 M_Interaction__Tessellation_Water_snp_0_float_38_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_39;
    float3 M_Interaction__Tessellation_Water_snp_0_float_39_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_40;
    float3 M_Interaction__Tessellation_Water_snp_0_float_40_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_42;
    float3 M_Interaction__Tessellation_Water_snp_0_float_42_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_43;
    float3 M_Interaction__Tessellation_Water_snp_0_float_43_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_44;
    float3 M_Interaction__Tessellation_Water_snp_0_float_44_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_5;
    float3 M_Interaction__Tessellation_Water_snp_0_float_5_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_6;
    float3 M_Interaction__Tessellation_Water_snp_0_float_6_PADDING;
    float M_Interaction__Tessellation_Water_snp_0_float_7;
    float3 M_Interaction__Tessellation_Water_snp_0_float_7_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_0;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_0_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_1;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_1_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_10;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_10_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_2;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_2_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_3;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_3_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_4;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_4_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_5;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_5_PADDING;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_7;
    float2 M_Interaction__Tessellation_Water_snp_0_float2_7_PADDING;
    float3 M_Interaction__Tessellation_Water_snp_0_float3_0;
    float M_Interaction__Tessellation_Water_snp_0_float3_0_PADDING;
    float3 M_Interaction__Tessellation_Water_snp_0_float3_1;
    float M_Interaction__Tessellation_Water_snp_0_float3_1_PADDING;
    float3 M_Interaction__Tessellation_Water_snp_0_float3_2;
    float M_Interaction__Tessellation_Water_snp_0_float3_2_PADDING;
    float3 M_Interaction__Tessellation_Water_snp_0_float3_3;
    float M_Interaction__Tessellation_Water_snp_0_float3_3_PADDING;
  } SAT_MtdParam : packoffset(c24);

}

cbuffer cbPerScene : register(b0)
{
  float4x4 g_InvProjMatrix : packoffset(c0);
  float4x4 g_ProjMatrix : packoffset(c4);
  float4x4 g_ViewMatrix : packoffset(c8);
  float4x4 g_ReprojMatrix : packoffset(c12);
  float4 g_fadeParam : packoffset(c16);
  float4 g_vDepthComputeParam : packoffset(c17);
  float2 g_vScreenSize : packoffset(c18);
  float4 g_rayTraceParam : packoffset(c19);
  float4 rayTerminateInvDist : packoffset(c20);
  float4 g_DepthRejectParam : packoffset(c21);
  float2 g_FresnelRejectParam : packoffset(c22);
  float2 g_ShininessRejectParam : packoffset(c22.z);
  int binarySearchLoopCount : packoffset(c23);
  float stepCountSafetyMax : packoffset(c23.y);
  float2 rayTraceStepScaleMinMax : packoffset(c23.z);
  float4x4 g_CurViewToPrevProj : packoffset(c24);
  float2 viewTangent : packoffset(c28);
  int debugMode : packoffset(c28.z);
  float sceneMultiplyer : packoffset(c28.w);
  float2 dispMipScaleOffset : packoffset(c29);
  float4x4 g_CurViewToPrevView : packoffset(c30);
  float4x4 g_PrevProjMatrix : packoffset(c34);
  float displayMipOffset : packoffset(c38.w);
}

SamplerState SS_ClampPoint_s : register(s7);
SamplerState SS_ClampLinear_s : register(s9);
Texture2D<float4> g_PrevFrameTexture : register(t26);
Texture2D<float4> g_ConvertedDepthTexture : register(t27);


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


void main(
  float4 v0 : SV_POSITION0,
  float4 v1 : POSITION1,
  float4 v2 : NORMAL0,
  float4 v3 : TANGENT0,
  float4 v4 : TEXCOORD0,
  float4 v5 : TEXCOORD3,
  float4 v6 : TEXCOORD6,
  uint v7 : SV_ISFRONTFACE0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.x = saturate(SAT_MtdParam.M_Interaction__Tessellation_Water_snp_0_float_2);
  r0.y = cmp(r0.x < g_ShininessRejectParam.x);
  if (r0.y != 0) {
    o0.xyzw = float4(0,0,0,0);
  } else {
    r1.z = 1 / v1.w;
    r0.y = cmp(g_DepthRejectParam.y >= r1.z);
    if (r0.y != 0) {
      r2.xyzw = float4(0,0,0,0);
    }
    if (r0.y == 0) {
      r0.y = dot(v2.xyz, v2.xyz);
      r0.y = rsqrt(r0.y);
      r0.yzw = v2.xyz * r0.yyy;
      r0.yzw = v7.xxx ? r0.yzw : -r0.yzw;
	  
	  float2 temp = v1.xy;
	  float4 iniParams = IniParams.Load(0);
	  
      r3.xy = temp.xy / v1.ww;
	  
      r4.x = dot(r0.yzw, g_ViewMatrix._m00_m10_m20);
      r4.y = dot(r0.yzw, g_ViewMatrix._m01_m11_m21);
      r4.z = dot(r0.yzw, g_ViewMatrix._m02_m12_m22);
	  
      r0.yz = viewTangent.xy * r3.xy;
      r5.xy = v1.ww * r0.yz;
      r5.z = v1.w;
      r0.y = dot(r5.xyz, r5.xyz);
      r0.y = rsqrt(r0.y);
      r0.yzw = r5.xyz * r0.yyy;
      r1.w = dot(r0.yzw, r4.xyz);
      r1.w = r1.w + r1.w;
      r6.xyz = r4.xyz * -r1.www + r0.yzw;
      r1.w = dot(r6.xyz, r6.xyz);
      r1.w = rsqrt(r1.w);
      r3.z = r6.z * r1.w;
      r3.z = cmp(r3.z < g_fadeParam.x);
      if (r3.z != 0) {
        r2.xyzw = float4(0,0,0,0);
      }
      if (r3.z == 0) {
        r3.z = saturate(SAT_MtdParam.M_Interaction__Tessellation_Water_snp_0_float_1);
        r3.z = r3.z * -0.0299999993 + 0.0299999993;
        r0.y = dot(-r0.yzw, r4.xyz);
        r0.y = min(1, abs(r0.y));
        r0.y = 1 + -r0.y;
        r0.z = r0.y * r0.y;
        r0.z = r0.z * r0.z;
        r0.y = r0.y * r0.z;
        r0.z = 1 + -r3.z;
        r0.y = r0.z * r0.y;
        r0.x = r0.x * r0.x;
        r0.x = r0.y * r0.x + r3.z;
        r0.y = cmp(r0.x < g_FresnelRejectParam.x);
        if (r0.y != 0) {
          o0.xyzw = float4(0,0,0,0);
        } else {
          o0.xyzw = r2.xyzw;
        }
        if (r0.y == 0) {
          r1.xy = r3.xy * float2(0.5,-0.5) + float2(0.5,0.5);
          r0.y = saturate(r6.z * r1.w + -g_fadeParam.x);
          r0.y = r0.y * r0.y;
          r0.x = -g_FresnelRejectParam.x + r0.x;
          r0.x = saturate(10 * r0.x);
          r0.x = min(r0.y, r0.x);
          r0.y = g_DepthRejectParam.x + -v1.w;
          r0.y = saturate(g_DepthRejectParam.z * r0.y);
          r0.x = min(r0.x, r0.y);
          r3.xyz = r6.xyz * r1.www + r5.xyz;
          r3.w = 1;
          r4.x = dot(r3.xyzw, g_ProjMatrix._m00_m10_m20_m30);
          r4.y = dot(r3.xyzw, g_ProjMatrix._m01_m11_m21_m31);
          r0.y = dot(r3.xyzw, g_ProjMatrix._m03_m13_m23_m33);
          r4.xy = r4.xy / r0.yy;
          r4.z = 1 / r3.z;
          r0.yzw = r4.xyz + -r1.xyz;
          r3.xy = g_vScreenSize.xy * r0.yz;
          r1.w = dot(r3.xy, r3.xy);
          r1.w = sqrt(r1.w);
          r1.w = 9.99999975e-006 + r1.w;
          r0.yzw = r0.yzw / r1.www;
          r3.xyz = rayTraceStepScaleMinMax.xxx * r0.yzw;
          r4.xyz = cmp(float3(0,0,0) < r3.xyz);
          r5.xy = r4.xy ? float2(1,1) : 0;
          r5.z = r4.z ? rayTerminateInvDist.x : rayTerminateInvDist.y;
          r4.xyz = r5.xyz + -r1.xyz;
          r5.xyz = float3(1.00000001e-007,1.00000001e-007,1.00000001e-007) + abs(r3.xyz);
          r4.xyz = abs(r4.xyz) / r5.xyz;
          r1.w = min(r4.x, r4.y);
          r3.z = 2 + r4.z;
          r1.w = min(r3.z, r1.w);
          r1.w = min(stepCountSafetyMax, r1.w);
          r1.w = (int)r1.w;
          r4.xyz = r0.yzw * rayTraceStepScaleMinMax.xxx + r1.xyz;
          r3.z = log2(rayTraceStepScaleMinMax.x);
          r3.z = 0.999000013 + r3.z;
          r3.z = (int)r3.z;
          r3.w = dot(r3.xy, r3.xy);
          r3.w = rsqrt(r3.w);
          r3.xy = r3.xy * r3.ww;
          r5.z = 1;
          r6.xyz = float3(0,0,0);
          r7.xyz = r1.xyz;
          r3.w = 0;
          r4.w = 0;
          r6.w = r1.z;
          r8.xyz = r4.xyz;
          r7.w = -1;
          while (true) {
            r8.w = cmp((int)r4.w >= (int)r1.w);
            if (r8.w != 0) break;
            r8.w = g_ConvertedDepthTexture.SampleLevel(SS_ClampPoint_s, r8.xy, 0).x;
            r9.x = r8.z + -r8.w;
            r9.y = -g_rayTraceParam.y * r6.w + r8.w;
            r9.z = cmp(0 >= r9.x);
            r9.y = cmp(r9.y < 0);
            r9.y = r9.y ? r9.z : 0;
            r9.y = r9.y ? r7.w : 0;
            if (r9.y != 0) {
              r10.xyz = r8.xyz;
              r11.xyz = r7.xyz;
              r5.w = r8.w;
              r9.y = 0;
              while (true) {
                r9.z = cmp((int)r9.y >= (int)r3.z);
                if (r9.z != 0) break;
                r12.xyz = r11.xyz + r10.xyz;
                r13.xyz = float3(0.5,0.5,0.5) * r12.xyz;
                r11.w = g_ConvertedDepthTexture.SampleLevel(SS_ClampPoint_s, r13.xy, 0).x;
                r9.z = r12.z * 0.5 + -r11.w;
                r9.z = cmp(r9.z < 0);
                r10.xyz = r9.zzz ? r13.xyz : r10.xyz;
                r13.w = r5.w;
                r11.xyzw = r9.zzzz ? r11.xyzw : r13.xyzw;
                r9.y = (int)r9.y + 1;
                r5.w = r11.w;
              }
              r8.xyz = r10.xyz;
              r7.xyz = r11.xyz;
              r9.yz = r8.xy * float2(2,-2) + float2(-1,1);
              r5.xy = viewTangent.xy * r9.yz;
              r12.x = dot(r5.xyzw, g_CurViewToPrevProj._m00_m10_m20_m30);
              r12.y = dot(r5.xyzw, g_CurViewToPrevProj._m01_m11_m21_m31);
              r5.x = dot(r5.xyzw, g_CurViewToPrevProj._m03_m13_m23_m33);
			  
              r5.xy = r12.xy / r5.xx;
              r6.xyz = g_PrevFrameTexture.SampleLevel(SS_ClampLinear_s, r5.xy, 0).xyz;
              r5.xy = float2(0.5,0.5) + -r5.xy;
              r5.xy = r5.xy + r5.xy;
              r9.yz = r5.xy * r5.xy;
              r9.yz = min(float2(1,1), r9.yz);
              r9.yz = float2(1,1) + -r9.yz;
              r9.y = r9.y * r9.z;
              r9.z = dot(r5.xy, r5.xy);
              r9.z = rsqrt(r9.z);
              r5.xy = r9.zz * r5.xy;
              r5.x = saturate(dot(-r5.xy, r3.xy));
              r5.x = r5.x * -2 + 4;
              r5.x = r9.y * r5.x;
              r5.x = min(1, r5.x);
              r5.x = r5.x * r5.x;
              r3.w = min(r5.x, r0.x);
              r4.w = r1.w;
              r7.w = -1;
            } else {
              r7.w = cmp(0 < r9.x);
              r4.w = (int)r4.w + 1;
              r9.xyz = r0.yzw * rayTraceStepScaleMinMax.xxx + r8.xyz;
              r7.xyz = r8.xyz;
              r6.w = r8.w;
              r8.xyz = r9.xyz;
            }
          }
          r0.xyz = r6.xyz * r3.www;
          o0.xyz = sceneMultiplyer * r0.xyz;
          o0.w = r3.w;
		  // Disable the SSR
		  o0.xyz = 0;
		  // Maintain some ambience
		  o0.w = 0.35;
        }
      } else {
        o0.xyzw = r2.xyzw;
      }
    } else {
      o0.xyzw = r2.xyzw;
    }
  }
  
  //o0 = 0;
  
  return;
}
