返回介绍

RenderTexture.active 激活

发布于 2019-12-18 15:38:27 字数 2801 浏览 1465 评论 0 收藏 0

JavaScript => public static var active: RenderTexture;
C# => public static RenderTexture active;

Description 描述

Currently active render texture.

激活当前的渲染贴图。

All rendering goes into the active RenderTexture. If the active RenderTexture is null everything is rendered in the main window.

所有渲染进入激活渲染纹理。如果激活渲染纹理为空在主窗口的所有物体被渲染。

Setting RenderTexture.active is the same as calling Graphics.SetRenderTarget. Typically you change or query the active render texture when implementing custom graphics effects; if all you need is to make a Camera render into a texture then use Camera.targetTexture instead.

设置RenderTexture.active是与调用Graphics.SetRenderTarget一样。当执行自定义图形效果时你可以改变或者查询激活渲染纹理;如果你需要所有的摄像机渲染到纹理那么使用Camera.targetTexture代替。

When a RenderTexture becomes active its hardware rendering context is automatically created if it hasn't been created already.

当渲染纹理变成激活,如果它没有被创建,它的硬件渲染环境是自动创建的。

JavaScript:

#pragma strict
// Get the contents of a RenderTexture into a Texture2D
public static function GetRTPixels(rt: RenderTexture) {
	// Remember currently active render texture
	var currentActiveRT: RenderTexture = RenderTexture.active;
	// Set the supplied RenderTexture as the active one
	RenderTexture.active = rt;
	// Create a new Texture2D and read the RenderTexture image into it
	var tex: Texture2D = 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;
}

C#:

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;
    }
}

rendertexture

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文