我在一個非常簡單的DirectX11渲染引擎上工作了一段時間。今天,我設法爲我的Oculus Rift集成安裝立體渲染(將場景渲染成紋理)。在簡單的DirectX引擎中集成Oculus SDK Distortion
[當前] 那麼我基本上做的是目前:
- 我有一個1280 x 800的窗口
- 渲染整個場景到RenderTargetViewLeft_(1280×800)
- 將RenderTargetViewLeft_的內容渲染爲屏幕左側的「EyeWindow」(如教程中所示)(640 x 800)渲染整個場景到RenderTargetViewRight_(1280 x 800)
- 渲染RenderTargetViewRight_的內容爲「EyeWindow」(像教程)的屏幕(640×800)
所以所有的到目前爲止是這種情況的右側,我得到了渲染的場景兩次進入獨立紋理,最後進入分割畫面。
[DirectX11的渲染循環]
bool GraphicsAPI::Render()
{
bool result;
// [Left Eye] The first pass of our render is to a texture now.
result = RenderToTexture(renderTextureLeft_);
if (!result)
{
return false;
}
// Clear the buffers to begin the scene.
BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Turn off the Z buffer to begin all 2D rendering.
TurnZBufferOff();
// Render The Eye Window orthogonal to the screen
RenderEyeWindow(eyeWindowLeft_, renderTextureLeft_);
// Turn the Z buffer back on now that all 2D rendering has completed.
TurnZBufferOn();
// [Right Eye] ------------------------------------
result = RenderToTexture(renderTextureRight_);
if (!result)
{
return false;
}
TurnZBufferOff();
RenderEyeWindow(eyeWindowRight_, renderTextureRight_);
TurnZBufferOn();
// [End] Present the rendered scene to the screen.
EndScene(); // calls Present
return true;
}
[我想現在要做] 現在我想實現一個桶形畸變與魔環SDK。目前,我並不關心第二張圖片的不同虛擬相機,只是想現在就實現桶形失真。
我已閱讀開發人員指南[1],並試圖研究TinyRoom演示,但我完全不明白現在需要使用已在使用的DirectX引擎中的SDK實現失真。
開發人員指南渲染紋理初始化,它們顯示瞭如何爲API創建紋理。我想這意味着,我需要設置所有我的RendertargetViews與相應的API大小(渲染目標目前大小爲1280 x 800) - 甚至改變DepthStencilView和Backbuffer sice,我也想。
渲染環會是這個樣子,那麼:
ovrHmd_BeginFrame(hmd, 0);
BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
...
// Render Loop as the Code above
...
ovrHmd_EndFrame(hmd, headPose, EyeTextures);
// EndScene(); // calls Present, not needed on Oculus Rendering
我覺得有什麼遺漏,所以我相信我不會把所有這種權利。
[更新] 所以,我使用Oculus API實現了使用桶形失真渲染場景。雖然左右圖像的多邊形太分離,但這可能是由於我的默認1280 x 800紋理大小用於渲染目標。當移動HMD時,CameraStream似乎也不會與屏幕正交。會做一些進一步的測試;)
[1] - Oculus公司開發指南:https://developer.oculus.com/documentation/