Yardım Unity Çapraz Gradient Oluşturucu

UnluckyCalimero

Öğrenci
Katılım
19 Nisan 2023
Mesajlar
3
Reaksiyon puanı
0
Puanları
1
Yaş
17
Okul Projem için atılan image nesnesine göre çapraz olacak şekilde bir gradient texture oluşturan bir script yazıyorum fakat renklerin buluştuğu yeri ortalamıyor. Chatgpt ile bu işi çözemedim. Sorunu nasıl çözebilirim?

C#:
void GradientYapCapraz()
{
    int textureWidth = 256;
    int textureHeight = 256;

    Texture2D gradientTexture = GradientTextureCapraz(renk1, renk2, textureWidth, textureHeight, mixPosition);

    imageComponent.sprite = Sprite.Create(gradientTexture, new Rect(0, 0, textureWidth, textureHeight), new Vector2(0.5f, 0.5f));
}

Texture2D GradientTextureCapraz(Color startColor, Color endColor, int textureWidth, int textureHeight, float mixPosition)
{
    Texture2D texture = new Texture2D(textureWidth, textureHeight);
    Color[] gradientColors = new Color[textureWidth * textureHeight];

    for (int y = 0; y < textureHeight; y++)
    {
        for (int x = 0; x < textureWidth; x++)
        {
            float t = Mathf.InverseLerp(0, textureWidth - 1, x);
            float u = Mathf.InverseLerp(0, textureHeight - 1, y);

            Color lerpedColor = Color.Lerp(startColor, endColor, Mathf.Lerp(0, 1, Mathf.Clamp01(t + u - mixPosition)));
            gradientColors[y * textureWidth + x] = lerpedColor;
        }
    }

    texture.SetPixels(gradientColors);
    texture.Apply();

    return texture;
}

Çıktı:
Ekran görüntüsü 2024-01-03 200305.png
 
Üst