PolySpatial 渲染纹理支持
PolySpatial使用优化的路径将RenderTexture传输到主机平台。 在visionOS上,这是通过使用GPU blit将RenderTexture的内容复制到RealityKit提供的纹理中来执行的。 然而,一次传输大量的RenderTexture和/或具有大尺寸的RenderTexture仍然可能导致性能损失。
格式
visionOS上支持的RenderTexture格式受到底层DrawableQueue API的限制。 当前测试的唯一格式是“R8G8B8A8_UNORM”(默认RenderTexture格式)和“R16G16B16A16_SFLOAT”。 其他格式可能有效,也可能无效;我们建议通过实验来找出答案。
批处理模式渲染
VisionOS 的混合现实应用程序以批处理模式运行,这说明摄像机不会自动渲染。 如果您使用RenderTexture作为摄像机的“Output Texture”,您可以使用以下脚本来确保摄像机每次更新渲染一次。
using UnityEngine;
using Unity.PolySpatial;
public class BatchModeUpdateRenderer : MonoBehaviour
{
Camera m_Camera;
void Start()
{
m_Camera = GetComponent<Camera>();
}
void Update()
{
if (Application.isBatchMode && m_Camera)
m_Camera.Render();
}
}
手动清理
如果您在调用“Camera.Render”之外更新 RenderTexture(例如,通过设置 [RenderTexture.active](https://docs.unity3d.com/ScriptReference/RenderTexture-active.html并调用即时模式渲染命令),PolySpatial将不会自动传输RenderTexture的新内容。 相反,您必须在更新的每个帧中使用“Unity.PolySpatial.PolySpatialObjectUtils.MarkDirty(renderTexture)”手动弄脏RenderTexture。 从而PolySpatial将RenderTexture的新内容发送到主机。
using UnityEngine;
using Unity.PolySpatial;
public class SetRenderTextureDirty : MonoBehaviour
{
public RenderTexture texture;
void Update()
{
Unity.PolySpatial.PolySpatialObjectUtils.MarkDirty(texture);
}
}