由于项目需要,要做偏振3D投影,查到了这篇资料,很有用,原文是英文,翻译了一下,一些专有名词可能会有错误,希望行家指正。
这个方法有一个问题就是鼠标对物体的点击会失效,主要是因为该方法相当于是用一个摄像机获取了两个摄像机的投影,相当于鼠标和物体间隔了一层东西,所以鼠标点击无法响应,如果哪位高人有好的方法希望不吝赐教。目前我的解决办法是不要鼠标点击,利用碰撞来完成拾取等动作。
原文地址:http://paulbourke.net/miscellaneous/stereographics/Unitystereo/
看得出这是一个高手啊,觉得自己英语过关的可以多关注。
相关源文件和图片请到作者博客查看和下载。
Create side-by-side stereo pairs in the Unity game engine
应用Unity游戏引擎创建平行立体影像对
Paul Bourke
December 2008
Sample Island project: Island_stereo.zip
See also: Using Unity in the iDome
In the following I will outline one way of creating stereo pairs within the Unity game engine. Since Unity does not support quad buffer stereo (also known as frame sequential stereo) the approach here is suited to dual projector stereoscopic projection, most commonly this would be a polaroid or Infitec based stereoscopic systems. The technique outlined below involves parallel cameras (as opposed to toe-in) and as such creates optimal stereo pairs without vertical parallax.
下面我要展示一种利用Unity游戏引擎创建立体影像对的方法。由于Unity不支持四缓冲立体(即帧序列立体),本文提到的方法适用于双机立体投影,最通常就是这会成为一个基于偏振片或分色技术的立体投影系统。以下介绍的技术包含平行镜头(和toe-in相反)并且还有不用垂直视差创建立体对。
The reader is assumed to be moderately familiar with Unity3D, screen shots are provided along with each step discussed. The reader is also assumed to be familiar with the basic theory required to generate "easy on the eye" stereoscopic pairs, this includes the relationship between eye separation and the distance to zero parallax. The method here requires render to texture and as such Unity-Pro is required. The example adds stereoscopic support to the demo environment that ships with Unity.
我们假定读者是比较熟悉Unity3D的,每一步讨论都带有屏幕截图。同时我们也认为读者熟悉关于“好看的”立体像对的基本理论,这包括两眼间距和调整到零视差的距离之间的关系。本文所述方法需要纹理渲染以及Unity-Pro。这个例子可为unity下制作的demo环境添加立体支持。
The first step is to create two cameras, one for each eye. In the following, one of the cameras of the standard first person controller is duplicated. Each camera is offset horizontally about the central position of the original camera (in this case by +-0.03 units). Two render textures are created and the cameras set to render to each one. The stereo projection system is XGA (1024x768) so 1K render textures are adequate. An open question is what eye/camera separation to use. For strictly correct stereoscopic projection a knowledge of the viewing screen is required, for this more casual setup one commonly used strategy is to choose a zero parallax distance that is equal to the distance of the camera to the ground. The eye separation then is typically (a common standard) 1/30 of this zero parallax distance. In order to give the most realistic sense of depth the field of view of the two game controller cameras should be close to the field of view of the players eyes to the bounds of the real stereoscopic display.
第一步创建两个摄像机,每只眼睛配备一个。然后将标准第一人称控制器的摄像机中的一个进行复制。每个摄像机相对原来摄像机的中心位置水平偏移(本例中是+-0.03单位)。创建两个渲染纹理,每个摄像机各渲染一个。立体投影系统是XGA(1024*768),因此1K的渲染纹理就足够。一个开放的问题是眼睛/摄像机分离用来做什么。为了达到十分精确的立体投影,这里需要先了解显示屏的一点知识。对于临时增加的这一步,一个通常的做法是让零视差距离等于摄像机相对地面的距离,两眼间距基本上(通常标准)是这个零视差距离的1/30.为了提供最真实的深度感觉,两个游戏控制器的摄像机的视野应该接近玩家眼睛所看到的真实立体影像显示的边界。
The two render textures are applied to side by side square planes. These are both placed on a separate layer so they can be precluded from the first person controller cameras, and can have independent lighting applied. While not strictly necessary, a parallel light is also applied to the "stereo" layer, this provides additional control over brightness and even can apply colour (mood) effects.
两个渲染纹理被应用在一对平行的方形平板上。二者都放在单独的层上,这样他们可以被第一人称控制器的摄像机捕获,而且可以施加独立的光照。当要求不是很严格时,一组平行光也可以加到“立体”层,这提供了额外的光照控制甚至可以加入颜色(气氛)效果。
Finally an orthographic camera is positioned centered on the two render texture planes. It is set to cull all layers except the stereo layer. The zero parallax is controlled by trimming columns from the left of the left image and off the right of the right image, this is described here. This trimming is controlled by the "orthographic size". However, the relationship between the player window aspect ratio and the correct orthographic size (for a particular zero parallax distance) is somewhat convoluted due to some "magic" in the choices made by Unity. The solution is simply to place an object like a small sphere temporarily in front of the camera rig at the desired zero parallax distance and adjust the orthographic size until it is indeed appears to be at zero parallax. Note that the game window below is not filled with the stereo pairs, this is because it doesn't have the right aspect ratio of 8:3 (2048x768).
最后,一个正交的相机放置在两个渲染纹理平板的中间,设置用来剔除除了立体层外的所有层。零视差取决于从左侧画面的左边缘到右侧画面的右边缘的裁切列。它由“正交尺寸”控制。但是,用户屏幕比例和正确的正交尺寸间的关系(对于详细的零视差距离)多多少少和Unity做的一些选择的“神奇的地方”有些复杂关系。一个简单解决方案是在摄像头前按要求的零视差距离上放置一个小球体一样的物体,调整正交尺寸,直到这个物体真正的出现在零视差位置上。注意,下面的游戏窗口并没有立体影像对,因为它的屏幕比例并不是最合适的8:3 (2048x768)。
The following shows the left and right image side by side. The left hand image is sent to the left eye projector and the right hand image sent to the right eye projector. In this case the splitting effect is accomplished by using the Matrox dualhead2go cards to give the desired 2048x768 pixel buffer.
下面显示了并列的左右两个画面。左侧画面送至左眼投影仪,右侧画面送至右眼投影仪。该例中的效果是通过Matrox dualhead2go卡所提供的2048x768像素缓冲所实现的。
The two images overlaid with 50% transparency shows how the parallax increases with distance and the front posts are at the intended zero parallax distance, and there is no vertical parallax.
两个画面被50%透明度覆盖,显示了如何随着距离的增加引起视差的增加,……(此句中的front posts不知何意,未作翻译)这里没有垂直视差。
In order to avoid excessive negative parallax for objects that approach the cameras one may choose to increase the front cutting plane of the two controller cameras to be some reasonable fraction of the zero parallax distance. This depends on the ghosting of the projection system, for polaroid systems this cutting plane may conservatively be set to 1/2 the zero parallax distance, this ensures that the maximum negative parallax equals the maximum positive parallax. For lower ghosting systems such as Infitec the cutting planes can be set closer to the camera.
为了避免由于物体靠近摄像机出现负视差,可以增加两个控制器摄像机的前切平板来使零视差距离更加合理。取决于投影系统的重影,对于偏光片系统这个切片可以适当地设置为零视差距离的1/2,保证最大负视差等于最大正视差。对于低重影系统比如Infitec,切片可以设置为更靠近摄像机。
The authors stereoscopic viewing system, rear projection linear polaroid.
Photographs of the display.