VR系列——Oculus Rift 开发者指南:四、高级渲染配置(一)

高级渲染配置

默认情况下,SDK为优化渲染质量生成配置值。

它也提供了一定程度的灵活性。例如,在创建渲染目标纹理的时候,你可以对它进行修改。

本节讨论的是,当在渲染质量及性能之间进行选择的时候,或者你正在使用的引擎有限制时你可以做的修改。

应对图形接口或硬件渲染目标粒度

SDK是以你想要尽可能小心地使用你的视频内存并且你可以根据你的需要创建正确的渲染目标大小为假设所设计的。

然而,真正的显卡和真正的图形API有大小限制(它们都有最大值限制;有些有最小值限制)。他们可能也有粒度的限制,例如,只能够创建尺寸是32像素的倍数的渲染目标,或在可能的长宽比上有限制。作为一个应用开发人员,你还可以额外加以限制,避免使用太多图形内存。

除了上述情况,内存中实际的渲染目标面大小可能不一定与被渲染的部分保持一致。后者可能会稍微小一些。然而,由于它被指定为一个视口,它一般不具有任何粒度限制。你绑定渲染目标作为纹理,但是,它是所使用是整个面,UV坐标(译者注:所有的图象文件都是二维的一个平面,水平方向是U,垂直方向是V,通过这个平面的二维的UV坐标系,我们可以定位图象上的任意一个象素)必须为渲染的尺寸和面的尺寸之间的差异进行修正。该API会为你做这个修正,但你需要告诉它相关的信息。

下面的代码展示了设置渲染目标分辨率的两阶段方法。代码首先调用ovr_GetFovTextureSize计算渲染目标的理想尺寸。接下来,调用图形库创建一个期望的分辨率的渲染目标。一般来说,由于平台和硬件的特性,由此产生的纹理大小可能和要求的不同。

// 获得推荐的左眼和右眼渲染目标的大小。
Sizei recommenedTex0Size = ovr_GetFovTextureSize(session, ovrEye_Left,
session->DefaultEyeFov[0], pixelsPerDisplayPixel);
Sizei recommenedTex1Size = ovr_GetFovTextureSize(session, ovrEye_Right,
session->DefaultEyeFov[1], pixelsPerDisplayPixel);
// 确定适合单个渲染目标的大小。
Sizei renderTargetSize;
renderTargetSize.w = recommenedTex0Size.w + recommenedTex1Size.w;
renderTargetSize.h = max ( recommenedTex0Size.h, recommenedTex1Size.h );
// 创建纹理。
pRendertargetTexture = pRender->CreateTexture(renderTargetSize.w, renderTargetSize.h);
// 实际的渲染目标大小可能由于硬件的限制而有所不同
renderTargetSize.w = pRendertargetTexture->GetWidth();
renderTargetSize.h = pRendertargetTexture->GetHeight();
// 初始化眼睛渲染信息。
// 重新计算视窗尺寸,以防由于硬件的局限性导致渲染目标大小的改变。
ovrFovPort eyeFov[2] = { session->DefaultEyeFov[0], session->DefaultEyeFov[1] };

EyeRenderViewport[0].Pos  = Vector2i(0,0);
EyeRenderViewport[0].Size = Sizei(renderTargetSize.w / 2, renderTargetSize.h);
EyeRenderViewport[1].Pos  = Vector2i((renderTargetSize.w + 1) / 2, 0);
EyeRenderViewport[1].Size = EyeRenderViewport[0].Size;  

这一数据作为描述层的一部分被传递到ovr_SubmitFrame。

你可以自由选择你喜欢的渲染目标纹理的大小和左、右眼视口,在调用ovr_SubmitFrame使用ovrTexture时提供你指定的这些值。但是,调用ovr_getfovtexturesizeq可以确保你为使用中的HMD(译者注:头盔显示器Head Mount Display)配置了最佳尺寸。下面的章节将介绍如何修改默认的配置,使得质量和性能相权衡。还应该注意的是,如果你的引擎要求的话,API能够为每只眼睛使用不同的渲染目标(虽然使用单一的渲染目标的性能可能会更好,因为它能减少上下文的切换)。OculusWorldDemo允许你通过导航进入设置菜单(按Tab键) 并且选择共用渲染目标(Share RenderTarget)选项来在单一的组合渲染目标与每只眼睛单独的渲染目标之间进行切换。


