// ---- Created with 3Dmigoto v1.3.16 on Mon Feb 16 13:40:30 2026
Texture3D<float4> t5 : register(t5);

Texture2D<float4> t4 : register(t4);

Texture2D<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s5_s : register(s5);

SamplerState s4_s : register(s4);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

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

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

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

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


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


void main(
  float4 v0 : SV_POSITION0,
  float4 v1 : POSITION1,
  float3 v2 : POSITION2,
  float4 v3 : TEXCOORD0,
  float4 v4 : TEXCOORD1,
  float4 v5 : TEXCOORD2,
  float4 v6 : TEXCOORD3,
  float4 v7 : TEXCOORD7,
  float4 v8 : TEXCOORD11,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7;
  uint4 bitmask, uiDest;
  float4 fDest;

  // [新增变量] 用于备份原始贴图颜色
  float3 rawTextureColor;

  r0.xy = v3.xy * cb2[8].xy + cb2[8].zw;
  r0.xy = t2.Sample(s3_s, r0.xy).xw;
  r0.zw = v3.xy * cb2[6].xy + cb2[6].zw;
  r1.xyz = t0.Sample(s1_s, r0.zw).xyz;
  
  // [修改点1] 备份原始贴图颜色 (因为 r1 后面会被光照乘法修改)
  rawTextureColor = r1.xyz;

  r0.zw = v3.xy * cb2[7].xy + cb2[7].zw;
  r2.xyz = t1.Sample(s2_s, r0.zw).xyz;
  r2.xy = saturate(float2(0.00196078443,0.00196078443) + r2.xy);
  r1.xyz = cb2[3].xyz * r1.xyz;
  r3.xyz = cb2[9].xxx * r1.xyz;
  r0.y = cb2[3].w * r0.y;
  r2.xyz = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r2.xy = cb2[9].yy * r2.xy;
  r4.x = dot(v4.xyz, r2.xyz);
  r4.y = dot(v5.xyz, r2.xyz);
  r4.z = dot(v6.xyz, r2.xyz);
  r0.x = -0.00999999978 + r0.x;
  r0.x = max(0, r0.x);
  r0.z = cmp(cb2[97].x == 1.000000);
  r2.xyz = cb2[133].xyz * v8.yyy;
  r2.xyz = cb2[132].xyz * v8.xxx + r2.xyz;
  r2.xyz = cb2[134].xyz * v8.zzz + r2.xyz;
  r2.xyz = cb2[135].xyz * v8.www + r2.xyz;
  r5.xyz = r0.zzz ? r2.xyz : cb2[63].xyz;
  r2.xyz = r0.zzz ? r2.xyz : cb2[65].xyz;
  r0.z = cmp(0.5 < cb2[80].w);
  r6.xy = v8.xy * float2(255,255) + float2(0.5,0.5);
  r6.xy = floor(r6.xy);
  r0.w = 0.00392156886 * r6.y;
  r1.w = r6.x * 0.00392156886 + cb3[7].w;
  r1.w = 79824.4531 * r1.w;
  r1.w = frac(r1.w);
  r1.w = r6.y * 0.00392156886 + r1.w;
  r1.w = cb3[7].w + r1.w;
  r0.w = r1.w * 3.1400001 + r0.w;
  r0.w = cb3[7].w + r0.w;
  r0.w = frac(r0.w);
  r1.w = dot(v8.xyz, float3(0.300000012,0.589999974,0.109999999));
  r2.w = -r1.w + r0.w;
  r1.w = cb2[81].z * r2.w + r1.w;
  r6.xyz = r5.xyz * r1.www;
  r7.xyz = r2.xyz * r1.www;
  r5.xyz = r0.zzz ? r6.xyz : r5.xyz;
  r2.xyz = r0.zzz ? r7.xyz : r2.xyz;
  r0.z = cmp(0.5 < cb2[81].x);
  r0.w = r0.w * 1.5 + 0.5;
  r0.w = cb0[0].y * r0.w;
  r0.w = cb2[81].y * r0.w;
  r0.w = sin(r0.w);
  r0.w = r0.w * 0.5 + 0.5;
  r6.xyz = r5.xyz * r0.www;
  r7.xyz = r2.xyz * r0.www;
  r5.xyz = r0.zzz ? r6.xyz : r5.xyz;
  r2.xyz = r0.zzz ? r7.xyz : r2.xyz;
  r6.xyz = cb0[5].xyz + -v2.xyz;
  r0.z = dot(r6.xyz, r6.xyz);
  r0.z = rsqrt(r0.z);
  r6.xyz = r6.xyz * r0.zzz;
  r0.z = dot(r4.xyz, r6.xyz);
  r2.xyz = r2.xyz + -r5.xyz;
  r2.xyz = cb3[19].xxx * r2.xyz + r5.xyz;
  r0.w = cb2[66].x + -cb2[64].y;
  r0.w = cb3[19].x * r0.w + cb2[64].y;
  r2.xyz = r2.xyz * r0.www;
  r2.xyz = r2.xyz * r0.xxx;
  r0.x = cmp(cb2[0].z < 0.5);
  r0.w = cmp(cb3[2].w < 0.5);
  r0.x = r0.w ? r0.x : 0;
  r0.w = saturate(0.0500000007 + r0.z);
  r0.w = 1 + -r0.w;
  r1.w = max(0.00999999978, cb2[81].w);
  r0.w = log2(r0.w);
  r0.w = r1.w * r0.w;
  r0.w = exp2(r0.w);
  r4.xyz = r0.www * cb2[82].xyz + r2.xyz;
  r0.w = 1 + -r0.z;
  r0.w = -cb2[85].x + r0.w;
  r1.w = 1 / cb2[85].y;
  r0.w = saturate(r1.w * r0.w);
  r5.xyz = cb2[84].xyz * r0.www;
  r5.xyz = cb2[86].xxx * r5.xyz;
  r5.xyz = max(float3(0,0,0), r5.xyz);
  r4.xyz = r5.xyz + r4.xyz;
  r2.xyz = r0.xxx ? r4.xyz : r2.xyz;
  r1.xyz = -r1.xyz * cb2[9].xxx + float3(1,1,1);
  r1.xyz = cb2[62].www * r1.xyz + r3.xyz;
  r3.xyz = saturate(r3.xyz);
  r0.x = cb2[10].x * r0.y;
  r4.w = max(0.100000001, r0.x);
  r0.z = saturate(r0.z);
  r0.x = r0.z * r0.z;
  r5.xyz = cb2[59].xyz * cb2[58].xxx;
  r5.xyz = float3(0.100000001,0.100000001,0.100000001) * r5.xyz;
  r0.x = r0.x * r0.x;
  r0.x = -r0.x * r0.z + 1;
  r0.xyz = r5.xyz * r0.xxx;
  r0.xyz = r0.xyz / r4.www;
  r0.xyz = r3.xyz + r0.xyz;
  r0.xyz = r2.xyz * r1.xyz + r0.xyz;

  // --- [修改点2] 核心逻辑：樱花粉色滤镜 + 智能识别 ---
  // 此时 r0.xyz 是最终计算出的光照颜色
  
  // 1. 准备樱花粉色 (Sakura Pink)
  // 提取亮度 (Luma)
  float luma = dot(r0.xyz, float3(0.299, 0.587, 0.114));
  // 应用粉色配方: R=1.8, G=0.8, B=1.1
  float3 sakuraColor = luma * float3(1.8, 0.8, 1.1);

  // 2. 智能判定 (基于原始贴图 rawTextureColor)
  // 条件A: 捕捉暖色调 (红 * 1.15 >= 绿) -> 抓住黄叶，放过绿灌木
  bool isWarm = (rawTextureColor.r * 1.15) >= rawTextureColor.g;
  
  // 条件B: 排除冷色调 (红 > 蓝 * 1.5) -> 排除天空或阴影中的物体
  bool isNotCold = rawTextureColor.r >= (rawTextureColor.b * 1.5);
  
  // 条件C: 排除深色物体 (红 > 0.15) -> 排除树干
  bool isBright = rawTextureColor.r >= 0.15;

  // 3. 最终替换
  if (isWarm && isNotCold && isBright) {
      r0.xyz = sakuraColor;
  }
  // --- [修改结束] ---

  r1.xy = cb3[76].yy * v2.xz;
  r0.w = t4.SampleLevel(s5_s, r1.xy, 0).x;
  r0.w = r0.w * 2 + -1;
  r1.y = cb3[76].x * r0.w + v2.y;
  r1.xz = v2.xz;
  r1.xyz = -cb0[5].xyz + r1.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = sqrt(r0.w);
  r1.xyz = r1.xyz / r0.www;
  r2.x = cmp(abs(r1.y) < 0.00100000005);
  r1.w = r2.x ? 0.00100000005 : r1.y;
  r2.xy = float2(0.200000003,0.5) * cb3[75].yx;
  r2.zw = -cb3[75].wz + r0.ww;
  r2.zw = max(float2(0,0), r2.zw);
  r3.x = r2.z * r2.x;
  r0.w = -cb3[72].x + cb0[5].y;
  r0.w = cb3[73].y * -r0.w;
  r0.w = max(-126, r0.w);
  r1.y = r2.w * r1.w;
  r1.y = cb3[73].y * r1.y;
  r1.y = max(-127, r1.y);
  r0.w = exp2(r0.w);
  r1.y = exp2(-r1.y);
  r2.x = r2.y / cb3[73].y;
  r0.w = r2.x * r0.w;
  r1.y = 1 + -r1.y;
  r0.w = r1.y * r0.w;
  r3.y = r0.w / r1.w;
  r2.xy = exp2(-r3.xy);
  r2.xy = float2(1,1) + -r2.xy;
  r0.w = saturate(dot(cb3[18].xzy, r1.xzw));
  r0.w = log2(r0.w);
  r0.w = cb3[78].x * r0.w;
  r0.w = exp2(r0.w);
  r0.w = r0.w * r2.y;
  r1.x = saturate(r3.y * 0.899999976 + -1);
  r1.y = 1 + -cb3[78].y;
  r1.y = cb3[6].w * r1.y;
  r2.z = r1.y * 0.125 + cb3[70].y;
  r3.xyz = t3.SampleLevel(s4_s, r2.xz, 0).xyz;
  r1.zw = max(float2(0,0), r2.xy);
  r2.xz = float2(1,1) + -r1.zw;
  r3.xyz = r3.xyz * r1.zzz;
  r3.xyz = r0.xyz * r2.xxx + r3.xyz;
  r2.w = r1.y * 0.125 + cb3[71].w;
  r2.xyw = t3.SampleLevel(s4_s, r2.yw, 0).xyz;
  r1.x = cb3[74].x * -r1.x + r1.x;
  r1.yzw = r2.xyw * r1.www;
  r1.yzw = r3.xyz * r2.zzz + r1.yzw;
  r1.xyz = r1.xxx * r3.xyz + r1.yzw;
  r1.xyz = r0.www * cb3[77].xyz + r1.xyz;
  r0.w = 1 + -cb3[1].y;
  r1.xyz = r1.xyz + -r0.xyz;
  r4.xyz = r0.www * r1.xyz + r0.xyz;
  r0.x = cmp(0 < asint(cb1[0].z));
  if (r0.x != 0) {
    r0.xy = float2(1,1) + -cb0[36].xy;
    r0.xy = v1.xy * r0.xy + cb0[36].zw;
    r0.z = v1.z;
    r0.xyz = r0.xyz / v1.www;
    r1.xy = r0.xy * float2(2,2) + float2(-1,-1);
    r1.yz = cb0[11].zw * r1.yy;
    r1.xy = cb0[10].zw * r1.xx + r1.yz;
    r1.xy = cb0[12].zw * r0.zz + r1.xy;
    r1.xy = cb0[13].zw + r1.xy;
    r0.z = -r1.x / r1.y;
    r0.z = r0.z * cb1[10].x + cb1[10].y;
    r0.z = max(9.99999975e-05, r0.z);
    r0.z = log2(r0.z);
    r0.w = cb1[10].z * r0.z;
    r0.xyzw = t5.SampleLevel(s0_s, r0.xyw, 0).xyzw;
    r4.xyz = r4.xyz * r0.www + r0.xyz;
  }
  o0.xyzw = r4.xyzw;
  return;
}