SDK:SDK/Tools/Modelling/3ds Max/Stereoscopy

From Programmer Art

3dsMax_Stereoscopy_small.png

Contents

This DirectX Shader (FX) file performs stereoscopic rendering in 3ds Max viewports.

It provides the following 3D output formats:

  • Anaglyph (coloured glasses)
  • Interlaced (eg. Zalman)
  • Checkerboard (eg. DLP)
  • Anaglyph-checkerboard (coloured glasses)

Download

3dsMax_Stereoscopy.fx

Links

Installation

  • Save the file as 3dsMax_Stereoscopy.fx (removing the '.txt' extension), in your Max maps\fx folder, eg. C:\Program Files\Autodesk\3ds Max 2010\maps\fx\
  • Apply a DirectX Shader material to your object(s), using this fx file (see Max/DirectX help for details on DirectX Shader materials).

Performance and code style

Please be aware that this code is not performance-optimised.

Rather it is intended just as a utility and an educational tool:

  • To allow people to see their models in 3D without leaving the modelling environment.
  • To demonstrate the parameters of stereo rendering and the geometric relationships between them.

Multiple objects sort incorrectly in anaglyph mode

Please note that multiple objects will sort incorrectly against each other when displayed in angalyph mode.

The solutions are:

  • attach all the objects to each other to form a single mesh;
  • or use the "GlyphBoard" (anaglyph-checkerboard) modes which avoid all sorting problems at the expense of image quality;
  • or ideally, use the interlaced or checkerboard modes (with an appropriate 3D display) instead.

Wireframes etc. display in 2D

Elements such as wireframes, bounding boxes and gizmos display in 2D only, aligned with the left-eye view. In interlaced and checkerboard modes, the wireframe is hidden as much as possible in the right-eye view.

You are advised to keep these elements hidden whenever possible when displaying the viewport in 3D.

  • To hide wireframe:
    • F4
  • To hide the grid:
    • G
  • To hide the transform gizmo:
    • Views > Show Transform Gizmo
  • To hide safe frames:
    • (viewport '+' button) > Safe Frames > untick 'Show safe frames in active view'
  • To hide the view cube:
    • (viewport '+' button) > untick 'Show the ViewCube'
  • To hide the selection brackets:
    • (viewport '+' button) > untick "Use Selection Brackets"

Anaglyph depth hack

The anaglyph techniques in this file use a dirty hack to prevent z-buffer interaction between the left & right views:

The first of the two views to render is pushed deeper into the Z buffer by offsetting its view-space vertex Z positions by cAnaglyphDepthHackZSpacing.

If you find that you get z-buffer problems in anaglyph mode (especially with larger scenes), you can try changing the values of cAnaglyphDepthHackZMultiplier and cAnaglyphDepthHackZSpacing. But please firstly read the note "Multiple objects sort incorrectly in anaglyph mode" above.

The adjusted Z positions are calculated in _VertexShader (see output.csPositionZW) and then output in PixelShader_Base using the DEPTH semantic.

Please note that this hack is not usually required for anaglyph. Normally, you would either:

  • clear the Z buffer between rendering the first & second view, or
  • render the two views to separate areas of VRAM before combining them on the screen.

However, using *just* an FX file and no other code, I don't know a way of doing a z-buffer clear between the two passes. If you know of a way of doing this in an FX file, please let me know, I'll buy you a beer!

It is possible to render the two views side-by-side using an FX file, and then combine them on the Max viewport using a post effect. However, that would mess-up all the wireframes, transform gizmo, etc which aren't passed through the FX file, making it impossible to do any editing while rendering in stereo.

Viewport resolution adjustment

In the interlaced and checkerboard pixel shaders, I've had to subtract one from the X and Y resolutions specified.

I don't know why that's needed for these Max viewports, but it is.

Normally, those '-1's would not be required for interlaced or checkerboard stereo.

Terms of use

You are free to do what you want with this code. It's not proprietary or protected in any way.

It is provided free-of-charge and without warranty, and it's in the public domain.