// Decals - dirty tracks in master sabertooth hunt (broken in 2D, still broken in 3D)
// ---- Created with 3Dmigoto v1.2.34 on Fri Mar 11 01:54:17 2016

cbuffer CViewportShaderParameterProvider : register(b0)
{
  float4x4 InvProjectionMatrix : packoffset(c0);
  float4x4 InvViewMatrix : packoffset(c4);
  float4x4 ProjectionMatrix : packoffset(c8);
  float4x4 ViewMatrix : packoffset(c12);
  float4x4 ViewProjectionMatrix : packoffset(c16);
  float4x4 ViewRotProjectionMatrix : packoffset(c20);
  float4x4 ViewRotProjectionMatrix_Previous : packoffset(c24);
  float4 AmbientSHR : packoffset(c28);
  float4 AmbientSHG : packoffset(c29);
  float4 AmbientSHB : packoffset(c30);
  float4 CameraDistances : packoffset(c31);
  float4 CameraNearPlaneSize : packoffset(c32);
  float4 DepthScale : packoffset(c33);
  float4 DepthTextureScaleOffset : packoffset(c34);
  float4 FogParams : packoffset(c35);
  float4 FogSHB : packoffset(c36);
  float4 FogSHG : packoffset(c37);
  float4 FogSHR : packoffset(c38);
  float4 HeightFogParams : packoffset(c39);
  float4 ViewportSize : packoffset(c40);
  float3 ViewPoint : packoffset(c41);
  float3 CameraPosition : packoffset(c42);
  float3 CameraPosition_Previous : packoffset(c43);
  float3 CameraPositionFractions : packoffset(c44);
  float3 CameraPositionFractions_Previous : packoffset(c45);
  float3 CameraRight : packoffset(c46);
  float3 CameraUp : packoffset(c47);
  float3 CameraDirection : packoffset(c48);
  float3 EnvironmentMapColorOffset : packoffset(c49);
  float3 EnvironmentMapColorScale : packoffset(c50);
  float3 AmbientOcclusionRanges : packoffset(c51);
  float3 DepthTextureRcpSize : packoffset(c52);
  float2 MotionVectorOffsets : packoffset(c53);
  float2 DepthRangeCompression : packoffset(c53.z);
  float ShadowProjDepthMinValue : packoffset(c54);
  float DistanceScale : packoffset(c54.y);
  float WorldSpaceZOffset : packoffset(c54.z);
  float WorldSpaceZOffset_Previous : packoffset(c54.w);
  float CameraFOVDeg : packoffset(c55);
  float EffectsEmissiveEVBias : packoffset(c55.y);
  float ShadowCSMLastSliceIndex : packoffset(c55.z);
  float UseNormalization : packoffset(c55.w);
  float FogUndergroundColorScale : packoffset(c56);
}

cbuffer Decal : register(b1)
{
  float4 DiffuseAndNormalTiling1 : packoffset(c0);
  float4 DiffuseColor1 : packoffset(c1);
  float4 MaterialPickingID : packoffset(c2);
  float4 ParallaxScale : packoffset(c3);
  float4 Settings : packoffset(c4);
  float2 AlphaTiling1 : packoffset(c5);
  float2 ParallaxHeightAndOffset : packoffset(c5.z);
  float2 SpecularTiling1 : packoffset(c6);
  bool AlbedoOnly : packoffset(c6.z);
  float DepthOffset : packoffset(c6.w);
  bool DisableAlbedo : packoffset(c7);
  bool TerrainDecal : packoffset(c7.y);
}

cbuffer CSceneTransformParameterProvider : register(b2)
{
  float4x4 WorldMatrix : packoffset(c0);
  float3 WorldPositionFractions : packoffset(c4);
}

cbuffer CSceneGeometry : register(b3)
{
  float4 GeometryPickingID : packoffset(c0);
  float4 MeshDecompression : packoffset(c1);
  float4 NormalizedXYBBox : packoffset(c2);
}

cbuffer CTerrainDecalLayerOffsetProvider : register(b4)
{
  float LayerOffset : packoffset(c0);
}



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


