r/oculusdev • • Aug 04 '14

Oculus DK2-WebGL WebSocket Bridge

https://mega.co.nz/#!gBZVDI7L!QxBESxUaDuFMUcr6F0ERwC70EGk8whjIGXfWhJWxVXE Here's a build of an Oculus DK2 WebSocket broadcaster I am working on, that opens a websocket on localhost port 38950 and streams the HMD's rotation quaternion and position vector as a json packet. This is a VERY rough implementation but is enough to get a flakey connection between the dk2 hmd and a webgl app. Please wrap your JSON parse in an exception handler because of a bug in the packet stream that sometimes loses the last character of the json being sent... Let me know if you find this useful and I can give you the source or help with integration..

EDIT: A reminder from r/pyalot: There are existing browser VR extensions in the developer builds of Chrome/FireFox. These should be used in place of any workarounds like mine for more performant and full featured browser support. My bridge is just a hack to quickly snoop the computed eye position/orientation from the SDK to a websocket and use that to update a gl view matrix in any websocket supporting browser.

Mozilla Firefox Rift integration: http://blog.bitops.com/blog/2014/07/31/css-and-vr-integration/ Google Chrome Rift integration: http://blog.tojicode.com/2014/07/bringing-vr-to-chrome.html

Caveat: This is currently only streaming the position of one eye, forcing the client to implement the ipd/eye matrix transforms in addition to the streamed data. The SDK actually reports pos/rot for each eye, so I will start streaming both in the next rev I make.

6 Upvotes

13 comments sorted by

3

u/pyalot Aug 04 '14

I'll just leave these here:

1

u/irascible Aug 04 '14

Yeah I saw those..

AFAIK the chrome integration is for DK1, and is an experimental build of chrome. The Firefox version says it supports DK2. Those integrations also provide distortion shaders and a bunch of other vr supporting functions.

The bridge I wrote is just something simple that works with current browsers. The latency is probably a lot worse than the browser implementations as well.

I just made this app as a thin bridge that works with current browsers, to get the HMD position/orientation data directly from the Oculus SDK. It is a modified OculusRoomTiny sample, with rendering disabled, and a websocket server grafted onto it.

2

u/pyalot Aug 04 '14

AFAIK the chrome integration is for DK1, and is an experimental build of chrome. The Firefox version says it supports DK2. Those integrations also provide distortion shaders and a bunch of other vr supporting functions.

Chrome hasn't updated to the new SDK yet, but I'm sure Brandon is working on it as we speak. Firefox doesn't use the 0.4 SDK either (yet) but they've got a newer one deployed than Chrome.

he latency is probably a lot worse than the browser implementations as well.

The latency of solutions like this is usually pretty bad.

I just made this app as a thin bridge that works with current browsers, to get the HMD position/orientation data directly from the Oculus SDK. It is a modified OculusRoomTiny sample, with rendering disabled, and a websocket server grafted onto it.

Once the browsers update to a newer SDK (and once oculus fixes their SDK), it'll be much better to use for these reasons:

  • They'll be able to talk to the HMD in direct mode, so no worries about placing the window on the right screen in fullscreen

  • Browsers are limited to 60fps. They're working on making it happen that things will tick over when talking to the HMD at 75hz.

  • Latency is pretty bad in browsers, so one thing they're working on is to get rid of all the gunk that makes that so, this involves coalescing all functionality (JS engine, WebGL bindings, GPU process, input handling etc.) into a single process without IPCs between. Switching from a proxy context to a real context for HMD mode.

1

u/irascible Aug 04 '14

Yep. I totally agree.

Having said that.. I've gotten some test webgl apps running on my DK2 with this bridge.. the latency is noticable.. there is some judder, but it worked well enough to check out my GL world stereoscopically.. I haven't even worked on doing proper distortion/chromatic abberation shaders in my webgl apps, but they are still surprisingly immersive and playable.

Definitely looking forward to full browser implementations!

Another funny realization I've had is that browsers handle the display integration better than most Oculus demos I've played. You just drag the window down to the extended rift display, and hit f11 fullscreen. I'm enjoying this experimentation!

3

u/48K Aug 04 '14

I have high hopes for browser-based VR for this reason - quick and dirty projects. All the other options are SO heavy, even for professional programmers.

2

u/48K Aug 04 '14

These plug-ins will often lag behind what's possible in VR hardware, so there's definitely a place for hackable options like this.

2

u/pyalot Aug 04 '14

They're not plug-ins. They're integrations, by the browser vendors, with the VR hardware's SDK.

2

u/48K Aug 04 '14

Sorry, poor choice of words. What I meant was that to use Firefox or Chrome in this way you have to install something, in this case an entire replacement version of the browser.

2

u/pyalot Aug 04 '14

Those are going to roll out to the release versions of browsers once the integrations are satisfactory.

3

u/48K Aug 04 '14

Open sourcing this would make it more compelling and someone might be able to fix your lost character issue for you.

1

u/irascible Aug 04 '14 edited Aug 04 '14

Yep. It's on my list. I just wanted to put a build out there because it works well enough to make webgl walkthroughs demos as is. When I throw it on github, I'll update this thread.

The whole webgl integration is this:

var eyeLocal = mat4.create();
var url = "ws://127.0.0.1:38950"
var ws= new WebSocket(url);
ws.onmessage=function(evt){
        if (typeof evt !== "undefined" && typeof evt.data == "string") {
            var str = evt.data.toString();
            try{
                var packet = JSON.parse(str);
                var lq=packet.L.O;
                var lo=packet.L.P;
                quat4.toMat4(lq,eyeLocal);
                mat4.translate(eyeLocal,[lo[0]*-1,lo[1]*-1,lo[2]*-1]);
            {
            catch(syntaxError){
                console.log("Bad Packet!");
                console.log(str);
            }
        }
}

and then in the rendering code after computing the regular left/right eye view matrix in your app, catenate the HMD view matrix to offset it by the transform of the HMDs position/orientation.

    mat4.multiply(eyeLocal,wglrenderer.vMatrix,wglrenderer.vMatrix);

Caveat: This is currently only streaming the position of one eye, forcing the client to implement the ipd/eye matrix transforms in addition to the streamed data. The SDK actually reports pos/rot for each eye, so I will start streaming both in the next rev I make.

3

u/48K Aug 04 '14

You may need to defer registering the onmessage handler until the connection is open. Typically this is done in an onopen handler. You might also want to register onerror and redirect it to the console at least. I doubt this is causing problems, but it's one possible cause of non-determinism you can eliminate in the hunt for your missing character.

1

u/irascible Aug 05 '14

Ah thanks! I'll fix that!