// Decals

cbuffer PER_BATCH : register(b0)
{
  float4 g_LightDiffuse : packoffset(c0);
  float4 g_WorldViewPos : packoffset(c1);
  row_major float4x4 g_mLightProj : packoffset(c2);
  float4 g_ScreenScale : packoffset(c6);
  float4 vWBasisX : packoffset(c7);
  float4 vWBasisY : packoffset(c8);
  float4 vWBasisZ : packoffset(c9);
}

SamplerState _tex0_s : register(s0);
SamplerState _tex2_s : register(s2);
Texture2D<float4> _tex0 : register(t0);
Texture2D<float4> _tex2 : register(t2);


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


void main( 
  float4 v0 : SV_POSITION0,
  out float4 o0 : SV_Target0,
  
    row_major matrix vp : TEXCOORD0,
  row_major matrix ivp : TEXCOORD4)
  
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v0.xy * g_ScreenScale.xy + g_ScreenScale.zw;
  r0.x = _tex0.Sample(_tex0_s, r0.xy).x;
  r0.yzw = vWBasisX.xyz * v0.xxx + vWBasisZ.xyz;
  r0.yzw = vWBasisY.xyz * v0.yyy + r0.yzw;
  r0.xyz = r0.yzw * r0.xxx + g_WorldViewPos.xyz;
  r0.w = 1;
  
  float4 stereo = StereoParams.Load(0);
  float4 tmp = mul(vp, r0);
  tmp.x -= stereo.x * (tmp.w - stereo.y);
  r0 = mul(ivp, tmp);
  
  r1.x = dot(g_mLightProj._m00_m01_m02_m03, r0.xyzw);
  r1.y = dot(g_mLightProj._m10_m11_m12_m13, r0.xyzw);
  r1.z = dot(g_mLightProj._m20_m21_m22_m23, r0.xyzw);
  r0.x = dot(g_mLightProj._m30_m31_m32_m33, r0.xyzw);
  r0.xyz = r1.xyz / r0.xxx;
  r1.xyzw = r0.xyxy * float4(1,1,-1,-1) + float4(0,0,1,1);
  r1.xyzw = cmp(r1.xyzw < float4(0,0,0,0));
  r1.xy = (int2)r1.zw | (int2)r1.xy;
  r0.w = (int)r1.y | (int)r1.x;
  if (r0.w != 0) discard;
  r1.xy = cmp(r0.zz < float2(0,0.200000003));
  if (r1.x != 0) discard;
  r0.w = r1.y ? 5 : 1;
  r0.z = -0.200000003 + r0.z;
  r1.xyzw = _tex2.Sample(_tex2_s, r0.xy).xyzw;
  r0.x = r0.z * r0.w;
  r0.x = -r0.x * r0.x + 1;
  r0.x = max(0, r0.x);
  r0.x = g_LightDiffuse.w * r0.x;
  o0.w = r1.w * r0.x;
  r0.xyz = g_LightDiffuse.xyz * r1.xyz;
  o0.xyz = sqrt(r0.xyz);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.2.34 on Fri Apr 29 16:17:19 2016
//
//
// Buffer Definitions: 
//
// cbuffer PER_BATCH
// {
//
//   float4 g_LightDiffuse;             // Offset:    0 Size:    16
//   float4 g_WorldViewPos;             // Offset:   16 Size:    16
//   row_major float4x4 g_mLightProj;   // Offset:   32 Size:    64
//   float4 g_ScreenScale;              // Offset:   96 Size:    16
//   float4 vWBasisX;                   // Offset:  112 Size:    16
//   float4 vWBasisY;                   // Offset:  128 Size:    16
//   float4 vWBasisZ;                   // Offset:  144 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// _tex0                             sampler      NA          NA    0        1
// _tex2                             sampler      NA          NA    2        1
// _tex0                             texture  float4          2d    0        1
// _tex2                             texture  float4          2d    2        1
// PER_BATCH                         cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   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_constantbuffer cb0[10], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s2, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t2
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 2
mad r0.xy, v0.xyxx, cb0[6].xyxx, cb0[6].zwzz
sample_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t0.xyzw, s0
mad r0.yzw, cb0[7].xxyz, v0.xxxx, cb0[9].xxyz
mad r0.yzw, cb0[8].xxyz, v0.yyyy, r0.yyzw
mad r0.xyz, r0.yzwy, r0.xxxx, cb0[1].xyzx
mov r0.w, l(1.000000)
dp4 r1.x, cb0[2].xyzw, r0.xyzw
dp4 r1.y, cb0[3].xyzw, r0.xyzw
dp4 r1.z, cb0[4].xyzw, r0.xyzw
dp4 r0.x, cb0[5].xyzw, r0.xyzw
div r0.xyz, r1.xyzx, r0.xxxx
mad r1.xyzw, r0.xyxy, l(1.000000, 1.000000, -1.000000, -1.000000), l(0.000000, 0.000000, 1.000000, 1.000000)
lt r1.xyzw, r1.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
or r1.xy, r1.zwzz, r1.xyxx
or r0.w, r1.y, r1.x
discard_nz r0.w
lt r1.xy, r0.zzzz, l(0.000000, 0.200000, 0.000000, 0.000000)
discard_nz r1.x
movc r0.w, r1.y, l(5.000000), l(1.000000)
add r0.z, r0.z, l(-0.200000)
sample_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.xyxx, t2.xyzw, s2
mul r0.x, r0.w, r0.z
mad r0.x, -r0.x, r0.x, l(1.000000)
max r0.x, r0.x, l(0.000000)
mul r0.x, r0.x, cb0[0].w
mul o0.w, r0.x, r1.w
mul r0.xyz, r1.xyzx, cb0[0].xyzx
sqrt o0.xyz, r0.xyzx
ret 
// Approximately 29 instruction slots used

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