SBS (S3D) and Top/Bottom StereoRenderMethods - code attached

Software: Away3D 4.x

Bibek S, Newbie
Posted: 23 January 2013 03:12 AM   Total Posts: 3

Hi all,

Inside the attached .zip file:, and

Away3D 4.1Alpha has a new stereoscopic rendering framework.  The problem is it doesn’t support side-by-side (SBS) stereoscopic rendering.  As near as I can tell, SBS is one of the most common rendering methods, used by 3D TVs, Head-Mounted-Displays (HMDs), etc.  And in particular, for /my/ application, I need SBS-rendering.

In the past, I’ve been using 2 Views, one for each eye.  This still works on the desktop, but it killed my mobile app.  In contrast, Away3D-4.1’s stereoscopic support works on my mobile devices.  So, I spent the last two days implementing an SBSStereoRenderMethod class for Away3D-4.1, then tweaked it a bit to create TopBottomStereoRenderMethod.

Please understand that this is the first time that I’ve worked with shaders.  I know of at least one bug in my code - there’s some dead space between the images that isn’t supposed to be there.  There may be other bugs.  I make no guarantees about the quality or the usability of the attached code.

I attempted to heavily document my AGAL code.  It took me forever to work backwards from the assembly-langauge AGAL code, and I’m hoping my documentation can help others not only to understand my code, but also hopefully to gain a better understanding of the fragment-shader code in AnaglyphStereoRenderMethod and InterleavedStereoRenderMethod.  But again: I make no guarantees.

(Also: I have a commented version of the fragment shader code in, if anyone’s interested.  The only difference is the comments.)

If anyone knows what’s up with the bar in the middle with these render methods, I would love to hear it.  Better yet, if you can offer a patch, I would greatly appreciate it.

Licensing: I consider my own work on this to be public-domain.  That said, this is based on code from Away3D-4.x, so the full files are under Away3D’s license (Apache-2.0).

All the best,


File Attachments  (File Size: 3KB - Downloads: 632)

seanClusta, Jr. Member
Posted: 07 July 2014 10:01 AM   Total Posts: 38   [ # 1 ]

Hi Bibek.
I know this was a long time ago and you’ve probably forgotten all about it! I’m looking at building an SBS rendering system on away3D to combine with the new android VR Toolkit - hopefully i will create an ANE to bring the sensor data in and turn the handset into a VR headset.
I was looking into how to do this and came across your custom method. I’ve plugged it in and although it works by duplicating the fragments to the left and right side of the screen - there seems to be an issue with the vertex data being stretched along the y axis? When trying to render a cube it renders as a box stretched along the y (see image).
Was this happening to your version? Any ideas what’s causing this? I tried adjusting your constants in the fragment shader but couldn’t get it to render properly.
Although I’m new to AGAL and shader coding I will have a go at trying to fix it myself and adapting it for the VR toolkit, but any help to fast-track this would be appreciated.
I’ll post up any updates I make.



Image Attachments

theMightyAtom, Sr. Member
Posted: 07 July 2014 11:13 AM   Total Posts: 669   [ # 2 ]

Hi Sean, I’ve implemented this myself for use with Google Cardboard, etc.
Rather than making a new shader I simply used a shared Stage3D and copied the scene from one eye to the other. Works like a charm smile
In order to get distance between I shift the camera apart from each other.
This means you can use all the other features of Away without any issues.

Here’s a code sample. Mine is mixed in with an ANE for device orientation (doesn’t work that well so I’d like to see what you come up with! smile
May need tweeking for your own situation.

   * Initialise the Stage3D proxies
private function initProxies():void
// Define a new Stage3DManager for the Stage3D objects
stage3DManager Stage3DManager.getInstance(stage);
// Create a new Stage3D proxy to contain the separate views
stage3DProxy stage3DManager.getFreeStage3DProxy();
stage3DProxy.antiAlias 0;
stage3DProxy.color 0xFFFFFF;
private function init3D():void
= new View3D()
leftEye.width stage.stageHeight;
leftEye.height _width 2;
leftEye.backgroundColor 0xFF0000; = new Camera3D();
/* = 0; = 0; = -1000; new Vector3D(0, 0, 0) );*/
_lensL = new PerspectiveLens(60); _lensL;
_lensL.far 21000000;
dolly = new ObjectContainer3D();
leftEye.stage3DProxy stage3DProxy;
leftEye.shareContext true;
addChildleftEye );
rightEye = new View3D()
rightEye.width stage.stageHeight;
rightEye.height _width/2;
rightEye.backgroundColor 0xFF0000; = new Camera3D();
_lensR = new PerspectiveLens(); _lensR;
_lensR.far 21000000;
rightEye.stage3DProxy stage3DProxy;
rightEye.shareContext true;
rightEye.scene leftEye.scene;
addChildrightEye );

// then on every frame....

public function redraw(e:Event):void{
var q:Quaternion = new Quaternionevent.values[1]event.values[2]event.values[3]event.values[0] );
m:Matrix3D q.toMatrix3D();
positionMatrix.position dolly.position;
   m; m;
//add stereoscopic seperation;;


How you move your cameras will depend on how your ANE and Away3D coordinate systems are aligned. Good idea to convert to portrait mode, or even better make it optional.

For the Java code, I would recommend you use the Sensor Fusion code by Alexander Pacha (MIT license).

(Improved Orientation Sensor 2 seems best to me!)

Good luck!

Remember to send me an ANE for testing! :O)




seanClusta, Jr. Member
Posted: 07 July 2014 11:19 AM   Total Posts: 38   [ # 3 ]

Excellent! I’ll try it out now!

So I assume you’ve not used the sensor data from the VR toolkit API yet?
I’ll try and get it integrated and see if I can get the orientation and responsiveness as lean as they have in the native cardboard app. I was at Google i/o and grabbed a cardboard headset, the app is really responsive though it obviously uses native OpenGL ES API so maybe there will be performance issues when using AIR and sensor fusion together?




theMightyAtom, Sr. Member
Posted: 07 July 2014 11:28 AM   Total Posts: 669   [ # 4 ]

If there are performance issues, I haven’t run into them yet smile
Have only been running simple scenes and panoramas.
I built the same scene up in Unity3D and AIR and could see absolutely no difference performance wise. Latency was less than Rift Development Kit 1. Haven’t tried their latest. With my Oppo Find 7, quadHD, how could I ever go back to the pixelated rift? wink

I was hoping someone with more java experience would take this up for AIR.
I wish you the very best, and if you need any sparring on the AS3 side, I’m your man.




seanClusta, Jr. Member
Posted: 07 July 2014 11:58 AM   Total Posts: 38   [ # 5 ]

Ah, when you said ‘doesn’t work that well’ i thought you meant there were issues like performance or lag. You meant the ANE as a whole.
Great, I’m no expert but have a bit of experience with native android and building ANE’s. Pretty confident I should be able to get that integrated nicely.
I totally agree, when I used the cardboard VR with a Nexus 5 the image quality and responsiveness were far better than the OR v1. Glad to hear you’ll be there to help on anything AS3. I’ll definitely keep you posted as to my progress or if I have any questions. Hopefully later today as I have a couple spare hours


‹‹ Better Documentation


Away3D Forum

Member Login