//Decals PS 1
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);

Texture2D<float4> StereoParams : register(t125);
Texture1D<float4> IniParams : register(t120);

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(1.40129846e-045,1.40129846e-045,1,1);
  r1.xyzw = 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 = r0.zz < float2(0,0.200000003);
  if (r1.x != 0) discard;
  r0.w = r1.y ? 5 : 1;
  r0.z = -0.200000003 + r0.z;
  r0.x = _tex2.Sample(_tex2_s, r0.xy).w;
  r0.y = r0.z * r0.w;
  r0.y = -r0.y * r0.y + 1;
  r0.y = max(0, r0.y);
  r0.x = r0.y * r0.x;
  o0.w = g_LightDiffuse.w * r0.x;
  o0.xyz = float3(0,0,0);
  return;
}