RenderTexture.active

Unity · Версия 2020.3 LTS · Scripting · RenderTexture

RenderTexture.active

public static RenderTexture active;

Описание

Текущая активная текстура рендеринга.

Вся визуализация выполняется в активной RenderTexture. Если активная RenderTexture имеет значение null, все отображается в главном окне.

Настройка RenderTexture.active аналогична вызову Graphics.SetRenderTarget. Обычно вы изменяете или запрашиваете активную текстуру рендеринга при реализации пользовательских графических эффектов; если все, что вам нужно, это превратить рендер камеры в текстуру, используйте Camera.targetTexture вместо этого.

Когда RenderTexture становится активной, ее аппаратный контекст рендеринга создается автоматически, если он еще не создан.

Смотрите так же: Graphics.SetRenderTarget.

using UnityEngine;
using System.Collections;

// Get the contents of a RenderTexture into a Texture2D
public class ExampleClass : MonoBehaviour
{
    static public Texture2D GetRTPixels(RenderTexture rt)
    {
        // Remember currently active render texture
        RenderTexture currentActiveRT = RenderTexture.active;

        // Set the supplied RenderTexture as the active one
        RenderTexture.active = rt;

        // Create a new Texture2D and read the RenderTexture image into it
        Texture2D tex = new Texture2D(rt.width, rt.height);
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

        // Restorie previously active render texture
        RenderTexture.active = currentActiveRT;
        return tex;
    }
}

Обновлено 17 ноября 2026 г.