StereoEffect.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @authod mrdoob / http://mrdoob.com/
  4. * @authod arodic / http://aleksandarrodic.com/
  5. * @authod fonserbc / http://fonserbc.github.io/
  6. */
  7. THREE.StereoEffect = function ( renderer ) {
  8. var _stereo = new THREE.StereoCamera();
  9. _stereo.aspect = 0.5;
  10. this.setEyeSeparation = function ( eyeSep ) {
  11. _stereo.eyeSep = eyeSep;
  12. };
  13. this.setSize = function ( width, height ) {
  14. renderer.setSize( width, height );
  15. };
  16. this.render = function ( scene, camera ) {
  17. scene.updateMatrixWorld();
  18. if ( camera.parent === null ) camera.updateMatrixWorld();
  19. _stereo.update( camera );
  20. var size = renderer.getSize();
  21. if ( renderer.autoClear ) renderer.clear();
  22. renderer.setScissorTest( true );
  23. renderer.setScissor( 0, 0, size.width / 2, size.height );
  24. renderer.setViewport( 0, 0, size.width / 2, size.height );
  25. renderer.render( scene, _stereo.cameraL );
  26. renderer.setScissor( size.width / 2, 0, size.width / 2, size.height );
  27. renderer.setViewport( size.width / 2, 0, size.width / 2, size.height );
  28. renderer.render( scene, _stereo.cameraR );
  29. renderer.setScissorTest( false );
  30. };
  31. };