GithubHelp home page GithubHelp logo

cinder-cardboard's Introduction

Cinder-Cardboard

Google Cardboard VRview exported to C++ for use with Cinder 0.9.

This block is designed to quickly build/test out VR apps with Cinder for iOS. (Android helps are welcome.) The block supports both vertex distortion and fragment distortion. For more information on these 2 different methods, please read: VR DISTORTION CORRECTION USING VERTEX DISPLACEMENT

Namespace

All code has been wrapped inside cinder::cardboard.

Usage

This block need to be used with the MotionManager block at the same time. Though if you only want to test the lens distortion, this block will run on desktop devices as well.

User Vertex Distortion

Image

Initialization
void VRApp:setup(){
  mHmd = Hmd::create(CardboardVersion::VERSION_2, true);
  mDistorter = mHmd->getVertexDistorter();
  
  //generate shaders using VertexDistorter's helper function
  mShader = mDistorter->createDistortionShader(loadAsset("phong.vert"), loadAsset("phong.frag"));
}

In your vertex shader, you need to add this include

#include "VertexDistortion"

And before you output gl_Position, use this function

gl_Position = Distort(position);

to distort your vertex positions.

Render

The benefit of using vertex distortion is it doesn't need an FBO, so you could do rendering by only 1 pass.

void VRApp:drawp(){
  mHmd->bindEye(Eye::LEFT);
  mDistorter->setDistortionUniforms(mShader); //this will set distortion uniforms
  drawScene(); //draw you objects
    
  mHmd->bindEye(Eye::RIGHT);
  mDistorter->setDistortionUniforms(mShader);
  drawScene();
    
  mHmd->unbind(); //unbind hmd to restore 2D viewport/matrices
}

Use Fragment Distortion

Image

Initialization
void VRApp:setup(){
  mHmd = Hmd::create(CardboardVersion::VERSION_2, false);
}
Render scene

When using fragment distortion, you need to draw your scenes firstly into the fbo.

void VRApp:update(){
  //bing and draw for each eye
  mHmd->bindEye(Eye::LEFT);
  drawScene();
  mHmd->bindEye(Eye::RIGHT);
  drawScene();
  //unbind hmd so it unbind the fbo internally
  mHmd->unbind();
}

And then you need to draw the output fbo inside the draw function

void VRApp:draw(){
  mHmd->render();
}

Note

Vertex and Fragment distortion usually yields different results. See the reading VR DISTORTION CORRECTION USING VERTEX DISPLACEMENT, so this is uninteded that you mix 2 methods at the sametime. Therefore once the Hmd is created, you can not change the distortion method.

cinder-cardboard's People

Contributors

seph14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.