In this chapter we'll cover stereoscopic rendering in V-Ray. We'll cover plugins, which can be used to achieve this effect - VRayStereoscopicSettings.
VrayStereoscopicSettings It is a helper plugin for stereoscopic (side by side) rendering. It turns the camera into 2 virtual cameras placed on some distance. It also implements Shademap mode: used to accelerate the stereoscopic rendering. It's also usable for accelerating DOF & motion blur.
Parameters The following parameters are located in the VRayStereoscopicSettings plugin:
eye_distance – Specifies the eye distance for which the stereoscopic image will be rendered. specify_focus – When enabled, defines the point of focus with the focus distance parameter. focus_method – Specifies one of the three following focus methods for the two views.None (0) – Both cameras have their focus points directly in front of them. Rotation (1) – The stereoscopic effect is achieved by rotating the left and right views so that their focus points coincide at the distance from the eyes where the lines of sight for each eye converge called fusion distance. Shear (2) – The orientation of both views remain the same but each eye's view is sheared along z so that the two frustums converge at the fusion distance. interocular_method – Specifies how the two virtual cameras will be placed in relation to the real camera in the scene.Shift both (0) – Both virtual cameras will be shifted in opposite directions at a distance equal to half of the eye distance. Shift left (1) – The virtual cameras are shifted to the left so that the right camera takes the position of the original camera. The left camera is shifted to the left at a distance equal to the eye distance. Shift right (2) – The virtual cameras are shifted to the right so that the left camera takes the position of the original camera. The right camera is shifted to the right at a distance equal to the eye distance. view – Specifies which of the stereoscopic views will be rendered.Both (0) – Both views will be rendered side by side. Left (1) – Only the left view will be rendered. Right (2) – Only the right view will be rendered. adjust_resolution – When enabled, this option will automatically adjust the resolution for the final image rendered. For example, if Both is selected for view and the specified image resolution for the render is 640x480, the resulting render will be a single image with a resolution of 1280x480 with both views side by side. output_layout – Specifies the format in which the Stereoscopic renders are output to the V-Ray frame buffer.Side-by-Side (0) – Arranges the cameras side by side. Top-Bottom (1) – Arranges the cameras one on top of another. left_camera - A camera plugin for the left eye; if not specified, the left camera is computed based on the scene camera. right_camera - A camera plugin for the right eye; if not specified, the right camera is computed based on the scene camera. film_offset_x_left - Horizontal film offset for the left camera film_offset_x_right - Horizontal film offset for the right camera film_offset_y_left - Vertical film offset for the left camera film_offset_y_right - Vertical film offset for the right camera Panoramic pole merging The options in this section are used when rendering a panoramic view with stereoscopy (for example a Spherical camera with FOV=360 degrees). These options allow us to avoid artifacts when looking upward and downward. This is achieved by gradually decreasing the eye distance and thus the stereoscopic effect. The eye distance value is kept the same until the viewing angle reaches the angles specified in the properties below after which the eye distance is gradually decreased until it reaches a value of 0 when looking directly downwards or upwards.
top_merge_angle - Panoramic pole merging: from what angle near the top does the stereo effect start to fade when rendering with a spherical panorama camera bottom_merge_angle - Panoramic pole merging: from what angle near the bottom does the stereo effect start to fade when rendering with a spherical panorama camera ShadeMap Parameters The shade map parameters can speed up the rendering of stereoscopic images as well as images with depth of field. The workflow with shade maps involves two stages. At the first stage a shade map is generated by setting the Shademap mode to Render shade map and rendering. The file in which the shademap will be saved needs to be specified by clicking on the Browse button before the actual rendering. This will save a file that contains important information about the visible shaded points. This information can be used later in Use shade map mode to render stereoscopic images or images with DoF much faster.
sm_mode - Allows us to specify the mode of operation for the shade map (0 - disabled; 1 - render shade map; 2 - use shade map). reuse_threshold - Lower values will make V-Ray use less of the shade map and more real shading. shademap_file - The name of the file in which the shade map information is stored. float_colors_mode - Store 32 bit (single precision) color channels in the shade map. When off 16 bit (half precision) values are stored. vrst_compression - Compression type for the .vrst files (0 - no compression, 1 - ZLIB compression) exr_compression - Compression type for the .exr files (0 - no compression, 1 - RLE compression, 2 - ZIPS compression) exclude_list - A list of plugins for which the shade map won't be used. exclude_list_inclusive - When on the exclude_list is considered as an "Include list" and when off the the Result Affect is considered as "Exclude list" General guidelines For spherical panorama rendering you need to:
Change the type parameter of SettingsCamera to 9. (Note that type=1 is spherical, but not for panoramas.) Set the field of view to 360 degrees or rather 2*pi, because the fov parameter is in radians. You need to do this with the RenderView plugin and with SettingsCamera - both have an fov parameter. Also if you're using CameraPhysical with specify_fov=1, set fov there too. Set the vertical field of view to 180 degrees. This may be a bit confusing: it is set through the height parameter of SettingsCamera. Also the value is not in radians, but in degrees. For cubic (6x1) panorama rendering you need to:
Change the type parameter of SettingsCamera to 10. Set a resolution with aspect ratio 6:1 (or 12:1 if you are doing stereo). So for a stereo cubic panorama with 1000x1000 pixel cube sides you will render at 12000x1000. For stereo rendering:
For CPU (Production or Interactive) rendering you need to create a VRayStereoscopicSettings plugin. It has to be created after SettingsCamera and SettingsOutput or it won't work! It's recommended to change the VRayStereoscopicSettings::focus_method parameter to 1 for panorama or 2 for normal camera. For GPU rendering you need to set RenderView::stereo_on to 1. You might also want to set RenderView::stereo_eye_distance to something like 6.5 (average human), instead of the default 1.0. It's recommended to change the RenderView::stereo_focus_method parameter to 1 for panorama or 2 for normal camera. Also remember to set a double horizontal resolution for stereo. So if your normal render resolution is 640x480, make that 1280x480. The left half of the image will be the left eye view and the right half is the right eye.
Examples Cube 6x1 Check comments in the scene file vrscenes/vr_cube6x1_camera.vrscene.
Stereo Cube 6x1 Check comments in the scene file vrscenes/vr_cube6x1_stereo.vrscene.
Spherical Check comments in the scene file vrscenes/vr_sphericalPanorama_camera.vrscene.
Stereo Spherical Check comments in the scene file vrscenes/vr_sphericalPanorama_stereo.vrscene.
Code example Here's an example code for Cube6x1 rendering:
Python <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line"># Compatibility with Python 2.7.</span><span data-v-c2b1f83f="" class="line">from __future__ import print_function</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># The directory containing the vray shared object should be present in the PYTHONPATH environment variable.</span><span data-v-c2b1f83f="" class="line"># Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH</span><span data-v-c2b1f83f="" class="line">import sys, os</span><span data-v-c2b1f83f="" class="line">VRAY_SDK = os.environ.get('VRAY_SDK')</span><span data-v-c2b1f83f="" class="line">if VRAY_SDK:</span><span data-v-c2b1f83f="" class="line"> sys.path.append(os.path.join(VRAY_SDK, 'python'))</span><span data-v-c2b1f83f="" class="line">import vray</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">SCENE_PATH = os.path.join(os.environ.get('VRAY_SDK'), 'scenes')</span><span data-v-c2b1f83f="" class="line"># Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">os.chdir(SCENE_PATH)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"># The renderer is automatically closed after the `with` block.</span><span data-v-c2b1f83f="" class="line">with vray.VRayRenderer() as renderer:</span><span data-v-c2b1f83f="" class="line"> # Register a simple log callback. Always useful for debugging.</span><span data-v-c2b1f83f="" class="line"> def dumpMsg(renderer, message, level, instant):</span><span data-v-c2b1f83f="" class="line"> if level == vray.LOGLEVEL_ERROR:</span><span data-v-c2b1f83f="" class="line"> print("[ERROR]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_WARNING:</span><span data-v-c2b1f83f="" class="line"> print("[Warning]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_INFO:</span><span data-v-c2b1f83f="" class="line"> print("[info]", message)</span><span data-v-c2b1f83f="" class="line"> # Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> #else: print("[debug]", message)</span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(dumpMsg)</span><span data-v-c2b1f83f="" class="line"> # Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load(os.path.join(SCENE_PATH, 'stereo.vrscene'))</span><span data-v-c2b1f83f="" class="line"> # The original image size is 3000x500px.</span><span data-v-c2b1f83f="" class="line"> # In this example 2 images are rendered side-by-side for the stereo effect</span><span data-v-c2b1f83f="" class="line"> # and the image width had to be doubled (6000px).</span><span data-v-c2b1f83f="" class="line"> renderer.size = (6000, 500)</span><span data-v-c2b1f83f="" class="line"> # The SettingsCamera plugin controls the way the scene geometry is</span><span data-v-c2b1f83f="" class="line"> # projected onto the image (camera type, motion blur and depth of field).</span><span data-v-c2b1f83f="" class="line"> settingsCamera = renderer.classes.SettingsCamera.getInstanceOrCreate()</span><span data-v-c2b1f83f="" class="line"> # Specifies the type of the camera</span><span data-v-c2b1f83f="" class="line"> # Possible values are:</span><span data-v-c2b1f83f="" class="line"> # 0 - default - Allows for the current scene camera to be used (usually a</span><span data-v-c2b1f83f="" class="line"> # pinhole camera).</span><span data-v-c2b1f83f="" class="line"> # 1 (Spherical) - A camera with a spherical lens.</span><span data-v-c2b1f83f="" class="line"> # 2 (Cylindrical (point)) - This camera casts all rays from the center of</span><span data-v-c2b1f83f="" class="line"> # a cylinder. In the vertical direction the camera acts as a pinhole</span><span data-v-c2b1f83f="" class="line"> # camera, and in the horizontal direction the camera acts as a</span><span data-v-c2b1f83f="" class="line"> # spherical camera.</span><span data-v-c2b1f83f="" class="line"> # 3 (Cylindrical (ortho)) - This camera casts all rays from the center of</span><span data-v-c2b1f83f="" class="line"> # a cylinder. In the vertical direction the camera acts as an</span><span data-v-c2b1f83f="" class="line"> # orthographic view, and in the horizontal direction the camera acts</span><span data-v-c2b1f83f="" class="line"> # as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> # 4 (Box) - Six standard cameras placed on the sides of a box, generating</span><span data-v-c2b1f83f="" class="line"> # a vertical cross format image. This type of camera is excellent for</span><span data-v-c2b1f83f="" class="line"> # generation of environment maps for cube mapping. The Box camera can</span><span data-v-c2b1f83f="" class="line"> # also be used for generating irradiance maps for GI: First you would</span><span data-v-c2b1f83f="" class="line"> # calculate the irradiance map with a Box camera, then save it to a</span><span data-v-c2b1f83f="" class="line"> # file and finally reuse it with a Default camera that can be pointed</span><span data-v-c2b1f83f="" class="line"> # in any direction.</span><span data-v-c2b1f83f="" class="line"> # 5 (Fish eye) - This special type of camera captures the scene as if it</span><span data-v-c2b1f83f="" class="line"> # is a pinhole camera pointed at a 100% reflective sphere that</span><span data-v-c2b1f83f="" class="line"> # reflects the scene back into the camera's shutter, as with using a</span><span data-v-c2b1f83f="" class="line"> # light probe in HDRI photography. You can use the Dist and FOV</span><span data-v-c2b1f83f="" class="line"> # settings to control which part of the sphere is captured by the</span><span data-v-c2b1f83f="" class="line"> # camera. Note that the virtual reflective sphere has always a radius</span><span data-v-c2b1f83f="" class="line"> # of 1.0.</span><span data-v-c2b1f83f="" class="line"> # 6 (Warped spherical (old-style)) - A spherical camera with slightly</span><span data-v-c2b1f83f="" class="line"> # different mapping formula than the Spherical camera.</span><span data-v-c2b1f83f="" class="line"> # 7 (Orthographic) - A camera enabling a non-perspective view.</span><span data-v-c2b1f83f="" class="line"> # 8 (Perspective) - Overrides the scene camera to force it to be a</span><span data-v-c2b1f83f="" class="line"> # pinhole camera.</span><span data-v-c2b1f83f="" class="line"> # 9 (Spherical panorama) - A spherical camera with independent horizontal</span><span data-v-c2b1f83f="" class="line"> # and vertical FOV selection that is useful for generating latlong</span><span data-v-c2b1f83f="" class="line"> # images for spherical VR use.</span><span data-v-c2b1f83f="" class="line"> # 10 (Cube6x1) - A variant of the Box camera with the cube sides arranged</span><span data-v-c2b1f83f="" class="line"> # in a single row. Unlike the Box camera's output, Cube6x1 does not</span><span data-v-c2b1f83f="" class="line"> # produce an empty space in the output image and is quite useful in</span><span data-v-c2b1f83f="" class="line"> # generating cubic VR output.</span><span data-v-c2b1f83f="" class="line"> settingsCamera.type = 10</span><span data-v-c2b1f83f="" class="line"> renderView = renderer.classes.RenderView.getInstanceOrCreate()</span><span data-v-c2b1f83f="" class="line"> # Specify active camera (render camera) position and orientation.</span><span data-v-c2b1f83f="" class="line"> renderView.transform = vray.Transform(</span><span data-v-c2b1f83f="" class="line"> vray.Matrix(</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0.9999999, 0, 0),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 0.9999999, 0),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 0, 0.9999999)),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 160, -144.4429302328891))</span><span data-v-c2b1f83f="" class="line"> # Update field of view value.</span><span data-v-c2b1f83f="" class="line"> renderView.fov = 6.283185</span><span data-v-c2b1f83f="" class="line"> # Specify near clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.clipping_near = 0.1</span><span data-v-c2b1f83f="" class="line"> # Specify far clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.clipping_far = 10000</span><span data-v-c2b1f83f="" class="line"> # The "VRayStereoscopicSettings" enables the stereoscopic rendering.</span><span data-v-c2b1f83f="" class="line"> stereo = renderer.classes.VRayStereoscopicSettings.getInstanceOrCreate()</span><span data-v-c2b1f83f="" class="line"> # Specify the focus method for the two views.</span><span data-v-c2b1f83f="" class="line"> # Possible values are:</span><span data-v-c2b1f83f="" class="line"> # 0 (None/Parallel) - default</span><span data-v-c2b1f83f="" class="line"> # 1 (Rotation)</span><span data-v-c2b1f83f="" class="line"> # 2 (Shear)</span><span data-v-c2b1f83f="" class="line"> stereo.focus_method = 2</span><span data-v-c2b1f83f="" class="line"> # Automatically adjust the resolution for the final image rendererd.</span><span data-v-c2b1f83f="" class="line"> stereo.adjust_resolution = True</span><span data-v-c2b1f83f="" class="line"> # Start rendering.</span><span data-v-c2b1f83f="" class="line"> renderer.startSync()</span><span data-v-c2b1f83f="" class="line"> # Wait for rendering to end.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd()</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"></span></code>
C++ <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">#define VRAY_RUNTIME_LOAD_PRIMARY</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">#include "vraysdk.hpp"</span><span data-v-c2b1f83f="" class="line">#include "vrayplugins.hpp"</span><span data-v-c2b1f83f="" class="line">#include "utils.h"</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">using namespace VRay;</span><span data-v-c2b1f83f="" class="line">using namespace VRay::Plugins;</span><span data-v-c2b1f83f="" class="line">using namespace std;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">const char *BASE_PATH = getenv("VRAY_SDK");</span><span data-v-c2b1f83f="" class="line">string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">int main() {</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> changeCurrentDir(SCENE_PATH.c_str());</span><span data-v-c2b1f83f="" class="line"> // Load V-Ray SDK library.</span><span data-v-c2b1f83f="" class="line"> VRayInit init(NULL, true);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> // The renderer is automatically closed at the end of the current scope.</span><span data-v-c2b1f83f="" class="line"> VRayRenderer renderer;</span><span data-v-c2b1f83f="" class="line"> // It's recommended to always have a console log</span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(logMessage);</span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load("stereo.vrscene");</span><span data-v-c2b1f83f="" class="line"> // The original image size is 3000x500px.</span><span data-v-c2b1f83f="" class="line"> // In this example 2 images are rendered side-by-side for the stereo effect</span><span data-v-c2b1f83f="" class="line"> // and the image width had to be doubled (6000px).</span><span data-v-c2b1f83f="" class="line"> renderer.setImageSize(6000, 500);</span><span data-v-c2b1f83f="" class="line"> // The SettingsCamera plugin controls the way the scene geometry is</span><span data-v-c2b1f83f="" class="line"> // projected onto the image(camera type, motion blur and depth of field).</span><span data-v-c2b1f83f="" class="line"> SettingsCamera settingsCamera = renderer.getInstanceOrCreate<SettingsCamera>();</span><span data-v-c2b1f83f="" class="line"> // Specifies the type of the camera</span><span data-v-c2b1f83f="" class="line"> // Possible values are:</span><span data-v-c2b1f83f="" class="line"> // 0 - default - Allows for the current scene camera to be used (usually a pinhole camera).</span><span data-v-c2b1f83f="" class="line"> // 1 (Spherical) - A camera with a spherical lens.</span><span data-v-c2b1f83f="" class="line"> // 2 (Cylindrical(point)) - This camera casts all rays from the center of a cylinder. </span><span data-v-c2b1f83f="" class="line"> // In the vertical direction the camera acts as a pinhole camera, and in the horizontal direction the camera acts as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 3 (Cylindrical(ortho)) - This camera casts all rays from the center of a cylinder. </span><span data-v-c2b1f83f="" class="line"> // In the vertical direction the camera acts as an orthographic view, and in the horizontal direction the camera acts as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 4 (Box) - Six standard cameras placed on the sides of a box, generating a vertical cross format image. </span><span data-v-c2b1f83f="" class="line"> // This type of camera is excellent for generation of environment maps for cube mapping. </span><span data-v-c2b1f83f="" class="line"> // The Box camera can also be used for generating irradiance maps for GI: </span><span data-v-c2b1f83f="" class="line"> // First you would calculate the irradiance map with a Box camera, then save it to a</span><span data-v-c2b1f83f="" class="line"> // file and finally reuse it with a Default camera that can be pointed in any direction.</span><span data-v-c2b1f83f="" class="line"> // 5 (Fish eye) - This special type of camera captures the scene as if it is a pinhole camera pointed at a 100% reflective sphere that</span><span data-v-c2b1f83f="" class="line"> // reflects the scene back into the camera's shutter, as with using a light probe in HDRI photography. You can use the Dist and FOV</span><span data-v-c2b1f83f="" class="line"> // settings to control which part of the sphere is captured by the camera. Note that the virtual reflective sphere has always a radius of 1.0.</span><span data-v-c2b1f83f="" class="line"> // 6 (Warped spherical (old-style)) - A spherical camera with slightly different mapping formula than the Spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 7 (Orthographic) - A camera enabling a non-perspective view.</span><span data-v-c2b1f83f="" class="line"> // 8 (Perspective) - Overrides the scene camera to force it to be a pinhole camera.</span><span data-v-c2b1f83f="" class="line"> // 9 (Spherical panorama) - A spherical camera with independent horizontal</span><span data-v-c2b1f83f="" class="line"> // and vertical FOV selection that is useful for generating latlong images for spherical VR use.</span><span data-v-c2b1f83f="" class="line"> // 10 (Cube6x1) - A variant of the Box camera with the cube sides arranged in a single row. Unlike the Box camera's output, </span><span data-v-c2b1f83f="" class="line"> // Cube6x1 does not produce an empty space in the output image and is quite useful in generating cubic VR output.</span><span data-v-c2b1f83f="" class="line"> settingsCamera.set_type(10);</span><span data-v-c2b1f83f="" class="line"> RenderView renderView = renderer.getInstanceOrCreate<RenderView>();</span><span data-v-c2b1f83f="" class="line"> // Specify active camera(render camera) position and orientation.</span><span data-v-c2b1f83f="" class="line"> renderView.set_transform(Transform(</span><span data-v-c2b1f83f="" class="line"> Matrix(</span><span data-v-c2b1f83f="" class="line"> Vector(0.9999999, 0.0, 0.0),</span><span data-v-c2b1f83f="" class="line"> Vector(0.0, 0.9999999, 0.0),</span><span data-v-c2b1f83f="" class="line"> Vector(0.0, 0.0, 0.9999999)),</span><span data-v-c2b1f83f="" class="line"> Vector(0.0, 160.0, -144.4429302328891)));</span><span data-v-c2b1f83f="" class="line"> // Update field of view value.</span><span data-v-c2b1f83f="" class="line"> renderView.set_fov(6.283185f);</span><span data-v-c2b1f83f="" class="line"> // Specify near clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.set_clipping_near(0.1f);</span><span data-v-c2b1f83f="" class="line"> // Specify far clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.set_clipping_far(10000);</span><span data-v-c2b1f83f="" class="line"> // The "VRayStereoscopicSettings" enables the stereoscopic rendering.</span><span data-v-c2b1f83f="" class="line"> VRayStereoscopicSettings stereo = renderer.getInstanceOrCreate<VRayStereoscopicSettings>();</span><span data-v-c2b1f83f="" class="line"> // Specify the focus method for the two views.</span><span data-v-c2b1f83f="" class="line"> // Possible values are :</span><span data-v-c2b1f83f="" class="line"> // 0 (None / Parallel) - default</span><span data-v-c2b1f83f="" class="line"> // 1 (Rotation)</span><span data-v-c2b1f83f="" class="line"> // 2 (Shear)</span><span data-v-c2b1f83f="" class="line"> stereo.set_focus_method(2);</span><span data-v-c2b1f83f="" class="line"> // Automatically adjust the resolution for the final image rendererd.</span><span data-v-c2b1f83f="" class="line"> stereo.set_adjust_resolution(true);</span><span data-v-c2b1f83f="" class="line"> // Start rendering.</span><span data-v-c2b1f83f="" class="line"> renderer.startSync();</span><span data-v-c2b1f83f="" class="line"> // Wait for rendering to end.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd();</span><span data-v-c2b1f83f="" class="line"> return 0;</span><span data-v-c2b1f83f="" class="line">}</span></code>
C#.NET <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">using System;</span><span data-v-c2b1f83f="" class="line">using System.IO;</span><span data-v-c2b1f83f="" class="line">using VRay;</span><span data-v-c2b1f83f="" class="line">using VRay.Plugins;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">namespace _08_stereo_panorama</span><span data-v-c2b1f83f="" class="line">{</span><span data-v-c2b1f83f="" class="line"> class Program</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> static void Main(string[] args)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> Directory.SetCurrentDirectory(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> // The renderer is automatically closed after the `using` block.</span><span data-v-c2b1f83f="" class="line"> using (VRayRenderer renderer = new VRayRenderer())</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // Add a listener for any type of log message.</span><span data-v-c2b1f83f="" class="line"> renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =></span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // You can remove the if for testing, but you might want to ignore Debug in real code</span><span data-v-c2b1f83f="" class="line"> if (e.LogLevel != LogLevelType.Debug)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.Load("stereo.vrscene");</span><span data-v-c2b1f83f="" class="line"> // The original image size is 3000x500px.</span><span data-v-c2b1f83f="" class="line"> // In this example 2 images are rendered side-by-side for the stereo effect</span><span data-v-c2b1f83f="" class="line"> // and the image width had to be doubled (6000px).</span><span data-v-c2b1f83f="" class="line"> renderer.SetImageSize(6000, 500);</span><span data-v-c2b1f83f="" class="line"> // The SettingsCamera plugin controls the way the scene geometry is</span><span data-v-c2b1f83f="" class="line"> // projected onto the image (camera type, motion blur and depth of field).</span><span data-v-c2b1f83f="" class="line"> SettingsCamera settingsCamera = renderer.GetInstanceOrCreate<SettingsCamera>();</span><span data-v-c2b1f83f="" class="line"> // Specifies the type of the camera</span><span data-v-c2b1f83f="" class="line"> // Possible values are:</span><span data-v-c2b1f83f="" class="line"> // 0 - default - Allows for the current scene camera to be used (usually a pinhole camera).</span><span data-v-c2b1f83f="" class="line"> // 1 (Spherical) - A camera with a spherical lens.</span><span data-v-c2b1f83f="" class="line"> // 2 (Cylindrical(point)) - This camera casts all rays from the center of a cylinder. </span><span data-v-c2b1f83f="" class="line"> // In the vertical direction the camera acts as a pinhole camera, and in the horizontal direction the camera acts as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 3 (Cylindrical(ortho)) - This camera casts all rays from the center of a cylinder. </span><span data-v-c2b1f83f="" class="line"> // In the vertical direction the camera acts as an orthographic view, and in the horizontal direction the camera acts as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 4 (Box) - Six standard cameras placed on the sides of a box, generating a vertical cross format image. </span><span data-v-c2b1f83f="" class="line"> // This type of camera is excellent for generation of environment maps for cube mapping. </span><span data-v-c2b1f83f="" class="line"> // The Box camera can also be used for generating irradiance maps for GI: </span><span data-v-c2b1f83f="" class="line"> // First you would calculate the irradiance map with a Box camera, then save it to a</span><span data-v-c2b1f83f="" class="line"> // file and finally reuse it with a Default camera that can be pointed in any direction.</span><span data-v-c2b1f83f="" class="line"> // 5 (Fish eye) - This special type of camera captures the scene as if it is a pinhole camera pointed at a 100% reflective sphere that</span><span data-v-c2b1f83f="" class="line"> // reflects the scene back into the camera's shutter, as with using a light probe in HDRI photography. You can use the Dist and FOV</span><span data-v-c2b1f83f="" class="line"> // settings to control which part of the sphere is captured by the camera. Note that the virtual reflective sphere has always a radius of 1.0.</span><span data-v-c2b1f83f="" class="line"> // 6 (Warped spherical (old-style)) - A spherical camera with slightly different mapping formula than the Spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 7 (Orthographic) - A camera enabling a non-perspective view.</span><span data-v-c2b1f83f="" class="line"> // 8 (Perspective) - Overrides the scene camera to force it to be a pinhole camera.</span><span data-v-c2b1f83f="" class="line"> // 9 (Spherical panorama) - A spherical camera with independent horizontal</span><span data-v-c2b1f83f="" class="line"> // and vertical FOV selection that is useful for generating latlong images for spherical VR use.</span><span data-v-c2b1f83f="" class="line"> // 10 (Cube6x1) - A variant of the Box camera with the cube sides arranged in a single row. Unlike the Box camera's output, </span><span data-v-c2b1f83f="" class="line"> // Cube6x1 does not produce an empty space in the output image and is quite useful in generating cubic VR output.</span><span data-v-c2b1f83f="" class="line"> settingsCamera.SettingsCameraType = 10;</span><span data-v-c2b1f83f="" class="line"> RenderView renderView = renderer.GetInstanceOrCreate<RenderView>();</span><span data-v-c2b1f83f="" class="line"> // Specify active camera (render camera) position and orientation.</span><span data-v-c2b1f83f="" class="line"> renderView.Transform = new Transform(</span><span data-v-c2b1f83f="" class="line"> new Matrix(</span><span data-v-c2b1f83f="" class="line"> new Vector(0.9999999, 0, 0),</span><span data-v-c2b1f83f="" class="line"> new Vector(0, 0.9999999, 0),</span><span data-v-c2b1f83f="" class="line"> new Vector(0, 0, 0.9999999)),</span><span data-v-c2b1f83f="" class="line"> new Vector(0, 160, -144.4429302328891));</span><span data-v-c2b1f83f="" class="line"> // Update field of view value.</span><span data-v-c2b1f83f="" class="line"> renderView.Fov = 6.283185F;</span><span data-v-c2b1f83f="" class="line"> // Specify near clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.ClippingNear = 0.1F;</span><span data-v-c2b1f83f="" class="line"> // Specify far clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.ClippingFar = 10000;</span><span data-v-c2b1f83f="" class="line"> // The "VRayStereoscopicSettings" enables the stereoscopic rendering.</span><span data-v-c2b1f83f="" class="line"> VRayStereoscopicSettings stereo = renderer.GetInstanceOrCreate<VRayStereoscopicSettings>();</span><span data-v-c2b1f83f="" class="line"> // Specify the focus method for the two views.</span><span data-v-c2b1f83f="" class="line"> // Possible values are:</span><span data-v-c2b1f83f="" class="line"> // 0 (None/Parallel) - default</span><span data-v-c2b1f83f="" class="line"> // 1 (Rotation)</span><span data-v-c2b1f83f="" class="line"> // 2 (Shear)</span><span data-v-c2b1f83f="" class="line"> stereo.FocusMethod = 2;</span><span data-v-c2b1f83f="" class="line"> // Automatically adjust the resolution for the final image rendererd.</span><span data-v-c2b1f83f="" class="line"> stereo.AdjustResolution = true;</span><span data-v-c2b1f83f="" class="line"> // Start rendering.</span><span data-v-c2b1f83f="" class="line"> renderer.StartSync();</span><span data-v-c2b1f83f="" class="line"> // Wait for rendering to end.</span><span data-v-c2b1f83f="" class="line"> renderer.WaitForRenderEnd();</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line">}</span></code>
Node.js <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">var path = require('path');</span><span data-v-c2b1f83f="" class="line">var vray = require(path.join(process.env.VRAY_SDK, 'node', 'vray'));</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">var SCENE_PATH = path.join(process.env.VRAY_SDK, 'scenes');</span><span data-v-c2b1f83f="" class="line">// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">process.chdir(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line">var renderer = vray.VRayRenderer();</span><span data-v-c2b1f83f="" class="line">// It's recommended to always have a console log callback</span><span data-v-c2b1f83f="" class="line">renderer.on("logMessage", function(message, level, instant) {</span><span data-v-c2b1f83f="" class="line"> if (level == vray.LOGLEVEL_ERROR)</span><span data-v-c2b1f83f="" class="line"> console.log("[ERROR] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_WARNING)</span><span data-v-c2b1f83f="" class="line"> console.log("[Warning] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_INFO)</span><span data-v-c2b1f83f="" class="line"> console.log("[info] ", message);</span><span data-v-c2b1f83f="" class="line"> // Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> //else console.log("[debug] ", message);</span><span data-v-c2b1f83f="" class="line">});</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Load scene from a file asynchronously.</span><span data-v-c2b1f83f="" class="line">renderer.load("stereo.vrscene", function(err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> // The original image size is 3000x500px.</span><span data-v-c2b1f83f="" class="line"> // In this example 2 images are rendered side-by-side for the stereo effect</span><span data-v-c2b1f83f="" class="line"> // and the image width had to be doubled (6000px).</span><span data-v-c2b1f83f="" class="line"> renderer.size = {"width": 6000, "height": 500};</span><span data-v-c2b1f83f="" class="line"> // The SettingsCamera plugin controls the way the scene geometry is</span><span data-v-c2b1f83f="" class="line"> // projected onto the image (camera type, motion blur and depth of field).</span><span data-v-c2b1f83f="" class="line"> var settingsCamera = renderer.classes.SettingsCamera.getInstanceOrCreate();</span><span data-v-c2b1f83f="" class="line"> // Specifies the type of the camera</span><span data-v-c2b1f83f="" class="line"> // Possible values are:</span><span data-v-c2b1f83f="" class="line"> // 0 - default - Allows for the current scene camera to be used (usually a</span><span data-v-c2b1f83f="" class="line"> // pinhole camera).</span><span data-v-c2b1f83f="" class="line"> // 1 (Spherical) - A camera with a spherical lens.</span><span data-v-c2b1f83f="" class="line"> // 2 (Cylindrical(point)) - This camera casts all rays from the center of</span><span data-v-c2b1f83f="" class="line"> // a cylinder. In the vertical direction the camera acts as a pinhole</span><span data-v-c2b1f83f="" class="line"> // camera, and in the horizontal direction the camera acts as a</span><span data-v-c2b1f83f="" class="line"> // spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 3 (Cylindrical(ortho)) - This camera casts all rays from the center of</span><span data-v-c2b1f83f="" class="line"> // a cylinder. In the vertical direction the camera acts as an</span><span data-v-c2b1f83f="" class="line"> // orthographic view, and in the horizontal direction the camera acts</span><span data-v-c2b1f83f="" class="line"> // as a spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 4 (Box) - Six standard cameras placed on the sides of a box, generating</span><span data-v-c2b1f83f="" class="line"> // a vertical cross format image. This type of camera is excellent for</span><span data-v-c2b1f83f="" class="line"> // generation of environment maps for cube mapping. The Box camera can</span><span data-v-c2b1f83f="" class="line"> // also be used for generating irradiance maps for GI: First you would</span><span data-v-c2b1f83f="" class="line"> // calculate the irradiance map with a Box camera, then save it to a</span><span data-v-c2b1f83f="" class="line"> // file and finally reuse it with a Default camera that can be pointed</span><span data-v-c2b1f83f="" class="line"> // in any direction.</span><span data-v-c2b1f83f="" class="line"> // 5 (Fish eye) - This special type of camera captures the scene as if it</span><span data-v-c2b1f83f="" class="line"> // is a pinhole camera pointed at a 100% reflective sphere that</span><span data-v-c2b1f83f="" class="line"> // reflects the scene back into the camera's shutter, as with using a</span><span data-v-c2b1f83f="" class="line"> // light probe in HDRI photography. You can use the Dist and FOV</span><span data-v-c2b1f83f="" class="line"> // settings to control which part of the sphere is captured by the</span><span data-v-c2b1f83f="" class="line"> // camera. Note that the virtual reflective sphere has always a radius</span><span data-v-c2b1f83f="" class="line"> // of 1.0.</span><span data-v-c2b1f83f="" class="line"> // 6 (Warped spherical (old-style)) - A spherical camera with slightly</span><span data-v-c2b1f83f="" class="line"> // different mapping formula than the Spherical camera.</span><span data-v-c2b1f83f="" class="line"> // 7 (Orthographic) - A camera enabling a non-perspective view.</span><span data-v-c2b1f83f="" class="line"> // 8 (Perspective) - Overrides the scene camera to force it to be a</span><span data-v-c2b1f83f="" class="line"> // pinhole camera.</span><span data-v-c2b1f83f="" class="line"> // 9 (Spherical panorama) - A spherical camera with independent horizontal</span><span data-v-c2b1f83f="" class="line"> // and vertical FOV selection that is useful for generating latlong</span><span data-v-c2b1f83f="" class="line"> // images for spherical VR use.</span><span data-v-c2b1f83f="" class="line"> // 10 (Cube6x1) - A variant of the Box camera with the cube sides arranged</span><span data-v-c2b1f83f="" class="line"> // in a single row. Unlike the Box camera's output, Cube6x1 does not</span><span data-v-c2b1f83f="" class="line"> // produce an empty space in the output image and is quite useful in</span><span data-v-c2b1f83f="" class="line"> // generating cubic VR output.</span><span data-v-c2b1f83f="" class="line"> settingsCamera.type = 10;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> var renderView = renderer.classes.RenderView.getInstanceOrCreate();</span><span data-v-c2b1f83f="" class="line"> // Specify active camera (render camera) position and orientation.</span><span data-v-c2b1f83f="" class="line"> renderView.transform = vray.Transform(</span><span data-v-c2b1f83f="" class="line"> vray.Matrix(</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0.9999999, 0, 0),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 0.9999999, 0),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 0, 0.9999999)),</span><span data-v-c2b1f83f="" class="line"> vray.Vector(0, 160, -144.4429302328891));</span><span data-v-c2b1f83f="" class="line"> // Update field of view value.</span><span data-v-c2b1f83f="" class="line"> renderView.fov = 6.283185;</span><span data-v-c2b1f83f="" class="line"> // Specify near clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.clipping_near = 0.1;</span><span data-v-c2b1f83f="" class="line"> // Specify far clipping plane.</span><span data-v-c2b1f83f="" class="line"> renderView.clipping_far = 10000;</span><span data-v-c2b1f83f="" class="line"> // The "VRayStereoscopicSettings" enables the stereoscopic rendering.</span><span data-v-c2b1f83f="" class="line"> var stereo = renderer.classes.VRayStereoscopicSettings.getInstanceOrCreate();</span><span data-v-c2b1f83f="" class="line"> // Specify the focus method for the two views.</span><span data-v-c2b1f83f="" class="line"> // Possible values are:</span><span data-v-c2b1f83f="" class="line"> // 0 (None/Parallel) - default</span><span data-v-c2b1f83f="" class="line"> // 1 (Rotation)</span><span data-v-c2b1f83f="" class="line"> // 2 (Shear)</span><span data-v-c2b1f83f="" class="line"> stereo.focus_method = 2;</span><span data-v-c2b1f83f="" class="line"> // Automatically adjust the resolution for the final image rendererd.</span><span data-v-c2b1f83f="" class="line"> stereo.adjust_resolution = true;</span><span data-v-c2b1f83f="" class="line"> // Start rendering.</span><span data-v-c2b1f83f="" class="line"> renderer.start(function(err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> // Wait for rendering to end.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd(function() {</span><span data-v-c2b1f83f="" class="line"> renderer.close();</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line">});</span></code>