gpt4 book ai didi

opengl - 带有 Oculus Rift 的原生渲染插件

转载 作者:行者123 更新时间:2023-12-04 08:55:20 25 4
gpt4 key购买 nike

我正在开发一个项目,该项目将一些渲染卸载到我为 Unity 编写的 native 插件,以便利用实例化和其他高级图形功能。我正在为跨平台版本开发它,但我使用的是 Mac,因此测试主要使用 OpenGL 完成。此时,插件仅将四边形渲染到屏幕中心,用十六进制值着色。该插件在一个空白的 Unity 项目中按预期工作,但是一旦我将它合并到我的 Oculus 项目中,它就开始表现异常。

在 Rift 中,插件的几何图形绘制了两次,一次横跨双眼,另一次仅在右眼范围内绘制。此外,我应用于几何的任何原始颜色都会丢失,并且几何似乎会拾取周围的颜色;在带有红色文本的黑色屏幕上,几何图形大部分是黑色的,线条中会渗入一些红色。我的绿色地形一加载,插件绘制的几何图形就会变成绿色。

下面是在空白 Unity 项目中绘制的几何图形的屏幕截图,没有其他内容:

Blank Unity project

这是在我的 Oculus Rift 应用程序上绘制的相同几何图形的屏幕截图:

Native rendering on top of Oculus Rift

这是我正在渲染的顶点的创建(三个坐标和颜色):

Vertex verts[4] =
{
{ -0.5f, 0.5f, 0, 0xFF0000ff },
{ 0.5f, 0.5f, 0, 0xFFff0000 },
{ 0.5f, -0.5f, 0, 0xFF00ff00 },
{ -0.5f, -0.5f, 0, 0xFFff0000 },
};

这是绘制函数,在插件中的每一帧都被调用:
// OpenGL case
if (g_DeviceType == kGfxRendererOpenGL)
{
//initialize model view matrices
glMatrixMode (GL_MODELVIEW);
float modelMatrix[16] =
{
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
};
glLoadMatrixf (modelMatrix); //assign our matrix to the current MatrixMode

//initialize projection matrix
glMatrixMode (GL_PROJECTION);
projectionMatrix[10] = 2.0f; //tweak projection matrix to match D3D
projectionMatrix[14] = -1.0f;
glLoadMatrixf (projectionMatrix);

// Vertex layout
glVertexPointer (3, GL_FLOAT, sizeof(verts[0]), &verts[0].x);
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (4, GL_UNSIGNED_BYTE, sizeof(verts[0]), &verts[0].color);
glEnableClientState (GL_COLOR_ARRAY);

glDrawArrays(GL_LINE_LOOP, 0, 4);

}

经验丰富的原生插件/Rift 图形编码人员的任何见解将不胜感激!

最佳答案

您可以根据需要使用 Unity UI 系统来渲染 Sprite 。这是一篇来自 Oculus 的文章,描述了如何为 VR 调整 Unity UI 系统:https://developer.oculus.com/blog/unitys-ui-system-in-vr/

在 Unity 之外,您将使用四边形图层在眼睛 FOV 上进行渲染。以下是 Oculus Rift 文档中描述的层:https://developer.oculus.com/documentation/pcsdk/latest/concepts/dg-render/#dg_render_layers

四层:

A monoscopic image that is displayed as a rectangle at a given pose and size in the virtual world. This is useful for heads-up-displays, text information, object labels and so on. By default the pose is specified relative to the user's real-world space and the quad will remain fixed in space rather than moving with the user's head or body motion. For head-locked quads, use the ovrLayerFlag_HeadLocked flag as described below.

关于opengl - 带有 Oculus Rift 的原生渲染插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26594208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com