void main( 
  int4 v0 : position0,
  int2 v1 : texcoord0,
  float4 v2 : normal0,
  float4 v3 : color0,
  out float4 o0 : SV_Position0,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float2 o3 : TEXCOORD2)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyz = (int3)v0.xyz;
  r0.xyz = r0.xyz * MeshDecompression.yyy + MeshDecompression.xxx;
  r0.w = 1;
  r1.x = dot(r0.xyzw, WorldMatrix._m00_m10_m20_m30);
  r1.y = dot(r0.xyzw, WorldMatrix._m01_m11_m21_m31);
  r1.z = dot(r0.xyzw, WorldMatrix._m02_m12_m22_m32);

float4 stereo = StereoParams.Load(0);
float4 tmp = mul(float4(r1.xyz, 1), ViewProjectionMatrix);
tmp = float4(stereo.x * (tmp.w - stereo.y) * InvProjectionMatrix._m00, 0, 0, 0);
r1.xyz += mul(tmp, InvViewMatrix);

  r0.xyz = -CameraPosition.xyz + r1.xyz;
  r0.w = dot(-r0.xyz, -r0.xyz);
  r0.w = sqrt(r0.w);
  r1.w = 0.03125 * r0.w;
  r0.xyz = -r0.xyz / r0.www;
  r0.w = min(1, r1.w);
  r0.w = r0.w * DepthOffset + LayerOffset;
  r0.xyz = r0.www * r0.xyz + r1.xyz;
  o2.xyz = r1.xyz;
  r0.xyz = -CameraPosition.xyz + r0.xyz;
  r0.w = 1;
  o0.x = dot(r0.xyzw, ViewRotProjectionMatrix._m00_m10_m20_m30);
  o0.y = dot(r0.xyzw, ViewRotProjectionMatrix._m01_m11_m21_m31);
  o0.z = dot(r0.xyzw, ViewRotProjectionMatrix._m02_m12_m22_m32);
  o0.w = dot(r0.xyzw, ViewRotProjectionMatrix._m03_m13_m23_m33);

o0.x -= stereo.x * (o0.w - stereo.y);

  r0.xyz = v2.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r1.x = dot(r0.xyz, WorldMatrix._m00_m10_m20);
  r1.y = dot(r0.xyz, WorldMatrix._m01_m11_m21);
  r1.z = dot(r0.xyz, WorldMatrix._m02_m12_m22);
  r0.x = dot(r1.xyz, r1.xyz);
  r0.x = rsqrt(r0.x);
  o1.xyz = r1.xyz * r0.xxx;
  r0.xy = (int2)v1.xy;
  r0.xy = r0.xy * MeshDecompression.ww + MeshDecompression.zz;
  r0.xy = float2(-0.5,-0.5) + r0.xy;
  r0.z = 0.0174532924 * Settings.z;
  sincos(r0.z, r1.x, r2.x);
  r3.z = r1.x;
  r3.y = r2.x;
  r3.x = -r1.x;
  r1.y = dot(r0.xy, r3.xy);
  r1.x = dot(r0.xy, r3.yz);
  o3.xy = float2(0.5,0.5) + r1.xy;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.34 on Fri Mar 11 01:54:17 2016
