İçeriğe geç
ShiftDelete.Net
Haber ara/ SDN'ye SorGiriş
Haber Akışı SDNTV İnceleme Forum Yapay Zeka Akıllı Telefon Elektrikli Otomobil Oyun ShiftDelete.Net Global Teknoloji Haberleri Mobil Otomobil Donanım Savunma Bilim Sosyal Medya İnternet Giyilebilir Teknoloji Rehber Ürünler Son dakika Yazarlar
  1. Ana sayfa
  2. Topluluk
  3. Yazılım
  4. Diğer Yazılım Konuları
Diğer Yazılım Konuları

Unity Çapraz Gradient Oluşturucu

UnluckyCalimero03.01.20240 cevap609 görüntüleme
2023'den beri5 mesaj
#1
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?
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

Cevabını yaz

Cevap yazmak için giriş yap ya da üye ol. Eski forum kullanıcı adın ve parolanla girebilirsin.