// ---- Created with 3Dmigoto v1.3.16 on Sun Apr 26 20:26:55 2026
Texture2D<float4> t3 : register(t3);
Texture2D<float4> t2 : register(t2);
Texture2D<float4> t1 : register(t1);
Texture2D<float4> t0 : register(t0);
SamplerState s2_s : register(s2);
SamplerState s1_s : register(s1);
SamplerState s0_s : register(s0);
cbuffer cb4 : register(b4) { float4 cb4[10]; }
cbuffer cb3 : register(b3) { float4 cb3[112]; }
cbuffer cb2 : register(b2) { float4 cb2[2]; }
cbuffer cb1 : register(b1) { float4 cb1[37]; }
cbuffer cb0 : register(b0) { float4 cb0[59]; }

#define cmp -
Texture1D<float4> IniParams : register(t120);

void main(
  float4 v0 : SV_POSITION0,
  float4 v1 : COLOR0,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD3,
  float3 v4 : TEXCOORD6,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyzw = t3.Sample(s2_s, v2.xy).xyzw;

  // ---- 黑色背景剔除（仅使用亮度与饱和度）----
  float brightness = r0.r + r0.g + r0.b;
  float saturation = max(r0.r, max(r0.g, r0.b)) - min(r0.r, min(r0.g, r0.b));
  if (brightness < 0.95 || (saturation < 0.03 && brightness < 0.99)) discard;
  // ------------------------------------------

  // 备份原始颜色用于暖色判定
  float3 rawTextureColor = r0.xyz;

  r0.w = saturate(cb4[4].z + r0.w);
  r1.xyzw = v1.xyzw * r0.xyzw;
  r1.w = saturate(r1.w);
  r2.x = cmp(asint(cb4[6].x) == 1);
  r2.yzw = saturate(cb4[2].www + r0.xyz);
  r3.x = dot(cb4[2].xyz, r0.xyz);
  r3.w = saturate(v1.w * r3.x);
  r3.xyz = v1.xyz * r2.yzw;
  r2.y = saturate(dot(cb4[3].xyzw, r0.xyzw));
  r0.x = dot(cb4[2].xyzw, r0.xyzw);
  r0.w = saturate(v1.w * r0.x);
  r0.xyz = v1.xyz * r2.yyy;
  r0.xyzw = r2.xxxx ? r3.xyzw : r0.xyzw;
  r0.xyzw = cb4[6].xxxx ? r0.xyzw : r1.xyzw;
  r1.x = cmp(0 < cb4[4].w);
  r1.y = cmp(0 < cb4[5].x);
  r1.x = (int)r1.y | (int)r1.x;
  if (r1.x != 0) {
    r1.xyz = v3.xyz / v3.www;
    r2.xy = float2(1,1) + -cb1[36].xy;
    r1.xy = r1.xy * r2.xy + cb1[36].zw;
    r2.xyzw = t0.SampleLevel(s1_s, r1.xy, 0).xyzw;
    r1.x = cb2[1].z * r1.z + cb2[1].w;
    r1.x = 1 / r1.x;
    r1.y = r2.x * cb0[44].x + -cb4[4].w;
    r1.x = r1.y + -r1.x;
    r1.x = saturate(cb4[5].x * r1.x);
  } else {
    r1.x = 1;
  }
  r0.w = r1.x * r0.w;
  r1.xy = cmp(asint(cb4[5].yz) == int2(0,3));
  r1.x = r1.y ? r1.x : 0;
  r2.xyzw = float4(-1,-1,-1,-1) + r0.xyzw;
  r2.xyzw = r0.wwww * r2.xyzw + float4(1,1,1,1);
  r0.xyzw = r1.xxxx ? r2.xyzw : r0.xyzw;
  r1.x = 1 + -cb4[5].w;
  r0.w = r1.x * r0.w;
  r1.w = cb4[9].w * r0.w;

  // ---- 樱花滤镜 + 橙色捕获 ----
  float luma = dot(r0.xyz, float3(0.299, 0.587, 0.114));
  float3 sakuraColor = luma * float3(1.8, 0.8, 1.1);
  bool isWarm = (rawTextureColor.r * 1.25) >= rawTextureColor.g;
  bool isNotCold = rawTextureColor.r >= (rawTextureColor.b * 1.2);
  bool isBright = rawTextureColor.r >= 0.10;
  if (isWarm && isNotCold && isBright) {
      r0.xyz = sakuraColor;
  }
  // -------------------------

  r2.xy = -cb0[45].xy * cb3[1].xy + float2(1,1);
  r0.xyz = r2.xxx * r0.xyz;
  r0.xyz = r0.xyz * r2.yyy;
  r0.xyz = cb3[111].www * r0.xyz;
  r0.w = max(r0.x, r0.y);
  r0.w = max(r0.w, r0.z);
  r0.w = r0.w * r1.w;
  r0.w = max(0.00999999978, r0.w);
  r0.xyz = r0.xyz / r0.www;
  r2.x = cmp(cb3[79].x < r0.w);
  r2.y = -cb3[79].x + cb3[78].w;
  r2.z = -cb3[79].x + r0.w;
  r2.w = 1 / r2.y;
  r2.z = saturate(r2.z * r2.w);
  r2.w = r2.z * -2 + 3;
  r2.z = r2.z * r2.z;
  r2.z = r2.w * r2.z;
  r2.y = r2.z * r2.y + cb3[79].x;
  r2.y = r2.y + -r0.w;
  r2.y = cb3[79].y * r2.y + r0.w;
  r0.w = r2.x ? r2.y : r0.w;
  r1.xyz = r0.xyz * r0.www;
  r2.x = cmp(0 < cb0[58].x);
  if (r2.x != 0) {
    r2.xyz = v3.xyz / v3.www;
    r3.xyzw = t2.SampleLevel(s0_s, r2.xy, 0).xyzw;
    r2.w = cmp(0.99000001 >= r3.w);
    r4.x = ~(int)r2.w;
    if (r2.w != 0) {
      r5.xyzw = t1.SampleLevel(s0_s, r2.xy, 0).xyzw;
      r2.x = cb2[1].x * r2.z + cb2[1].y;
      r2.x = 1 / r2.x;
      r2.x = cmp(r5.x >= r2.x);
      r2.x = r2.x ? 1.000000 : 0;
      r5.xyzw = cmp(asint(cb4[5].yzzy) == int4(5,10,1,1));
      r2.yzw = r3.www * r1.xyz;
      r4.yzw = r1.xyz * r3.www + r3.xyz;
      r5.xyz = r5.yzy ? r5.xxw : 0;
      r3.xyz = r3.xyz * r1.www + r2.yzw;
      r3.xyz = r5.zzz ? r3.xyz : r1.xyz;
      r2.yzw = r5.yyy ? r2.yzw : r3.xyz;
      r2.yzw = r5.xxx ? r4.yzw : r2.yzw;
      r0.xyz = r0.xyz * r0.www + -r2.yzw;
      r0.xyz = r2.xxx * r0.xyz + r2.yzw;
    } else {
      r0.xyz = r1.xyz;
    }
    r2.xyzw = r1.xyzw;
    r1.xyz = r0.xyz;
  } else {
    r4.x = 0;
  }
  o0.xyzw = r4.xxxx ? r2.xyzw : r1.xyzw;
  return;
}