Version: 2022.1

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

静态变量

active当前处于活动状态的渲染纹理。

变量

antiAliasingRenderTexture 的抗锯齿级别。
autoGenerateMips如果设置了该标志,则自动生成多级渐进纹理级别。
bindTextureMS如果为 true 且 antiAliasing 大于 1,则默认不解析渲染纹理。如果需要在着色器中将渲染纹理绑定为多重采样纹理,请使用该属性。
colorBuffer渲染纹理的颜色缓冲区(只读)。
depthThe precision of the render texture's depth buffer in bits (0, 16, 24 and 32 are supported).
depthBuffer渲染纹理的深度/模板缓冲区(只读)。
depthStencilFormatThe format of the depth/stencil buffer.
descriptor此结构包含创建 RenderTexture 需要的所有信息。可以复制、缓存和重用来轻松创建全部共享相同属性的 RenderTexture。
dimension渲染纹理的维度(类型)。
enableRandomWrite在 Shader Model 5.0 级别着色器上启用随机访问写入该渲染纹理。
graphicsFormatThe color format of the render texture. You can set the color format to None to achieve depth-only rendering.
height渲染纹理的高度(以像素为单位)。
memorylessMode渲染纹理无记忆模式属性。
sRGB该渲染纹理是否使用 sRGB 读/写转换?(只读)
stencilFormatThe format of the stencil data that you can encapsulate within a RenderTexture.Specifying this property creates a stencil element for the RenderTexture and sets its format. This allows for stencil data to be bound as a Texture to all shader types for the platforms that support it. This property does not specify the format of the stencil buffer, which is constrained by the depth buffer format specified in RenderTexture.depth.Currently, most platforms only support R8_UInt (DirectX11, DirectX12), while PS4 also supports R8_UNorm.
useDynamicScaleIs the render texture marked to be scaled by the Dynamic Resolution system.
useMipMap如果设置该标志,则渲染纹理具有多级渐进纹理。
volumeDepth3D 渲染纹理的体积范围或数组纹理的切片数。
vrUsage如果该 RenderTexture 是在立体渲染中使用的 VR 眼睛纹理,则该属性决定将进行哪些特殊渲染(如果有)。
width渲染纹理的宽度(以像素为单位)。

构造函数

RenderTexture创建一个新的 RenderTexture 对象。

公共函数

ConvertToEquirect将渲染纹理转换为等距圆柱投影格式(都为立体或单视场等距圆柱投影)。 左眼占据上半部分,右眼占据底部。单视场版本将占据整个纹理。 纹理尺寸必须为 TextureDimension.Cube 类型。
Create实际创建 RenderTexture。
DiscardContents提示 GPU 驱动程序将不使用 RenderTexture 的内容。
GenerateMips生成渲染纹理的多级渐进纹理级别。
GetNativeDepthBufferPtr获取指向该深度缓冲区资源的原生(底层图形 API)指针。
IsCreated是否实际创建了该渲染纹理?
Release释放 RenderTexture。
ResolveAntiAliasedSurface强制解析抗锯齿渲染纹理。
SetGlobalShaderProperty将该 RenderTexture 指定为名为 propertyName 的全局着色器属性。

静态函数

GetTemporary分配临时渲染纹理。
ReleaseTemporary释放使用 GetTemporary 分配的临时纹理。
SupportsStencilRenderTexture 是否具有模板缓冲区?

继承的成员

静态变量

allowThreadedTextureCreationAllow Unity internals to perform Texture creation on any thread (rather than the dedicated render thread).
currentTextureMemoryThe amount of memory that all Textures in the scene use.
desiredTextureMemoryThe total size of the Textures, in bytes, that Unity loads if there were no other constraints. Before Unity loads any Textures, it applies the memory budget which reduces the loaded Texture resolution if the Texture sizes exceed its value. The `desiredTextureMemory` value takes into account the mipmap levels that Unity has requested or that you have set manually. For example, if Unity does not load a Texture at full resolution because it is far away or its requested mipmap level is greater than 0, Unity reduces the `desiredTextureMemory` value to match the total memory needed. The `desiredTextureMemory` value can be greater than the `targetTextureMemory` value.
GenerateAllMipsCan be used with Texture constructors that take a mip count to indicate that all mips should be generated. The value of this field is -1.
nonStreamingTextureCountThe number of non-streaming Textures in the scene. This includes instances of Texture2D and CubeMap Textures. This does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.
nonStreamingTextureMemoryThe amount of memory Unity allocates for non-streaming Textures in the scene. This only includes instances of Texture2D and CubeMap Textures. This does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.
streamingMipmapUploadCountHow many times has a Texture been uploaded due to Texture mipmap streaming.
streamingRendererCountNumber of renderers registered with the Texture streaming system.
streamingTextureCountNumber of streaming Textures.
streamingTextureDiscardUnusedMipsThis property forces the streaming Texture system to discard all unused mipmaps instead of caching them until the Texture memory budget is exceeded. This is useful when you profile or write tests to keep a predictable set of Textures in memory.
streamingTextureForceLoadAllForce streaming Textures to load all mipmap levels.
streamingTextureLoadingCountNumber of streaming Textures with mipmaps currently loading.
streamingTexturePendingLoadCountNumber of streaming Textures with outstanding mipmaps to be loaded.
targetTextureMemoryThe total amount of Texture memory that Unity allocates to the Textures in the scene after it applies the memory budget and finishes loading Textures. `targetTextureMemory`also takes mipmap streaming settings into account. This value only includes instances of Texture2D and CubeMap Textures. This value does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.
totalTextureMemoryThe total amount of Texture memory that Unity would use if it loads all Textures at mipmap level 0. This is a theoretical value that does not take into account any input from the streaming system or any other input, for example when you set the`Texture2D.requestedMipmapLevel` manually. To see a Texture memory value that takes inputs into account, use `desiredTextureMemory`. `totalTextureMemory` only includes instances of Texture2D and CubeMap Textures. This value does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。
anisoLevelDefines the anisotropic filtering level of the Texture.
dimensionDimensionality (type) of the Texture (Read Only).
filterModeFiltering mode of the Texture.
graphicsFormatReturns the GraphicsFormat format or color format of a Texture object.
heightHeight of the Texture in pixels (Read Only).
imageContentsHash纹理的哈希值。
isReadableWhether Unity stores an additional copy of this texture's pixel data in CPU-addressable memory.
mipMapBiasThe mipmap bias of the Texture.
mipmapCountHow many mipmap levels are in this Texture (Read Only).
updateCountThis counter is incremented when the Texture is updated.
widthWidth of the Texture in pixels (Read Only).
wrapMode纹理坐标换行模式。
wrapModeU纹理 U 坐标换行模式。
wrapModeV纹理 V 坐标换行模式。
wrapModeW Texture3D 的纹理 W 坐标换行模式。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。
GetNativeTexturePtrRetrieve a native (underlying graphics API) pointer to the Texture resource.
IncrementUpdateCount递增更新计数器。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。
SetGlobalAnisotropicFilteringLimits设置各向异性限制。
SetStreamingTextureMaterialDebugPropertiesThis function sets mipmap streaming debug properties on any materials that use this Texture through the mipmap streaming system.

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961