原文如下


Advanced Rendering Configuration

By default, the SDK generates configuration values that optimize for rendering quality.

It also provides a degree of flexibility. For example, you can make changes when creating render target textures.

This section discusses changes you can make when choosing between rendering quality and performance, or if the engine you are using imposes constraints.

Coping with Graphics API or Hardware Rendertarget Granularity

The SDK is designed with the assumption that you want to use your video memory as carefully as possible and that you can create exactly the right render target size for your needs.

However, real video cards and real graphics APIs have size limitations (all have a maximum size; some also have a minimum size). They might also have granularity restrictions, for example, only being able to create render targets that are a multiple of 32 pixels in size or having a limit on possible aspect ratios. As an application developer, you can also impose extra restrictions to avoid using too much graphics memory.

In addition to the above, the size of the actual render target surface in memory might not necessarily be the same size as the portion that is rendered to. The latter may be slightly smaller. However, since it is specified as a viewport, it typically does not have any granularity restrictions. When you bind the render target as a texture, however, it is the full surface that is used, and so the UV coordinates must be corrected for the difference between the size of the rendering and the size of the surface it is on. The API will do this for you, but you need to tell it the relevant information.

The following code shows a two-stage approach for settings render target resolution. The code first calls ovr_GetFovTextureSize to compute the ideal size of the render target. Next, the graphics library is called to create a render target of the desired resolution. In general, due to idiosyncrasies of the platform and hardware, the resulting texture size might be different from that requested.

// Get recommended left and right eye render target sizes.
 Sizei recommenedTex0Size = ovr_GetFovTextureSize(session, ovrEye_Left,
 session->DefaultEyeFov[0], pixelsPerDisplayPixel);
 Sizei recommenedTex1Size = ovr_GetFovTextureSize(session, ovrEye_Right,
 session->DefaultEyeFov[1], pixelsPerDisplayPixel);
 // Determine dimensions to fit into a single render target.
 Sizei renderTargetSize;
 renderTargetSize.w = recommenedTex0Size.w + recommenedTex1Size.w;
 renderTargetSize.h = max ( recommenedTex0Size.h, recommenedTex1Size.h );
 // Create texture.
 pRendertargetTexture = pRender->CreateTexture(renderTargetSize.w, renderTargetSize.h);
 // The actual RT size may be different due to HW limits.
 renderTargetSize.w = pRendertargetTexture->GetWidth();
 renderTargetSize.h = pRendertargetTexture->GetHeight();
 // Initialize eye rendering information.
 // The viewport sizes are re-computed in case RenderTargetSize changed due to HW limitations.
 ovrFovPort eyeFov[2] = { session->DefaultEyeFov[0], session->DefaultEyeFov[1] };
 EyeRenderViewport[0].Pos = Vector2i(0,0);
 EyeRenderViewport[0].Size = Sizei(renderTargetSize.w / 2, renderTargetSize.h);
 EyeRenderViewport[1].Pos = Vector2i((renderTargetSize.w + 1) / 2, 0);
 EyeRenderViewport[1].Size = EyeRenderViewport[0].Size;

This data is passed into ovr_SubmitFrame as part of the layer description.

You are free to choose the render target texture size and left and right eye viewports as you like, provided that you specify these values when calling ovr_SubmitFrame using the ovrTexture. However, using ovr_GetFovTextureSize will ensure that you allocate the optimum size for the particular HMD in use. The following sections describe how to modify the default configurations to make quality and performance tradeoffs. You should also note that the API supports using different render targets for each eye if that is required by your engine (although using a single render target is likely to perform better since it will reduce context switches). OculusWorldDemo allows you to toggle between using a single combined render target versus separate ones for each eye, by navigating to the settings menu (press the Tab key) and selecting the Share RenderTarget option.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值