Page 1 of 2

Anaglyph rendering.

Posted: Mon May 04, 2009 12:53 pm
by Luke
hey, though I should post a bit of code I did lately for anaglyph rendering.

Code: Select all


void CGameEngine::drawAnaglyph()
{
    vector3df oldPosition=camera->getPosition();
	vector3df oldTarget=camera->getTarget();
	
	matrix4 startMatrix=camera->getAbsoluteTransformation();

	vector3df focusPoint= (camera->getTarget()-camera->getAbsolutePosition()).setLength(1) + camera->getAbsolutePosition() ;

	//Left eye...

	vector3df leftEye;
	matrix4 leftMove;
	leftMove.setTranslation( vector3df(-0.01f,0.0f,0.0f) );
	leftEye=(startMatrix*leftMove).getTranslation();

	//clear the depth buffer, and color
 	driver->beginScene( true, true, SColor(0,200,200,255) );

	driver->getOverrideMaterial().Material.ColorMask=ECP_RED;
	driver->getOverrideMaterial().EnableFlags=EMF_COLOR_MASK;
	driver->getOverrideMaterial().EnablePasses=ESNRP_SKY_BOX+ESNRP_SOLID+ESNRP_TRANSPARENT+ESNRP_TRANSPARENT_EFFECT+ESNRP_SHADOW;

    camera->setPosition( leftEye );
    camera->setTarget( focusPoint );

	draw(); // 'smgr->drawAll();' may go here


	//Right eye...

	vector3df rightEye;
	matrix4 rightMove;
	rightMove.setTranslation( vector3df(0.01f,0.0f,0.0f) );
	rightEye=(startMatrix*rightMove).getTranslation();

	//clear the depth buffer
	driver->clearZBuffer();

	driver->getOverrideMaterial().Material.ColorMask=ECP_GREEN+ECP_BLUE;
	driver->getOverrideMaterial().EnableFlags=EMF_COLOR_MASK;
	driver->getOverrideMaterial().EnablePasses=ESNRP_SKY_BOX+ESNRP_SOLID+ESNRP_TRANSPARENT+ESNRP_TRANSPARENT_EFFECT+ESNRP_SHADOW;

    camera->setPosition( rightEye );
	camera->setTarget( focusPoint );

    draw(); // 'smgr->drawAll();' may go here

    driver->endScene();

	driver->getOverrideMaterial().Material.ColorMask=ECP_ALL;
	driver->getOverrideMaterial().EnableFlags=0;
	driver->getOverrideMaterial().EnablePasses=0;

    camera->setPosition( oldPosition );

    camera->setTarget( oldTarget );

}
similar to the code by bob, here: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=32209

but fixes a few problems, and more irrlicht friendly.




Image

more images here

Posted: Mon May 04, 2009 1:02 pm
by hybrid
Wow, fantastic :D Actually, this was the thing I wanted to try out with the override material, but I failed to find proper glasses. So I postponed it - guess I have to buy some urgently!
We should probably set up a tutorial with this code.

Posted: Mon May 04, 2009 1:34 pm
by Malgodur
Its for 1.5? I got a bunch off errors...

Code: Select all

rror C2039: 'getOverrideMaterial' : is not a member of 'irr::video::IVideoDriver'

error C2228: left of '.Material' must have class/struct/union
etc

Posted: Mon May 04, 2009 1:47 pm
by Luke
We should probably set up a tutorial with this code.
yeah sounds good.
Its for 1.5? I got a bunch off errors...
hmm, you may have to use the svn or wait for 1.6. sorry I always work off the svn, I forget what is in each version.

Posted: Mon May 04, 2009 8:16 pm
by shadowslair
Haha! This is niiice... :)
I`ll better wait for 1.6 also. :?

Posted: Tue May 05, 2009 11:09 am
by wITTus
@hybrid: Check out ebay, there you can find tons of these glasses.

@Luke: This is almost a candidate for the screenshot of the month competition. Absolutely awesome 8). But is it real 3D? Normally the red and green bars around the objects should change their size with distance, shouldn't they? :?:

Posted: Tue May 05, 2009 11:19 am
by Luke
@Luke: This is almost a candidate for the screenshot of the month competition. Absolutely awesome Cool. But is it real 3D? Normally the red and green bars around the objects should change their size with distance, shouldn't they? Question
yeah it is real 3d, and they do change. The red and green bars, reverse at the focus point (the difference between poping out, and looking far away), so it may not look like they change in that image.

have a look at some of the other shots here (you can see the size changing better):

http://corrodinggames.com/forums/viewtopic.php?f=1&t=16

Posted: Tue May 05, 2009 1:04 pm
by wITTus
True. Did I already mention that this is awesome? :wink:

Your LUA stuff is also quite cool btw.
Was it hard to implement?

Posted: Tue May 05, 2009 3:20 pm
by CuteAlien
Meh. I urgently need red-green glasses!

Posted: Wed May 06, 2009 5:35 am
by BlindSide
Well if you want 3D glasses you can get em for 2 dollars with free shipping from here:

http://www.dealextreme.com/details.dx/s ... r.19022052

Yes thats my shamelessly tacked on referral id on the end there. :lol:

Posted: Wed May 06, 2009 2:49 pm
by CuteAlien
Hm, those are red-blue glasses. What will I need for that image here? Red-Green, Red-Blue, Red-XYZ?

Posted: Wed May 06, 2009 7:43 pm
by wITTus
In worst case, simply change the color within the code snippet :lol:

Posted: Thu May 07, 2009 1:36 am
by BlindSide
CuteAlien wrote:Hm, those are red-blue glasses. What will I need for that image here? Red-Green, Red-Blue, Red-XYZ?
I knew you would say that you pedantic **** :P

Actually they are Red-Cyan glasses, the title is misleading. And this is Red-Cyan anaglyph rendering (RED/GREEN+BLUE):

From luke's code:

Code: Select all

driver->getOverrideMaterial().Material.ColorMask=ECP_GREEN+ECP_BLUE; 
Yes I am hustlin' for my 1 DX point per 5 glass purchased. 8)

Posted: Thu May 07, 2009 2:03 am
by CuteAlien
BlindSide wrote:
CuteAlien wrote:Hm, those are red-blue glasses. What will I need for that image here? Red-Green, Red-Blue, Red-XYZ?
I knew you would say that you pedantic **** :P
Lol - purely innocent curiosity - I really had no idea :-)

Posted: Sun May 10, 2009 5:35 am
by thatdudeoverthere
i'm having a seizure... oh, the images just look like that anyhow good work. lol :)