Native Rendering plugin with Oculus Rift

I am working on a project that uploads some rendering to a native plugin that I wrote for Unity, in order to use instances and other advanced graphical functions. I am developing it for cross-platform release, but I work with Mac, so testing is done primarily with OpenGL. At the moment, the plugin displays only a square in the center of the screen, colored with hexadecimal values. The plugin works as expected in an empty Unity project, but as soon as I include it in my Oculus project, it starts to behave erratically.

In a rift, the geometry of the plug-in draws twice, stretches once to both eyes and another time pattern only within the right eye. Also, any primitive colors that I apply to geometry are lost, and the geometry seems to capture the surrounding colors; on a black screen with red text, the geometry will be mostly black with red blood flow in line. As soon as my green area loads, the geometry drawn by the plugin will turn green.

Below is a screenshot of the geometry created in an empty Unity project where there is nothing:

Blank unity project

And here is a screenshot of the same geometry as at the top of my Oculus Rift application:

Native rendering on top of Oculus Rift

Here the vertices that I execute are created (three coordinates and color):

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 }, }; 

Here's the draw function, called each frame inside the plugin:

 // 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); } 

Any insight from experienced plugin / rift graphic encoders will be appreciated!

+8
plugins rendering unity3d opengl oculus
source share
1 answer

You can use Unity UI to render sprites according to your needs. Here is an article from Oculus that describes how to set up the Unity UI system for VR: https://developer.oculus.com/blog/unitys-ui-system-in-vr/

Outside of Oneness, you would use four layers to render over FOV eyes. Here are the layers described in the Oculus Rift documentation: https://developer.oculus.com/documentation/pcsdk/latest/concepts/dg-render/#dg_render_layers

Four layers:

A monoscopic image that appears as a rectangle with a given pose and size in the virtual world. This is useful for heads-up displays, textual information, object labels, etc. By default, the pose is relative to the user space of the real world, and the square will remain motionless in space, rather than moving with the movement of the user's head or body. For ATVs, use the ovrLayerFlag_HeadLocked flag, as described below.

0
source share

All Articles