Povray, Anaglyphs, and Euler

Recently, I added a Povray interface to Euler, so that users can easily produce photo-realistic scenes with functions or other objects. Here are some examples. Since Euler could do red/cyan anaglyphs since a long time, I wanted that for Povray scenes too. However, Povray does not support this out of the box (though I feel it should). I finally was able to achieve this, but it was not trivial.

First an example. You need red/cyan glasses to appreciate the 3D effect.

Here is a short report, how I did that, and what problems there are.

First an overview: Povray must run twice from different camera positions. I produce two scene files with Euler, let both be parsed by Povray, and get two PNG files. These two images are combined into a red/cyan anaglyph in Euler, and inserted into the Euler notebook.

The first problem is the position of the two cameras for each eye. E.g., I want a camera looking to the center of the image, 20° upwards from the horizontal plane, and 50° to the right of the x-axis. Now, I cannot simply turn the camera left and right a bit more for each eye. This would obviously fail if the camera is 90° upwards looking straight down.

In Euler, I solve this problem by turning the scene. It is first turned left or right, then tilted up or down, and finally turned left and right for each eye.

In Povray, we need to turn the camera. So I put the above movements in a matrix (multiplying the turning matrices), and compute the inverse of this matrix. Then I move the camera position with the inverted matrix. I also move the „sky“. This is a vector pointing upwards from the camera top. I move it by the same inverted matrix, tilting the matrix correctly. This yields very good results, and it works even if the camera is upwards more than 90° from the horizontal plane. If you want to study the details, look into the Euler file povray.e at the function „writeCamera“.

The next problem is combining the two images to an anaglyph. There are several public domain programs and Photoshop actions available to this. I use a simple code, combining the color bits from both images in C++. For the details look into the source code of Euler at the file „images.cpp“.

That’s all not easy. So I feel, Povray should get this as a feature.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.