//
//
// Buffer Definitions: 
//
// cbuffer CViewportShaderParameterProvider
// {
//
//   float4x4 InvProjectionMatrix;      // Offset:    0 Size:    64 [unused]
//   float4x4 InvViewMatrix;            // Offset:   64 Size:    64 [unused]
//   float4x4 ProjectionMatrix;         // Offset:  128 Size:    64 [unused]
//   float4x4 ViewMatrix;               // Offset:  192 Size:    64 [unused]
//   float4x4 ViewProjectionMatrix;     // Offset:  256 Size:    64 [unused]
//   float4x4 ViewRotProjectionMatrix;  // Offset:  320 Size:    64
//   float4x4 ViewRotProjectionMatrix_Previous;// Offset:  384 Size:    64 [unused]
//   float4 AmbientSHR;                 // Offset:  448 Size:    16 [unused]
//   float4 AmbientSHG;                 // Offset:  464 Size:    16 [unused]
//   float4 AmbientSHB;                 // Offset:  480 Size:    16 [unused]
//   float4 CameraDistances;            // Offset:  496 Size:    16 [unused]
//   float4 CameraNearPlaneSize;        // Offset:  512 Size:    16 [unused]
//   float4 DepthScale;                 // Offset:  528 Size:    16 [unused]
//   float4 DepthTextureScaleOffset;    // Offset:  544 Size:    16 [unused]
//   float4 FogParams;                  // Offset:  560 Size:    16 [unused]
//   float4 FogSHB;                     // Offset:  576 Size:    16 [unused]
//   float4 FogSHG;                     // Offset:  592 Size:    16 [unused]
//   float4 FogSHR;                     // Offset:  608 Size:    16 [unused]
//   float4 HeightFogParams;            // Offset:  624 Size:    16 [unused]
//   float4 ViewportSize;               // Offset:  640 Size:    16 [unused]
//   float3 ViewPoint;                  // Offset:  656 Size:    12 [unused]
//   float3 CameraPosition;             // Offset:  672 Size:    12
//   float3 CameraPosition_Previous;    // Offset:  688 Size:    12 [unused]
//   float3 CameraPositionFractions;    // Offset:  704 Size:    12 [unused]
//   float3 CameraPositionFractions_Previous;// Offset:  720 Size:    12 [unused]
//   float3 CameraRight;                // Offset:  736 Size:    12 [unused]
//   float3 CameraUp;                   // Offset:  752 Size:    12 [unused]
//   float3 CameraDirection;            // Offset:  768 Size:    12 [unused]
//   float3 EnvironmentMapColorOffset;  // Offset:  784 Size:    12 [unused]
//   float3 EnvironmentMapColorScale;   // Offset:  800 Size:    12 [unused]
//   float3 AmbientOcclusionRanges;     // Offset:  816 Size:    12 [unused]
//   float3 DepthTextureRcpSize;        // Offset:  832 Size:    12 [unused]
//   float2 MotionVectorOffsets;        // Offset:  848 Size:     8 [unused]
//   float2 DepthRangeCompression;      // Offset:  856 Size:     8 [unused]
//   float ShadowProjDepthMinValue;     // Offset:  864 Size:     4 [unused]
//   float DistanceScale;               // Offset:  868 Size:     4 [unused]
//   float WorldSpaceZOffset;           // Offset:  872 Size:     4 [unused]
//   float WorldSpaceZOffset_Previous;  // Offset:  876 Size:     4 [unused]
//   float CameraFOVDeg;                // Offset:  880 Size:     4 [unused]
//   float EffectsEmissiveEVBias;       // Offset:  884 Size:     4 [unused]
//   float ShadowCSMLastSliceIndex;     // Offset:  888 Size:     4 [unused]
//   float UseNormalization;            // Offset:  892 Size:     4 [unused]
//   float FogUndergroundColorScale;    // Offset:  896 Size:     4 [unused]
//
// }
//
// cbuffer Decal
// {
//
//   float4 DiffuseAndNormalTiling1;    // Offset:    0 Size:    16 [unused]
//   float4 DiffuseColor1;              // Offset:   16 Size:    16 [unused]
//   float4 MaterialPickingID;          // Offset:   32 Size:    16 [unused]
//   float4 ParallaxScale;              // Offset:   48 Size:    16 [unused]
//   float4 Settings;                   // Offset:   64 Size:    16
//   float2 AlphaTiling1;               // Offset:   80 Size:     8 [unused]
//   float2 ParallaxHeightAndOffset;    // Offset:   88 Size:     8 [unused]
//   float2 SpecularTiling1;            // Offset:   96 Size:     8 [unused]
//   bool AlbedoOnly;                   // Offset:  104 Size:     4 [unused]
//   float DepthOffset;                 // Offset:  108 Size:     4
//   bool DisableAlbedo;                // Offset:  112 Size:     4 [unused]
//   bool TerrainDecal;                 // Offset:  116 Size:     4 [unused]
//
// }
//
// cbuffer CSceneTransformParameterProvider
// {
//
//   float4x4 WorldMatrix;              // Offset:    0 Size:    64
//   float3 WorldPositionFractions;     // Offset:   64 Size:    12 [unused]
//
// }
//
// cbuffer CSceneGeometry
// {
//
//   float4 GeometryPickingID;          // Offset:    0 Size:    16 [unused]
//   float4 MeshDecompression;          // Offset:   16 Size:    16
//   float4 NormalizedXYBBox;           // Offset:   32 Size:    16 [unused]
//
// }
//
// cbuffer CTerrainDecalLayerOffsetProvider
// {
//
//   float LayerOffset;                 // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// CViewportShaderParameterProvider    cbuffer      NA          NA    0        1
// Decal                             cbuffer      NA          NA    1        1
// CSceneTransformParameterProvider    cbuffer      NA          NA    2        1
// CSceneGeometry                    cbuffer      NA          NA    3        1
// CTerrainDecalLayerOffsetProvider    cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// position                 0   xyzw        0     NONE     int   xyz 
// texcoord                 0   xy          1     NONE     int   xy  
// normal                   0   xyzw        2     NONE   float   xyz 
// color                    0   xyzw        3     NONE   float       
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xyzw
// TEXCOORD                 0   xyz         1     NONE   float   xyz 
// TEXCOORD                 1   xyz         2     NONE   float   xyz 
// TEXCOORD                 2   xy          3     NONE   float   xy  
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[43], immediateIndexed
dcl_constantbuffer cb1[7], immediateIndexed
dcl_constantbuffer cb2[3], immediateIndexed
dcl_constantbuffer cb3[2], immediateIndexed
dcl_constantbuffer cb4[1], immediateIndexed
dcl_input v0.xyz
dcl_input v1.xy
dcl_input v2.xyz
dcl_output_siv o0.xyzw, position
dcl_output o1.xyz
dcl_output o2.xyz
dcl_output o3.xy
dcl_temps 4
itof r0.xyz, v0.xyzx
mad r0.xyz, r0.xyzx, cb3[1].yyyy, cb3[1].xxxx
mov r0.w, l(1.000000)
dp4 r1.x, r0.xyzw, cb2[0].xyzw
dp4 r1.y, r0.xyzw, cb2[1].xyzw
dp4 r1.z, r0.xyzw, cb2[2].xyzw
add r0.xyz, r1.xyzx, -cb0[42].xyzx
dp3 r0.w, -r0.xyzx, -r0.xyzx
sqrt r0.w, r0.w
mul r1.w, r0.w, l(0.031250)
div r0.xyz, -r0.xyzx, r0.wwww
min r0.w, r1.w, l(1.000000)
mad r0.w, r0.w, cb1[6].w, cb4[0].x
mad r0.xyz, r0.wwww, r0.xyzx, r1.xyzx
mov o2.xyz, r1.xyzx
add r0.xyz, r0.xyzx, -cb0[42].xyzx
mov r0.w, l(1.000000)
dp4 o0.x, r0.xyzw, cb0[20].xyzw
dp4 o0.y, r0.xyzw, cb0[21].xyzw
dp4 o0.z, r0.xyzw, cb0[22].xyzw
dp4 o0.w, r0.xyzw, cb0[23].xyzw
mad r0.xyz, v2.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r1.x, r0.xyzx, cb2[0].xyzx
dp3 r1.y, r0.xyzx, cb2[1].xyzx
dp3 r1.z, r0.xyzx, cb2[2].xyzx
dp3 r0.x, r1.xyzx, r1.xyzx
rsq r0.x, r0.x
mul o1.xyz, r0.xxxx, r1.xyzx
itof r0.xy, v1.xyxx
mad r0.xy, r0.xyxx, cb3[1].wwww, cb3[1].zzzz
add r0.xy, r0.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
mul r0.z, cb1[4].z, l(0.0174532924)
sincos r1.x, r2.x, r0.z
mov r3.z, r1.x
mov r3.y, r2.x
mov r3.x, -r1.x
dp2 r1.y, r0.xyxx, r3.xyxx
dp2 r1.x, r0.xyxx, r3.yzyy
add o3.xy, r1.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
ret 
// Approximately 40 instruction slots used

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