struct VertexAttributes {
    float3 position;
    float3 normal;
    float4 tangent;
};

RWStructuredBuffer<VertexAttributes> rw_buffer : register(u5);
StructuredBuffer<VertexAttributes> base : register(t50);
StructuredBuffer<VertexAttributes> BiggerBottom : register(t51);
StructuredBuffer<VertexAttributes> SmallerBottom : register(t52);
StructuredBuffer<VertexAttributes> BiggerChest : register(t53);
StructuredBuffer<VertexAttributes> SmallerChest : register(t54);

Texture1D<float4> IniParams : register(t120);
#define key IniParams[88].x
#define key1 IniParams[89].x

[numthreads(1, 1, 1)]
void main(uint3 threadID : SV_DispatchThreadID)
{
    uint i = threadID.x;
    float kt1 = saturate(key);   // For bottom morphing
    float kt2 = saturate(key1);  // For chest morphing

    float3 pos_bottom;
    float3 norm_bottom;
    float4 tang_bottom;

    // Interpolate bottom
    if (kt1 <= 0.5)
    {
        float t = kt1 * 2.0;
        pos_bottom = lerp(SmallerBottom[i].position, base[i].position, t);
        norm_bottom = normalize(lerp(SmallerBottom[i].normal, base[i].normal, t));
        tang_bottom = normalize(lerp(SmallerBottom[i].tangent, base[i].tangent, t));
    }
    else
    {
        float t = (kt1 - 0.5) * 4.0;
        pos_bottom = lerp(base[i].position, BiggerBottom[i].position, t);
        norm_bottom = normalize(lerp(base[i].normal, BiggerBottom[i].normal, t));
        tang_bottom = normalize(lerp(base[i].tangent, BiggerBottom[i].tangent, t));
    }

    float3 pos_chest;
    float3 norm_chest;
    float4 tang_chest;

    // Interpolate chest
    if (kt2 <= 0.5)
    {
        float t = kt2 * 2.0;
        pos_chest = lerp(SmallerChest[i].position, base[i].position, t);
        norm_chest = normalize(lerp(SmallerChest[i].normal, base[i].normal, t));
        tang_chest = normalize(lerp(SmallerChest[i].tangent, base[i].tangent, t));
    }
    else
    {
        float t = (kt2 - 0.5) * 4.0;
        pos_chest = lerp(base[i].position, BiggerChest[i].position, t);
        norm_chest = normalize(lerp(base[i].normal, BiggerChest[i].normal, t));
        tang_chest = normalize(lerp(base[i].tangent, BiggerChest[i].tangent, t));
    }

    // Combine bottom and chest blend equally (you can weight if needed)
    rw_buffer[i].position = (pos_bottom + pos_chest) * 0.5;
    rw_buffer[i].normal = normalize(norm_bottom + norm_chest);
    rw_buffer[i].tangent = normalize(tang_bottom + tang_chest);
}
