包含此页的版本:
不含此页的版本:
要优化渲染图,请合并或减少渲染通道的数量。渲染通道越多,CPU和GPU需要从内存中存储和检索的数据就越多。这会减慢渲染速度,尤其是在使用基于图块的延迟拖延 (TBDR) 的设备上。
如果您需要颜色的副本或深度缓冲区保存图像中每个像素的 z 值深度的内存存储,其中 z 值是投影平面中每个呈现像素的深度。更多信息
请参阅术语表,如果可以的话,避免自己复制它们。请改用 URP 默认创建的副本,以避免创建不必要的渲染通道。
使用 ConfigureInput API 确保 URP 在帧数据中生成所需的纹理。
要检查URP是否在帧内创建了可以使用的副本,请在渲染图表查看器中检查以下通道:
_CameraTargetAttachment自cameraOpaqueTexture在帧数据中。_CameraDepthAttachment自cameraDepthTexture在帧数据中。使用渲染图表查看器检查URP无法合并渲染通道的原因,并尽可能修复该问题。在使用基于图块的延迟拖延 (TBDR) 的设备上,合并传递有助于设备使用更少的能源并运行更长时间。
你可以执行以下作来确保URP合并渲染通道:
AddRasterRenderPass而不是尽可能其他类型的渲染通道。SetInputAttachmentAPI 和LOAD_FRAMEBUFFER_X_INPUT宏。有关更多信息,请参阅从 GPU 内存获取当前帧缓冲区。不要创建不必要的渲染通道来将代码组织成更小、更易于管理的块。您创建的每个渲染通道都需要在CPU上花费更多的处理时间。
要编写组合渲染通道,您可以使用AddUnsafePassAPI 和兼容模式 API,例如SetRenderTarget,但渲染速度可能会变慢,因为 URP 无法优化渲染通道。有关更多信息,请参阅在渲染图通道中使用兼容模式 API。
避免创建两个渲染通道blit“位块传输”的简写术语。blit作是将数据块从内存中的一个位置传输到另一个位置的过程。
请参阅术语表从 和 到相机在场景中创建特定视点图像的组件。输出要么绘制到屏幕上,要么作为纹理捕获。更多信息
请参阅术语表颜色纹理,使用ContextContainer对象直接读取和写入颜色缓冲区。
例如:
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
// Fetch the frame data textures
var resourceData = frameData.Get<UniversalResourceData>();
// Set the source as the color texture the camera currently targets
var source = resourceData.activeColorTexture;
// Create a destination texture, with the same dimensions as the source
var destinationDescriptor = renderGraph.GetTextureDesc(source);
destinationDescriptor.name = "DestinationTexture";
destinationDescriptor.clearBuffer = false;
TextureHandle destination = renderGraph.CreateTexture(destinationDescriptor);
// Use the AddBlitPass API to create a simple blit from the source to the destination
RenderGraphUtils.BlitMaterialParameters parameters = new(source, destination, BlitMaterial, 0);
renderGraph.AddBlitPass(parameters, passName: "MyRenderPass");
// Set the main color texture for the camera as the destination texture
resourceData.cameraColor = destination;
}