3D Anaglyph compositor

Everything related to 3D programming
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

3D Anaglyph compositor

Post by Kelebrindae »

Hi everyone,

Here's an anaglyph compositor I've made some time ago but forgot to post here (sorry).
Image
How does it work:
Two cameras, slightly apart and linked to a node, view the scene from two slightly different angles. The tricky part was to overlay the left view (red) and the right view (cyan).

- The "right" camera is used in a "CreateRenderTexture";
- This texture is named, so it can be passed in an Ogre script;
- The "left" camera uses a compositor, which render the scene and call a material to display it on screen;
- This material has two texture units: the one created by the compositor, and the named render-texture;
- These two texture are then passed to a shader, which converts them to greyscale and mix the red chanel from the left image and then green/blue channels from the right image;
- And the compositor displays the result fullscreen.

Maybe not the best method, but it works :wink: .

Here a zip with the source and the needed resources (textures, script, etc..)
http://keleb.free.fr/codecorner/downloa ... hCompo.zip

Have fun!
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Anaglyph compositor

Post by Samuel »

Very nice example! :D

CreateRenderTexture with shaders can be a very powerful combination.

I'll have to start experimenting more with them.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: 3D Anaglyph compositor

Post by applePi »

i don't have 3D glasses red/blue but i have positioned 2 red and greenish transparent plastic in front of my eyes and your cube looks like a true 3D object. i thought of something like that before but can't do it.
thank you
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: 3D Anaglyph compositor

Post by Bananenfreak »

Great! If it´s possible to integrate it easily, I will use it in my Project :D
Image
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: 3D Anaglyph compositor

Post by dige »

Does not work with PB5.30b7..

Code: Select all

12:59:25: *-*-* OGRE Initialising
12:59:25: *-*-* Version 1.8.2 (Byatis)
12:59:25: OGRE EXCEPTION(7:InternalErrorException): CG dll can't be loaded in CgPlugin::install at OgreCgPlugin.cpp (line 195)
12:59:25: *-*-* OGRE Shutdown
"Daddy, I'll run faster, then it is not so far..."
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: 3D Anaglyph compositor

Post by DK_PETER »

dige wrote:Does not work with PB5.30b7..

Code: Select all

12:59:25: *-*-* OGRE Initialising
12:59:25: *-*-* Version 1.8.2 (Byatis)
12:59:25: OGRE EXCEPTION(7:InternalErrorException): CG dll can't be loaded in CgPlugin::install at OgreCgPlugin.cpp (line 195)
12:59:25: *-*-* OGRE Shutdown
Hey dige.

Grab these dlls. They are a must for it to work. Unpack and place them at
the same location as the code.
Link removed - obsolete

Btw: nice example Kelebrindae. :-)
Last edited by DK_PETER on Tue Jul 15, 2014 11:37 am, edited 1 time in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: 3D Anaglyph compositor

Post by Bananenfreak »

@Dige:
You need Nvidias CG-toolkit (dll).
Image
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: 3D Anaglyph compositor

Post by dige »

@DK_PETER: Thanks, but unfortunately still does not work.

Windows 7 x86 says:

Code: Select all

cg.dll is either not designed to run on Windows or contains an error. Install the program using the original installation media again or consult your system administrator or software vendor for support.
"Daddy, I'll run faster, then it is not so far..."
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: 3D Anaglyph compositor

Post by applePi »

dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: 3D Anaglyph compositor

Post by dige »

It works! :-) Very nice. But why, it cannot run with ogre only?
"Daddy, I'll run faster, then it is not so far..."
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: 3D Anaglyph compositor

Post by DK_PETER »

dige wrote:It works! :-) Very nice. But why, it cannot run with ogre only?
Nvidia CG is a third party product: hence the need for the extra dlls.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Anaglyph compositor

Post by Samuel »

dige wrote:It works! :-) Very nice. But why, it cannot run with ogre only?
As DK_PETER said it's because the shader is in CG (Nvidia's shader language). If you want to get away from the DLL you can convert the CG shader to HLSL (windows only).
Since HLSL is pretty much identical to CG it should only take a few minutes to convert.
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: 3D Anaglyph compositor

Post by dige »

@Samuel: that would be great, if you could convert it to "ogre only". Unfortunately I have no idea of shader programming...
Someone in the forum had created a great view into an cathedral OGRE. I'll look and hope to finde the source again and would like to implement in stereo. :-)

Edit: http://www.purebasic.fr/english/viewtop ... 36&t=57871
"Daddy, I'll run faster, then it is not so far..."
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Anaglyph compositor

Post by Samuel »

Here's the HLSL version with Kelebrindae's example code.

anaglyphHLSL.zip

This version will only work on windows, but the cg.DLL will no longer be required.
Let me know if something doesn't look right.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: 3D Anaglyph compositor

Post by applePi »

this is certainly useful addition Samuel, someday i may learn some HLSL, but is it depends on specific DirectX 9 or works with any version ?
Post Reply