//shadows
// ---- Created with 3Dmigoto v0.6.164 on Fri Oct 24 01:37:23 2025
Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

cbuffer cb3 : register(b3)
{
  float4 cb3[3];
}

cbuffer cb2 : register(b2)
{
  float4 cb2[16];
}

cbuffer cb1 : register(b1)
{
  float4 cb1[1];
}

cbuffer cb0 : register(b0)
{
  float4 cb0[115];
}




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


void main(
  float4 v0 : SV_POSITION0,
  nointerpolation uint v1 : CUSTOM_INSTANCE_ID0,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD1,
  float4 v4 : TEXCOORD2,
  float3 v5 : TEXCOORD3,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 s = StereoParams.Load(0);
  float4 testeo = IniParams.Load(int2(90,0));
  float fov = rsqrt(cb0[61].x * cb0[61].x + cb0[62].x * cb0[62].x + cb0[63].x * cb0[63].x);
  float fov1 = sqrt(cb0[61].x * cb0[61].x + cb0[62].x * cb0[62].x + cb0[63].x * cb0[63].x);
  float fov2 = cb0[61].x * cb0[61].x + cb0[62].x * cb0[62].x + cb0[63].x * cb0[63].x;



  r0.xyz = cb0[62].xyw * v2.yyy;
  r0.xyz = cb0[61].xyw * v2.xxx + r0.xyz;
  r0.xyz = cb0[63].xyw * v2.zzz + r0.xyz;
  r0.xyz = cb0[64].xyw + r0.xyz;
  r0.y = cb0[12].x * r0.y;
  r1.xzw = float3(0.5,0.5,0.5) * r0.xzy;
  r0.xy = r1.xw + r1.zz;
  
r0.x += s.x * (r0.z - s.y) * 0.5;
  
  r0.xy = r0.xy / r0.zz;
  r0.xyzw = t0.Sample(s0_s, r0.xy).xyzw;
  r0.x = cb0[14].z * r0.x + cb0[14].w;
  r0.x = 1 / r0.x;
  r0.y = (int)v1.x + asint(cb1[0].x);
  r0.y = (uint)r0.y << 3;
  r1.xyz = cb2[r0.y+5].xyz * cb0[59].yyy;
  r1.xyz = cb2[r0.y+4].xyz * cb0[59].xxx + r1.xyz;
  r1.xyz = cb2[r0.y+6].xyz * cb0[59].zzz + r1.xyz;
  r1.xyz = cb2[r0.y+7].xyz * cb0[59].www + r1.xyz;
  r2.xyz = cb2[r0.y+1].xyz * r1.yyy;
  r1.xyw = cb2[r0.y+0].xyz * r1.xxx + r2.xyz;
  r1.xyz = cb2[r0.y+2].xyz * r1.zzz + r1.xyw;
  r0.z = dot(v5.xyz, -r1.xyz);


float3 camRight = float3(cb0[57].x, cb0[58].x, cb0[59].x);
float3 flatRight = normalize(float3(camRight.x, 0, camRight.z));



v5.x += s.x * s.y * flatRight.x * fov;
v5.y += 0;  // Mantener en el suelo
v5.z += s.x * s.y * flatRight.z * fov;


//v5.x +=  s.x * s.y * cb0[57].x* fov;
//v5.y +=  s.x * s.y * cb0[58].x* fov;
//v5.z +=  s.x * s.y * cb0[59].x* fov;  


  r1.xyz = v5.xyz / r0.zzz;

  r0.xzw = r0.xxx * r1.xyz + cb0[11].xyz;

//r0.x += s.x * s.y * cb0[57].x*fov;
//r0.z += s.x * s.y * cb0[58].x*fov; 
//r0.w += s.x * s.y * cb0[59].x*fov;

r0.x += s.x * s.y * flatRight.x * fov;
r0.z += 0;  // Mantener en el suelo;
r0.w += s.x * s.y * flatRight.z * fov;


  r1.xyz = -cb2[r0.y+3].xyz + r0.xzw;
  r0.xzw = cb3[2].yzw + -r0.xzw;
  r0.x = dot(r0.xzw, r0.xzw);
  r0.z = dot(cb2[r0.y+0].xyz, cb2[r0.y+0].xyz);
  r0.w = max(1.17549435e-38, r0.z);
  r0.xz = sqrt(r0.xz);
  r2.x = 1 / r0.z;
  r0.z = rsqrt(r0.w);
  r3.xyz = cb2[r0.y+0].xyz * r0.zzz;
  r0.z = dot(r1.xyz, r3.xyz);
  r4.xyz = r3.xyz * r0.zzz;
  r0.z = dot(r3.xyz, r3.xyz);
  r4.xyz = r4.xyz / r0.zzz;
  r3.x = dot(r4.xyz, r3.xyz);
  r0.z = dot(cb2[r0.y+2].xyz, cb2[r0.y+2].xyz);
  r0.w = max(1.17549435e-38, r0.z);
  r0.z = sqrt(r0.z);
  r2.y = 1 / r0.z;
  r0.z = rsqrt(r0.w);
  r0.yzw = cb2[r0.y+2].xyz * r0.zzz;
  r1.x = dot(r1.xyz, r0.yzw);
  r1.xyz = r1.xxx * r0.yzw;
  r1.w = dot(r0.yzw, r0.yzw);
  r1.xyz = r1.xyz / r1.www;
  r3.y = dot(r1.xyz, r0.yzw);
  r0.yz = r3.xy * r2.xy + float2(0.5,0.5);
  r1.xy = frac(r0.yz);
  r2.x = -0;
  r2.y = -cb0[114].x;
  r1.zw = cb3[2].yz + r2.xy;
  r1.zw = cb3[2].yz + -r1.zw;
  r0.w = dot(r1.zw, r1.zw);
  r0.w = sqrt(r0.w);
  r0.w = 1 + r0.w;
  r0.x = cmp(r0.w >= r0.x);
  r0.xw = r0.xx ? r1.xy : 0;
  r1.xyzw = t1.Sample(s1_s, r0.xw).xyzw;
  r0.x = saturate(ceil(r1.x));
  r1.xy = cmp(r0.yz >= float2(0,0));
  r0.yz = cmp(float2(1,1) >= r0.yz);
  r0.yz = r0.yz ? float2(1,1) : 0;
  r1.xy = r1.xy ? float2(1,1) : 0;
  r0.yz = min(r1.xy, r0.yz);
  r0.y = min(r0.y, r0.z);
  r0.x = r0.y * r0.x;
  o0.w = 0.5 * r0.x;
  o0.xyz = float3(0,0,0);
  return;
}


