Page 1 of 2

3D Anaglyph compositor

Posted: Sun Jul 13, 2014 10:39 pm
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!

Re: 3D Anaglyph compositor

Posted: Mon Jul 14, 2014 12:15 am
by Samuel
Very nice example! :D

CreateRenderTexture with shaders can be a very powerful combination.

I'll have to start experimenting more with them.

Re: 3D Anaglyph compositor

Posted: Mon Jul 14, 2014 6:51 am
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

Re: 3D Anaglyph compositor

Posted: Mon Jul 14, 2014 9:02 am
by Bananenfreak
Great! If it´s possible to integrate it easily, I will use it in my Project :D

Re: 3D Anaglyph compositor

Posted: Mon Jul 14, 2014 12:00 pm
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

Re: 3D Anaglyph compositor

Posted: Mon Jul 14, 2014 12:11 pm
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. :-)

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 7:39 am
by Bananenfreak
@Dige:
You need Nvidias CG-toolkit (dll).

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 10:10 am
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.

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 10:20 am
by applePi

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 10:42 am
by dige
It works! :-) Very nice. But why, it cannot run with ogre only?

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 11:38 am
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.

Re: 3D Anaglyph compositor

Posted: Tue Jul 15, 2014 6:05 pm
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.

Re: 3D Anaglyph compositor

Posted: Wed Jul 16, 2014 10:51 am
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

Re: 3D Anaglyph compositor

Posted: Wed Jul 16, 2014 6:38 pm
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.

Re: 3D Anaglyph compositor

Posted: Wed Jul 16, 2014 8:39 pm
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 ?