// More UI - Fog Effect

cbuffer WorldBuffer : register(b0)
{

  struct
  {
    row_major float4x4 ViewProject;

    struct
    {
      row_major float4x4 World;
      row_major float4x4 WorldViewProject;
    } PerInstance[256];

  } WorldParameters : packoffset(c0);

}

cbuffer SceneBuffer : register(b2)
{
  row_major float4x4 View : packoffset(c0);
  row_major float4x4 ScreenMatrix : packoffset(c4);
  float2 DepthExportScale : packoffset(c8);
  float2 __padding0 : packoffset(c8.z);
  float4 FogParams : packoffset(c9);
  float3 __CameraPosition : packoffset(c10);
  float __padding12 : packoffset(c10.w);
  float3 CameraDirection : packoffset(c11);
  float __padding9 : packoffset(c11.w);
  float3 DepthFactors : packoffset(c12);
  float __padding10 : packoffset(c12.w);
  float3 ShadowDepthBiasAndLightType : packoffset(c13);
  float __padding11 : packoffset(c13.w);
  float4 SubframeViewport : packoffset(c14);
  row_major float3x4 DepthToWorld : packoffset(c15);
  float4 DepthToView : packoffset(c18);
  float4 OneOverDepthToView : packoffset(c19);
  float4 DepthToW : packoffset(c20);
  float4 ClipPlane : packoffset(c21);
  float2 ViewportDepthScaleOffset : packoffset(c22);
  float2 __padding1 : packoffset(c22.z);
  float2 ColorDOFDepthScaleOffset : packoffset(c23);
  float2 __padding2 : packoffset(c23.z);
  float4 TimeVector : packoffset(c24);
  float4 FogParams2 : packoffset(c25);
  float4 FogParams3 : packoffset(c26);
  float3 GlobalAmbient : packoffset(c27);
  float __padding8 : packoffset(c27.w);
  float4 GlobalParams[16] : packoffset(c28);
  float4 ViewToFogH : packoffset(c44);
  float4 ScreenExtents : packoffset(c45);
  float2 ScreenResolution : packoffset(c46);
  float2 __padding3 : packoffset(c46.z);
  float4 PSSMToMap1Lin : packoffset(c47);
  float4 PSSMToMap1Const : packoffset(c48);
  float4 PSSMToMap2Lin : packoffset(c49);
  float4 PSSMToMap2Const : packoffset(c50);
  float4 PSSMToMap3Lin : packoffset(c51);
  float4 PSSMToMap3Const : packoffset(c52);
  float4 PSSMDistances : packoffset(c53);
  row_major float4x4 WorldToPSSM0 : packoffset(c54);
  row_major float4x4 PrevViewProject : packoffset(c58);
  row_major float4x4 PrevWorld : packoffset(c62);
  row_major float4x4 ViewT : packoffset(c66);
  float4 PSSMExtents : packoffset(c70);
  float4 ShadowAtlasResolution : packoffset(c71);
  float4 UnitRimData[3] : packoffset(c72);
  float3 __CameraPositionForCorrection : packoffset(c75);
  float __padding7 : packoffset(c75.w);
  row_major float4x4 CameraViewProject : packoffset(c76);
  float4 BackBufferResolution : packoffset(c80);
  row_major float4x4 InverseProjection : packoffset(c81);
  float4 StereoOffset : packoffset(c85);
  row_major float4x4 Projection : packoffset(c86);
  row_major float4x4 ViewInv : packoffset(c90);
  float4 ColorSSAO : packoffset(c94);
  float4 GlobalFogColor : packoffset(c95);
  float4 VolumetricLightGlobalParams : packoffset(c96);
  float4 SnowParams01 : packoffset(c97);
  float4 SnowParams02 : packoffset(c98);
  float4 SnowParams03 : packoffset(c99);
  int SSREnabled : packoffset(c100);
  int __padding4 : packoffset(c100.y);
  int __padding5 : packoffset(c100.z);
  int __padding6 : packoffset(c100.w);
}

cbuffer StreamDeclBuffer : register(b3)
{
  float4 NormalScaleOffset : packoffset(c0);
  float4 TexcoordScales : packoffset(c1);
}



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


