RenderTexture
#unity/日常积累
RenderTexture
class in UnityEngine
/
继承自:Texture
描述
渲染纹理是可对其进行渲染的纹理。
它们可用于实现基于图像的渲染特效、动态阴影、 投影器、反射或监视摄像机。
渲染纹理的一个典型用法是将其设置为 摄像机的“目标纹理”属性 (Camera.targetTexture),这将使摄像机渲染到纹理, 而不是渲染到屏幕。
请记住,渲染纹理内容在某些情况下会“丢失”,例如加载新关卡、系统进入屏幕保护模式、进入和退出全屏模式等。 当发生这些情况时,您现有的渲染纹理将再度变为“尚未创建”的状态,您可以使用 IsCreated 函数对此进行检查。
与其他“本机引擎对象”类型一样,必须时刻注意任何渲染纹理的生命周期, 并牢记在使用完渲染纹理后使用 Release 函数释放它们, 因为系统不会像对待常规托管类型那样对它们进行垃圾回收。
A render texture only has a data representation on the GPU and you need to use Texture2D.ReadPixels to transfer its contents to CPU memory.
The initial contents of a newly created render texture are undefined. On some platforms/API’s the contents will default to black but users should not depend on this.
另请参阅:Camera.targetTexture。