// gunner PS2

cbuffer _Globals : register(b0)
{

  struct
  {
    float4 vPlane;
    float4 vSettings;
  } g_ClipPlane : packoffset(c0);

  float4x4 g_mCloudsShadowsSpace : packoffset(c2);
  float4 g_vCloudsShadowDesc : packoffset(c6);
  float4 g_vKSettings : packoffset(c7);
  float4x4 g_mPrevObjViewProj : packoffset(c8);
  float4 specColor : packoffset(c12);
  float4 ControlData : packoffset(c13);
  float4 difColor : packoffset(c14);
  float4 ambient : packoffset(c15);
  float4 g_vDefLightDir : packoffset(c16);
  float4 g_vDefLightColor : packoffset(c17);
  float4 g_vDefSpecColor : packoffset(c18);
  // uint CS_FRONT : packoffset(c19) = {  Unknown bad code for initializer (needs manual fix):
  //      = 0x00000000 
    // uint CS_RIGHT : packoffset(c19) = {    Unknown bad code for initializer (needs manual fix):
    //      = 0x00000001 
      // uint CS_BACK : packoffset(c19) = {      Unknown bad code for initializer (needs manual fix):
      //      = 0x00000002 
        // uint CS_LEFT : packoffset(c19) = {        Unknown bad code for initializer (needs manual fix):
        //      = 0x00000003 
          // uint CS_TOP : packoffset(c20) = {          Unknown bad code for initializer (needs manual fix):
          //      = 0x00000004 
            // uint CS_BOTTOM : packoffset(c20) = {            Unknown bad code for initializer (needs manual fix):
            //      = 0x00000005 
  float4 g_vAmbientSettings : packoffset(c21);

  struct
  {
    float4 vDesc;
    float4 vFogLayerPlane;
    float4 vFogLayerColor;
    float4 vFogLayerSettings;
    float4 vFogColor;
    float4 vFogDistance;
  } g_FogDesc : packoffset(c22);

  float4 g_vScreenDepthRect : packoffset(c28);
  float4x4 g_mViewProj : packoffset(c29);
  float4x4 g_mView : packoffset(c33);
  float4 g_vCamPos : packoffset(c37);
  float4 g_vSkyColor : packoffset(c38);
  float4 g_vFogK : packoffset(c39);

  struct
  {
    float4x4 mLightSpaceInverse;
    float4x4 mLightSpace;
    float4 vShadowBias;
    float4 vBiasDir;
    float4 vSmoothOffs;
    float4 vShadowsDesc;
    float4 avCPlane[8];
    float4 avCascadeZ[2];
    float4 avUVTransform[8];
    float4 avZTransformZF[8];
  } g_ShadSettings : packoffset(c40);

}

SamplerState AlphaSampler_s : register(s0);
SamplerState DiffuseSampler_s : register(s1);
Texture2D<float4> DiffuseSampler : register(t0);
Texture2D<float4> AlphaSampler : register(t1);


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


  uint CS_FRONT = 0x00000000; 
  uint CS_RIGHT = 0x00000001;
  uint CS_BACK  =  0x00000002;
  uint CS_LEFT  = 0x00000003;
  uint CS_TOP  =  0x00000004; 
  uint CS_BOTTOM  =  0x00000005;


void main( 
  float4 v0 : SV_Position0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD1,
  float4 v3 : TEXCOORD2,
  float4 v4 : TEXCOORD3,
  float4 v5 : TEXCOORD4,
  float4 v6 : TEXCOORD5,
  float4 v7 : TEXCOORD6,
  float4 v8 : TEXCOORD7,
  float v9 : SV_ClipDistance0,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1,
  out float4 o2 : SV_Target2,
  out float4 o7 : SV_Target7)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

              r0.y = DiffuseSampler.Sample(DiffuseSampler_s, v1.xy).w;
              r0.x = 0.5;
              r0.x = AlphaSampler.Sample(AlphaSampler_s, r0.xy).z;
              r0.y = cmp(r0.x < 0.5);
              if (r0.y != 0) {
                if (-1 != 0) discard;
              }
              r0.y = dot(v8.xyz, v8.xyz);
              r0.y = rsqrt(r0.y);
              r0.yzw = v8.xyz * r0.yyy;
              o0.xyz = r0.yzw * float3(0.5,0.5,0.5) + float3(0.5,0.5,0.5);
              o0.w = 0.5 * r0.x;
              r0.x = cmp(g_vKSettings.x < 0.5);
              if (r0.x != 0) {
                r0.xy = float2(0,0);
              } else {
                r1.x = v3.w;
                r1.y = v4.w;
                r1.z = v5.w;
                r1.w = 1;
                r2.x = dot(r1.xyzw, g_mViewProj._m00_m10_m20_m30);
                r2.y = dot(r1.xyzw, g_mViewProj._m01_m11_m21_m31);
                r0.w = dot(r1.xyzw, g_mViewProj._m03_m13_m23_m33);
                r2.xy = r2.xy / r0.ww;
                r3.x = dot(r1.xyzw, g_mPrevObjViewProj._m00_m10_m20_m30);
                r3.y = dot(r1.xyzw, g_mPrevObjViewProj._m01_m11_m21_m31);
                r0.w = dot(r1.xyzw, g_mPrevObjViewProj._m03_m13_m23_m33);
                r1.xy = r3.xy / r0.ww;
                r0.xz = r2.xy + -r1.xy;
                r0.y = g_vKSettings.y * -r0.z;
                r0.z = dot(r0.xy, r0.xy);
                r0.z = sqrt(r0.z);
                r0.w = cmp(2 < r0.z);
                if (r0.w != 0) {
                  r0.z = 2 / r0.z;
                  r0.xy = r0.xy * r0.zz;
                }
              }
              o1.x = v8.w;
              o1.yzw = float3(0,0,0);
              o2.xy = r0.xy;
              o2.zw = float2(0,0);
			  o7 = float4(1,1,1,1);
              return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HLSL errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\jeux\IL-2 Sturmovik Battle of Stalingrad\bin\game\ShaderCache\5c567a70502bffb4-ps_replace.txt(23,40-46): error X3004: undeclared identifier 'Unknown'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
