//speculars 
// ---- Created with 3Dmigoto v0.6.164 on Sun Nov  2 17:10:39 2025
Texture2D<float4> t8 : register(t8);

Texture2D<float4> t7 : register(t7);

Texture2D<float4> t6 : register(t6);

Texture2D<float4> t5 : register(t5);

Texture2D<float4> t4 : register(t4);

Texture2D<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

TextureCube<float4> t0 : register(t0);

SamplerState s7_s : register(s7);

SamplerState s6_s : register(s6);

SamplerState s5_s : register(s5);

SamplerState s4_s : register(s4);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerComparisonState s1_s : register(s1);

SamplerState s0_s : register(s0);

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

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

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

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


cbuffer cb13 : register(b13)
{
  float4 cb13[70];
}



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


void main(
  float4 v0 : SV_POSITION0,
  uint v1 : CUSTOM_INSTANCE_ID0,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD1,
  float4 v4 : TEXCOORD2,
  float4 v5 : TEXCOORD3,
  float4 v6 : TEXCOORD4,
  float4 v7 : TEXCOORD5,
  float4 v8 : TEXCOORD6,
  float4 v9 : TEXCOORD7,
  float4 v10 : TEXCOORD8,
  float4 v11 : TEXCOORD9,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  // ===== 3DMIGOTO STEREO FIX =====
  float4 stereo = StereoParams.Load(0);
  //float4 params = IniParams.Load(int2(90,0));
  float fov = rsqrt(cb13[61].x * cb13[61].x + cb13[62].x * cb13[62].x + cb13[63].x * cb13[63].x);  
  
  // Normalizar la normal de la superficie
  float3 worldNormal = normalize(v3.xyz);
  
  // Factor basado en cuán vertical es la superficie
  // worldNormal.y cercano a 1 o -1 = superficie horizontal (suelo/techo)
  // worldNormal.y cercano a 0 = superficie vertical (pared)
  float verticalAmount = saturate(1.0 - abs(worldNormal.y));
  
  // Usar los vectores de la matriz de vista de cb13
  float3 viewRight = float3(cb13[57].x, cb13[58].x, cb13[59].x);
  float viewScale = length(viewRight);
  
  // Aplicar corrección al vector de vista con parámetro de profundidad
  float3 v7_corrected = v7.xyz;
  v7_corrected += stereo.x * viewScale * verticalAmount * viewRight * fov;
  // ===============================

  r0.xyz = float3(1,1,1) + -cb3[11].xyz;
  r1.xyzw = t6.Sample(s6_s, float2(4.29083853e+09,4.29083853e+09)).xyzw;
  r2.xyz = float3(1,1,1) + -r1.xyz;
  r0.xyz = -r0.xyz * r2.xyz + -r1.xyz;
  r0.xyz = float3(1,1,1) + r0.xyz;
  r0.xyz = cb3[12].xxx * r0.xyz + r1.xyz;
  r0.w = 1 / cb3[4].w;
  r1.xyz = cb3[4].yyy * v2.xyz;
  r2.xyzw = t5.Sample(s5_s, r1.xy).xyzw;
  r3.xyzw = t5.Sample(s5_s, r1.zy).xyzw;
  r1.xyzw = t5.Sample(s5_s, r1.xz).xyzw;
  r1.w = dot(v3.xyz, v3.xyz);
  r2.w = sqrt(r1.w);
  r1.w = rsqrt(r1.w);
  r4.xyz = v3.xyz * r1.www;
  r1.w = 1 / r2.w;
  r5.xyz = v3.xyz * r1.www;
  r6.xyz = max(float3(5.96046448e-08,5.96046448e-08,5.96046448e-08), abs(r5.xyz));
  r1.w = dot(r6.xyz, float3(1,1,1));
  r6.xyz = r6.xyz / r1.www;
  r1.xyz = r6.yyy * r1.xyz;
  r1.xyz = r3.xyz * r6.xxx + r1.xyz;
  r1.xyz = r2.xyz * r6.zzz + r1.xyz;
  r1.w = r1.y * 0.5 + r5.y;
  r1.xyz = r1.xyz * r5.xyz;
  r2.x = -cb3[4].z + r1.w;
  r0.w = saturate(r2.x * r0.w);
  r2.x = r0.w * -2 + 3;
  r0.w = r0.w * r0.w;
  r2.y = -r2.x * r0.w + 1;
  r0.w = r2.x * r0.w;
  r2.xzw = cb3[4].xxx * v2.xyz;
  r3.xyzw = t4.Sample(s4_s, r2.wz).xyzw;
  r7.xyzw = t4.Sample(s4_s, r2.xw).xyzw;
  r8.xyzw = t4.Sample(s4_s, r2.xz).xyzw;
  r2.xzw = r7.xyz * r6.yyy;
  r2.xzw = r3.xyz * r6.xxx + r2.xzw;
  r2.xzw = r8.xyz * r6.zzz + r2.xzw;
  r2.xzw = cb3[3].xyz * r2.xzw;
  r2.xyz = r2.yyy * r2.xzw;
  r3.xyz = cb3[2].xxx * v2.xyz;
  r7.xyzw = t3.Sample(s3_s, r3.zy).xyzw;
  r8.xyzw = t3.Sample(s3_s, r3.xz).xyzw;
  r3.xyzw = t3.Sample(s3_s, r3.xy).xyzw;
  r8.xyz = r8.xyz * r6.yyy;
  r7.xyz = r7.xyz * r6.xxx + r8.xyz;
  r3.xyz = r3.xyz * r6.zzz + r7.xyz;
  r3.xyz = cb3[1].xyz * r3.xyz;
  r2.xyz = r0.www * r3.xyz + r2.xyz;
  r2.w = cb3[9].z + cb3[4].z;
  r3.x = cb3[9].w + r2.w;
  r2.w = -r3.x + r2.w;
  r1.w = -r3.x + r1.w;
  r2.w = 1 / r2.w;
  r1.w = saturate(r2.w * r1.w);
  r2.w = r1.w * -2 + 3;
  r1.w = r1.w * r1.w;
  r1.w = r2.w * r1.w;
  r0.w = r1.w * r0.w;
  r2.xyz = r0.www * -cb3[9].yyy + r2.xyz;
  r0.xyz = r2.xyz * r0.xyz;
  r0.w = dot(r5.xyz, r5.xyz);
  r0.w = rsqrt(r0.w);
  r2.xyz = r5.xyz * r0.www;
  r0.w = dot(v7_corrected, v7_corrected);
  r1.w = rsqrt(r0.w);
  r0.w = max(1.17549435e-38, r0.w);
  r0.w = rsqrt(r0.w);
  r3.xyz = v7_corrected * r1.www;
  r1.w = dot(r2.xyz, r3.xyz);
  r1.w = -0.217637643 + r1.w;
  r1.w = saturate(r1.w * cb3[7].y + 0.217637643);
  r1.w = 1 + -r1.w;
  r1.w = log2(r1.w);
  r1.w = cb3[7].x * r1.w;
  r1.w = exp2(r1.w);
  r1.w = r1.w * r1.w;
  r2.xyz = cb3[6].xyz * r1.www;
  r1.x = dot(r1.xyz, r3.xyz);
  r1.y = dot(r5.xyz, r3.xyz);
  r1.x = -0.217637643 + r1.x;
  r1.x = saturate(r1.x * cb3[7].y + 0.217637643);
  r1.x = 1 + -r1.x;
  r1.x = log2(r1.x);
  r1.x = cb3[7].x * r1.x;
  r1.x = exp2(r1.x);
  r1.x = r1.x * r1.x;
  r1.xzw = r1.xxx * cb3[5].xyz + r2.xyz;
  r1.xzw = cb3[5].www * r1.xzw;
  r2.xyzw = t2.Sample(s2_s, v6.xy).xyzw;
  r0.xyz = r2.xyz * r0.xyz + r1.xzw;
  r1.xzw = saturate(r0.xyz + r0.xyz);
  r1.xzw = -cb3[8].xyz + r1.xzw;
  r2.x = cmp(cb3[0].x >= 0.5);
  r2.x = r2.x ? 1.000000 : 0;
  r1.xzw = r2.xxx * r1.xzw + cb3[8].xyz;
  r2.xyz = cb3[12].yyy * v2.xyz;
  r3.xyzw = t7.Sample(s7_s, r2.xz).xyzw;
  r3.xyz = r3.xyz * r6.yyy;
  r7.xyzw = t7.Sample(s7_s, r2.zy).xyzw;
  r2.xyzw = t7.Sample(s7_s, r2.xy).xyzw;
  r3.xyz = r7.xyz * r6.xxx + r3.xyz;
  r2.xyz = r2.xyz * r6.zzz + r3.xyz;
  r2.w = dot(cb0[3].xyz, cb0[3].xyz);
  r2.w = rsqrt(r2.w);
  r3.xyz = cb0[3].xyz * r2.www;
  r2.w = dot(r5.xyz, r3.xyz);
  r2.w = -cb3[10].x + r2.w;
  r3.x = 1 + -cb3[10].x;
  r2.w = r2.w / r3.x;
  r3.x = -cb3[12].z * 1.10000002 + r2.w;
  r3.y = cb3[12].w * -0.999000013 + 1;
  r3.y = 1 / -r3.y;
  r3.x = saturate(r3.x * r3.y);
  r3.y = r3.x * -2 + 3;
  r3.x = r3.x * r3.x;
  r3.x = r3.y * r3.x;
  r2.xyz = -r2.xyz * r3.xxx + float3(1,1,1);
  r3.xyz = float3(1,1,1) + -r2.xyz;
  r5.xyzw = t8.Sample(s7_s, v5.xy).xyzw;
  r5.xy = float2(1,1) + -r5.zx;
  r2.xyz = r5.xxx * r3.xyz + r2.xyz;
  r3.xy = float2(1,0) * r2.ww;
  r1.y = r2.w * r1.y;
  r1.y = cmp(r1.y >= cb3[9].x);
  r1.y = r1.y ? 1.000000 : 0;
  r1.y = cb3[8].w * r1.y;
  r3.xyzw = t6.Sample(s6_s, r3.xy).xyzw;
  r2.xyz = r3.xyz * r2.xyz;
  r2.xyz = r5.yyy * -r2.xyz + r2.xyz;
  r1.xzw = -r0.xyz * r2.xyz + r1.xzw;
  r0.xyz = r2.xyz * r0.xyz;
  r0.xyz = r1.yyy * r1.xzw + r0.xyz;
  r0.xyz = float3(0.959999979,0.959999979,0.959999979) * r0.xyz;
  r1.xyz = v7_corrected * r0.www;
  r2.xyz = v7_corrected * r0.www + cb0[3].xyz;
  r0.w = dot(-r1.xyz, r4.xyz);
  r0.w = r0.w + r0.w;
  r3.xyz = r4.xyz * -r0.www + -r1.xyz;
  r0.w = saturate(dot(r4.xyz, r1.xyz));
  r1.x = saturate(dot(r4.xyz, cb0[3].xyz));
  r0.w = 1 + -r0.w;
  r0.w = r0.w * r0.w;
  r0.w = r0.w * r0.w;
  r0.w = r0.w * 2.23517418e-08 + 0.0399999991;
  r3.xyzw = t0.SampleLevel(s0_s, r3.xyz, 6).xyzw;
  r1.y = -1 + r3.w;
  r1.y = cb1[14].w * r1.y + 1;
  r1.y = max(0, r1.y);
  r1.y = log2(r1.y);
  r1.y = cb1[14].y * r1.y;
  r1.y = exp2(r1.y);
  r1.y = cb1[14].x * r1.y;
  r1.yzw = r1.yyy * r3.xyz;
  r1.yzw = float3(0.5,0.5,0.5) * r1.yzw;
  r1.yzw = r1.yzw * r0.www;
  r1.yzw = v9.xyz * r0.xyz + r1.yzw;
  r0.w = dot(r2.xyz, r2.xyz);
  r0.w = max(1.17549435e-38, r0.w);
  r0.w = rsqrt(r0.w);
  r2.xyz = r2.xyz * r0.www;
  r0.w = saturate(dot(cb0[3].xyz, r2.xyz));
  r0.w = r0.w * r0.w;
  r0.w = max(0.100000001, r0.w);
  r0.w = 6.00012016 * r0.w;
  r0.w = 1 / r0.w;
  r0.xyz = r0.www * float3(0.0399999991,0.0399999991,0.0399999991) + r0.xyz;
  r2.xy = v11.xy * cb2[30].zw + float2(0.5,0.5);
  r2.xy = floor(r2.xy);
  r2.zw = v11.xy * cb2[30].zw + -r2.xy;
  r3.xy = min(float2(0,0), r2.zw);
  r3.zw = float2(1,1) + -r2.zw;
  r3.xy = -r3.xy * r3.xy + r3.zw;
  r4.xy = float2(0.159999996,0.159999996) * r3.zw;
  r3.xy = float2(1,1) + r3.xy;
  r3.xy = float2(0.159999996,0.159999996) * r3.xy;
  r5.xy = max(float2(0,0), r2.zw);
  r6.xyzw = float4(0.5,1,0.5,1) + r2.zzww;
  r5.xy = -r5.xy * r5.xy + r6.yw;
  r5.xy = float2(1,1) + r5.xy;
  r5.xy = float2(0.159999996,0.159999996) * r5.xy;
  r7.xyzw = r6.xxzz * r6.xxzz;
  r6.xy = float2(0.159999996,0.159999996) * r6.yw;
  r2.zw = r7.xz * float2(0.5,0.5) + -r2.zw;
  r4.zw = float2(0.0799999982,0.0799999982) * r7.wy;
  r7.xy = float2(0.159999996,0.159999996) * r2.zw;
  r3.z = r7.y;
  r3.w = r6.y;
  r7.w = r6.x;
  r5.zw = r4.yz;
  r3.yzw = r5.zyw + r3.zyw;
  r7.z = r3.x;
  r5.yzw = r5.zyw / r3.yzw;
  r4.z = r5.x;
  r5.xyz = float3(-2.5,-0.5,1.5) + r5.yzw;
  r5.xyz = cb2[30].yyy * r5.xyz;
  r6.w = r5.x;
  r7.xyzw = r7.zwxz + r4.zwxz;
  r4.xyz = r4.xzw / r7.zwy;
  r4.xyz = float3(-2.5,-0.5,1.5) + r4.xyz;
  r6.xyz = cb2[30].xxx * r4.yxz;
  r4.xyzw = r2.xyxy * cb2[30].xyxy + r6.ywxw;
  r2.zw = r2.xy * cb2[30].xy + r6.zw;
  r0.w = t1.SampleCmpLevelZero(s1_s, r2.zw, v11.z).x;
  r2.z = t1.SampleCmpLevelZero(s1_s, r4.xy, v11.z).x;
  r2.w = t1.SampleCmpLevelZero(s1_s, r4.zw, v11.z).x;
  r4.xyzw = r7.zwyz * r3.yyyz;
  r2.w = r4.y * r2.w;
  r2.z = r4.x * r2.z + r2.w;
  r0.w = r4.z * r0.w + r2.z;
  r5.w = r6.y;
  r8.xyzw = r2.xyxy * cb2[30].xyxy + r5.wywz;
  r6.yw = r5.yz;
  r2.z = t1.SampleCmpLevelZero(s1_s, r8.xy, v11.z).x;
  r2.w = t1.SampleCmpLevelZero(s1_s, r8.zw, v11.z).x;
  r0.w = r4.w * r2.z + r0.w;
  r4.xyzw = r2.xyxy * cb2[30].xyxy + r6.xyzy;
  r5.xyzw = r2.xyxy * cb2[30].xyxy + r6.xwzw;
  r2.x = t1.SampleCmpLevelZero(s1_s, r4.xy, v11.z).x;
  r2.y = t1.SampleCmpLevelZero(s1_s, r4.zw, v11.z).x;
  r4.xyzw = r7.xyzw * r3.zzww;
  r2.z = r7.y * r3.w;
  r0.w = r4.x * r2.x + r0.w;
  r0.w = r4.y * r2.y + r0.w;
  r0.w = r4.z * r2.w + r0.w;
  r2.x = t1.SampleCmpLevelZero(s1_s, r5.xy, v11.z).x;
  r2.y = t1.SampleCmpLevelZero(s1_s, r5.zw, v11.z).x;
  r0.w = r4.w * r2.x + r0.w;
  r0.w = r2.z * r2.y + r0.w;
  r2.x = 1 + -cb2[29].x;
  r0.w = r0.w * cb2[29].x + r2.x;
  r2.x = cmp(0 >= v11.z);
  r2.y = cmp(v11.z >= 1);
  r2.x = (int)r2.y | (int)r2.x;
  r0.w = r2.x ? 1 : r0.w;
  r0.w = cb1[10].z * r0.w;
  r0.w = r0.w * r1.x;
  r2.xyz = cb0[4].xyz * r0.www;
  r0.xyz = r0.xyz * r2.xyz + r1.yzw;
  r0.xyz = -cb0[48].xyz + r0.xyz;
  o0.xyz = v10.xxx * r0.xyz + cb0[48].xyz;
  o0.w = 1;
  return;
}