void main( 
  float4 v0 : COLOR0,
  float4 v1 : TEXCOORD0,
  float3 v2 : POSITION0,
  uint v3 : SV_InstanceID0,
  uint v4 : SV_VertexID0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : COLOR0,
  out float4 o2 : TEXCOORD0)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.x = (uint)v3.x << 3;
  r1.xyzw = WorldParameters.PerInstance[r0.x/4].World._m10_m11_m12_m13 * v2.yyyy;
  r1.xyzw = v2.xxxx * WorldParameters.PerInstance[r0.x/4].World._m00_m01_m02_m03 + r1.xyzw;
  r1.xyzw = v2.zzzz * WorldParameters.PerInstance[r0.x/4].World._m20_m21_m22_m23 + r1.xyzw;
  r0.xyzw = WorldParameters.PerInstance[r0.x/4].World._m30_m31_m32_m33 + r1.xyzw;
  r1.xyzw = ScreenMatrix._m10_m11_m12_m13 * r0.yyyy;
  r1.xyzw = r0.xxxx * ScreenMatrix._m00_m01_m02_m03 + r1.xyzw;
  r1.xyzw = r0.zzzz * ScreenMatrix._m20_m21_m22_m23 + r1.xyzw;
  r0.xyzw = r0.wwww * ScreenMatrix._m30_m31_m32_m33 + r1.xyzw;
  o0.xy = r0.xy * r0.ww;
  o0.zw = r0.zw;
  o1.xyzw = v0.zyxw;
  o2.xy = TexcoordScales.xx * v1.xy;
  o2.zw = float2(0,0);
  
   // Remove correction
  float4 stereo = StereoParams.Load(0);
  o0.x -= stereo.x * (o0.w - stereo.y);
  
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.17672
//
//   using 3Dmigoto v1.2.27 on Thu Feb 04 20:29:40 2016
//
//
// Buffer Definitions: 
//
// cbuffer WorldBuffer
// {
//
//   struct WorldStruct
//   {
//       
//       row_major float4x4 ViewProject;// Offset:    0
//       
//       struct WorldStruct_PerInstanceData
//       {
//           
//           row_major float4x4 World;  // Offset:   64
//           row_major float4x4 WorldViewProject;// Offset:  128
//
//       } PerInstance[256];            // Offset:   64
//
//   } WorldParameters;                 // Offset:    0 Size: 32832
//
// }
//
// cbuffer SceneBuffer
// {
//
//   row_major float4x4 View;           // Offset:    0 Size:    64 [unused]
//   row_major float4x4 ScreenMatrix;   // Offset:   64 Size:    64
//   float2 DepthExportScale;           // Offset:  128 Size:     8 [unused]
//   float2 __padding0;                 // Offset:  136 Size:     8 [unused]
//   float4 FogParams;                  // Offset:  144 Size:    16 [unused]
//   float3 __CameraPosition;           // Offset:  160 Size:    12 [unused]
//   float __padding12;                 // Offset:  172 Size:     4 [unused]
//   float3 CameraDirection;            // Offset:  176 Size:    12 [unused]
//   float __padding9;                  // Offset:  188 Size:     4 [unused]
//   float3 DepthFactors;               // Offset:  192 Size:    12 [unused]
//   float __padding10;                 // Offset:  204 Size:     4 [unused]
//   float3 ShadowDepthBiasAndLightType;// Offset:  208 Size:    12 [unused]
//   float __padding11;                 // Offset:  220 Size:     4 [unused]
//   float4 SubframeViewport;           // Offset:  224 Size:    16 [unused]
//   row_major float3x4 DepthToWorld;   // Offset:  240 Size:    48 [unused]
//   float4 DepthToView;                // Offset:  288 Size:    16 [unused]
//   float4 OneOverDepthToView;         // Offset:  304 Size:    16 [unused]
//   float4 DepthToW;                   // Offset:  320 Size:    16 [unused]
//   float4 ClipPlane;                  // Offset:  336 Size:    16 [unused]
//   float2 ViewportDepthScaleOffset;   // Offset:  352 Size:     8 [unused]
//   float2 __padding1;                 // Offset:  360 Size:     8 [unused]
//   float2 ColorDOFDepthScaleOffset;   // Offset:  368 Size:     8 [unused]
//   float2 __padding2;                 // Offset:  376 Size:     8 [unused]
//   float4 TimeVector;                 // Offset:  384 Size:    16 [unused]
//   float4 FogParams2;                 // Offset:  400 Size:    16 [unused]
//   float4 FogParams3;                 // Offset:  416 Size:    16 [unused]
//   float3 GlobalAmbient;              // Offset:  432 Size:    12 [unused]
//   float __padding8;                  // Offset:  444 Size:     4 [unused]
//   float4 GlobalParams[16];           // Offset:  448 Size:   256 [unused]
//   float4 ViewToFogH;                 // Offset:  704 Size:    16 [unused]
//   float4 ScreenExtents;              // Offset:  720 Size:    16 [unused]
//   float2 ScreenResolution;           // Offset:  736 Size:     8 [unused]
//   float2 __padding3;                 // Offset:  744 Size:     8 [unused]
//   float4 PSSMToMap1Lin;              // Offset:  752 Size:    16 [unused]
//   float4 PSSMToMap1Const;            // Offset:  768 Size:    16 [unused]
//   float4 PSSMToMap2Lin;              // Offset:  784 Size:    16 [unused]
//   float4 PSSMToMap2Const;            // Offset:  800 Size:    16 [unused]
//   float4 PSSMToMap3Lin;              // Offset:  816 Size:    16 [unused]
//   float4 PSSMToMap3Const;            // Offset:  832 Size:    16 [unused]
//   float4 PSSMDistances;              // Offset:  848 Size:    16 [unused]
//   row_major float4x4 WorldToPSSM0;   // Offset:  864 Size:    64 [unused]
//   row_major float4x4 PrevViewProject;// Offset:  928 Size:    64 [unused]
//   row_major float4x4 PrevWorld;      // Offset:  992 Size:    64 [unused]
//   row_major float4x4 ViewT;          // Offset: 1056 Size:    64 [unused]
//   float4 PSSMExtents;                // Offset: 1120 Size:    16 [unused]
//   float4 ShadowAtlasResolution;      // Offset: 1136 Size:    16 [unused]
//   float4 UnitRimData[3];             // Offset: 1152 Size:    48 [unused]
//   float3 __CameraPositionForCorrection;// Offset: 1200 Size:    12 [unused]
//   float __padding7;                  // Offset: 1212 Size:     4 [unused]
//   row_major float4x4 CameraViewProject;// Offset: 1216 Size:    64 [unused]
//   float4 BackBufferResolution;       // Offset: 1280 Size:    16 [unused]
//   row_major float4x4 InverseProjection;// Offset: 1296 Size:    64 [unused]
//   float4 StereoOffset;               // Offset: 1360 Size:    16 [unused]
//   row_major float4x4 Projection;     // Offset: 1376 Size:    64 [unused]
//   row_major float4x4 ViewInv;        // Offset: 1440 Size:    64 [unused]
//   float4 ColorSSAO;                  // Offset: 1504 Size:    16 [unused]
//   float4 GlobalFogColor;             // Offset: 1520 Size:    16 [unused]
//   float4 VolumetricLightGlobalParams;// Offset: 1536 Size:    16 [unused]
//   float4 SnowParams01;               // Offset: 1552 Size:    16 [unused]
//   float4 SnowParams02;               // Offset: 1568 Size:    16 [unused]
//   float4 SnowParams03;               // Offset: 1584 Size:    16 [unused]
//   int SSREnabled;                    // Offset: 1600 Size:     4 [unused]
//   int __padding4;                    // Offset: 1604 Size:     4 [unused]
//   int __padding5;                    // Offset: 1608 Size:     4 [unused]
//   int __padding6;                    // Offset: 1612 Size:     4 [unused]
//
// }
//
// cbuffer StreamDeclBuffer
// {
//
//   float4 NormalScaleOffset;          // Offset:    0 Size:    16 [unused]
//   float4 TexcoordScales;             // Offset:   16 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// WorldBuffer                       cbuffer      NA          NA    0        1
// SceneBuffer                       cbuffer      NA          NA    2        1
// StreamDeclBuffer                  cbuffer      NA          NA    3        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// COLOR                    0   xyzw        0     NONE   float   xyzw
// TEXCOORD                 0   xyzw        1     NONE   float   xy  
// POSITION                 0   xyz         2     NONE   float   xyz 
// SV_InstanceID            0   x           3   INSTID    uint   x   
// SV_VertexID              0   x           4   VERTID    uint       
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xyzw
// COLOR                    0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 0   xyzw        2     NONE   float   xyzw
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[2048], dynamicIndexed
dcl_constantbuffer cb2[8], immediateIndexed
dcl_constantbuffer cb3[2], immediateIndexed
dcl_input v0.xyzw
dcl_input v1.xy
dcl_input v2.xyz
dcl_input_sgv v3.x, instance_id
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
dcl_output o2.xyzw
dcl_temps 2
ishl r0.x, v3.x, l(3)
mul r1.xyzw, v2.yyyy, cb0[r0.x + 5].xyzw
mad r1.xyzw, v2.xxxx, cb0[r0.x + 4].xyzw, r1.xyzw
mad r1.xyzw, v2.zzzz, cb0[r0.x + 6].xyzw, r1.xyzw
add r0.xyzw, r1.xyzw, cb0[r0.x + 7].xyzw
mul r1.xyzw, r0.yyyy, cb2[5].xyzw
mad r1.xyzw, r0.xxxx, cb2[4].xyzw, r1.xyzw
mad r1.xyzw, r0.zzzz, cb2[6].xyzw, r1.xyzw
mad r0.xyzw, r0.wwww, cb2[7].xyzw, r1.xyzw
mul o0.xy, r0.wwww, r0.xyxx
mov o0.zw, r0.zzzw
mov o1.xyzw, v0.zyxw
mul o2.xy, v1.xyxx, cb3[1].xxxx
mov o2.zw, l(0,0,0,0)
ret 
// Approximately 15 instruction slots used

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