大家好我是天睿Tera,目前专注于开发OculusRift沉浸式体验演示项目并且在建立一个开发者交流的论坛

www.vr-x.cn。

我会把在开发电梯惊魂DEMO的时候遇到的问题和怎么解决的拿出来给大家分享一下。这次分享的是解决双眼显示天空盒重影的问题。

在开发过程如果你用平常的方法加入天空盒的话,编辑器里是看不出来效果的,但当你打包运行之后会发现天空里的云是重影的。

我在Oculus官方开发者社区寻找了许久之后发现了一个Script文件SkyboxMesh.cs

把脚本贴在下面

// coded by Nora
// http://stereoarts.jp
using UnityEngine;
using System.Collections;public class SkyboxMesh : MonoBehaviour
{public enum Shape {Sphere,Cube,}public string      shaderName  = "Unlit/Texture";public float       radius      = 800.0f;public int            segments    = 32;public Shape      shape       = Shape.Sphere;public Material     skybox;public GameObject    follow;void Awake(){Mesh mesh = _CreateMesh();Shader shader = Shader.Find( this.shaderName );_CreatePlane( mesh, shader, "_FrontTex", Quaternion.identity );_CreatePlane( mesh, shader, "_LeftTex",  Quaternion.Euler( 0.0f, 90.0f, 0.0f ) );_CreatePlane( mesh, shader, "_BackTex",  Quaternion.Euler( 0.0f, 180.0f, 0.0f ) );_CreatePlane( mesh, shader, "_RightTex", Quaternion.Euler( 0.0f, 270.0f, 0.0f ) );_CreatePlane( mesh, shader, "_UpTex",    Quaternion.Euler( -90.0f, 0.0f, 0.0f ) );_CreatePlane( mesh, shader, "_DownTex",  Quaternion.Euler( 90.0f, 0.0f, 0.0f ) );}void PostUpdate(){if( this.follow != null ) {this.transform.position = this.follow.transform.position;}}Mesh _CreateMesh(){Mesh mesh = new Mesh();int hvCount2 = this.segments + 1;int hvCount2Half = hvCount2 / 2;int numVertices = hvCount2 * hvCount2;int numTriangles = this.segments * this.segments * 6;Vector3[] vertices = new Vector3[numVertices];Vector2[] uvs = new Vector2[numVertices];int[] triangles = new int[numTriangles];float scaleFactor = 2.0f / (float)this.segments;float angleFactor = Mathf.Deg2Rad * 90.0f / (float)this.segments;float uvFactor = 1.0f / (float)this.segments;if( this.segments <= 1 || this.shape == Shape.Cube ) {float ty = 0.0f, py = -1.0f;int index = 0;for( int y = 0; y < hvCount2; ++y, ty += uvFactor, py += scaleFactor ) {float tx = 0.0f, px = -1.0f;for( int x = 0; x < hvCount2; ++x, ++index, tx += uvFactor, px += scaleFactor ) {vertices[index] = new Vector3( px, py, 1.0f );uvs[index] = new Vector2( tx, ty );}}} else {float ty = 0.0f, py = -1.0f;int index = 0, indexY = 0;for( int y = 0; y <= hvCount2Half; ++y, indexY += hvCount2, ty += uvFactor, py += scaleFactor ) {float tx = 0.0f, px = -1.0f, py2 = py * py;int x = 0;for( ; x <= hvCount2Half; ++x, ++index, tx += uvFactor, px += scaleFactor ) {float d = Mathf.Sqrt( px * px + py2 + 1.0f );float theta = Mathf.Acos( 1.0f / d );float phi = Mathf.Atan2( py, px );float sinTheta = Mathf.Sin( theta );vertices[index] = new Vector3(sinTheta * Mathf.Cos( phi ),sinTheta * Mathf.Sin( phi ),Mathf.Cos( theta ) );uvs[index] = new Vector2( tx, ty );}int indexX = hvCount2Half - 1;for( ; x < hvCount2; ++x, ++index, --indexX, tx += uvFactor, px += scaleFactor ) {Vector3 v = vertices[indexY + indexX];vertices[index] = new Vector3( -v.x, v.y, v.z );uvs[index] = new Vector2( tx, ty );}}indexY = (hvCount2Half - 1) * hvCount2;for( int y = hvCount2Half + 1; y < hvCount2; ++y, indexY -= hvCount2, ty += uvFactor, py += scaleFactor ) {float tx = 0.0f, px = -1.0f;int x = 0;for( ; x <= hvCount2Half; ++x, ++index, tx += uvFactor, px += scaleFactor ) {Vector3 v = vertices[indexY + x];vertices[index] = new Vector3( v.x, -v.y, v.z );uvs[index] = new Vector2( tx, ty );}int indexX = hvCount2Half - 1;for( ; x < hvCount2; ++x, ++index, --indexX, tx += uvFactor, px += scaleFactor ) {Vector3 v = vertices[indexY + indexX];vertices[index] = new Vector3( -v.x, -v.y, v.z );uvs[index] = new Vector2( tx, ty );}}}{for( int y = 0, index = 0, ofst = 0; y < this.segments; ++y, ofst += hvCount2 ) {int y0 = ofst, y1 = ofst + hvCount2;for( int x = 0; x < this.segments; ++x, index += 6 ) {triangles[index+0] = y0 + x;triangles[index+1] = y1 + x;triangles[index+2] = y0 + x + 1;triangles[index+3] = y1 + x;triangles[index+4] = y1 + x + 1;triangles[index+5] = y0 + x + 1;}}}mesh.vertices = vertices;mesh.uv = uvs;mesh.triangles = triangles;return mesh;}void _CreatePlane( Mesh mesh, Shader shader, string textureName, Quaternion rotation ){GameObject go = new GameObject();go.name = textureName;go.transform.parent = this.transform;go.transform.localPosition = Vector3.zero;go.transform.localScale = new Vector3( this.radius, this.radius, this.radius );go.transform.localRotation = rotation;Material material = new Material( shader );material.mainTexture = skybox.GetTexture( textureName );MeshRenderer meshRenderer = go.AddComponent< MeshRenderer >();meshRenderer.material = material;meshRenderer.castShadows = false;meshRenderer.receiveShadows = false;MeshFilter meshFilter = go.AddComponent< MeshFilter >();meshFilter.mesh = mesh;}
}

OK,有了这个脚本之后我们这样操作首先把原来的Skybox关掉

选择我们的摄影机把脚本放上去

给脚本指定一个Skybox就可以了~

这样再用Oculus Rift试一下,就不会重影了哦!

用Unity开发基于Oculus Rift的体验游戏时遇到天空盒重影问题的解决方法相关推荐

  1. PHP 接口开发使用 lcobucci/jwt 进行 Token 认证时提示 Error while decoding to JSON 解决方法

    在 Stack Overflow 提过这个问题,很快就被网友解答了,非常感谢,有兴趣的朋友可以去瞧瞧我的渣英文.How to validate the user JWT pass over Token ...

  2. 如何在Unity上开发Nintendo(任天堂)Switch平台游戏时让游戏patch包大小尽量小

    如何在Unity上开发Nintendo(任天堂)Switch平台游戏时让游戏patch包大小尽量小 众所周知,Nintendo Switch有一条guidline-0123来限制游戏的patch包大小 ...

  3. 如何用GameMakerStudio开发基于物理引擎的平台游戏 | Lynda教程 中文字幕

    GameMakerStudio教程之如何用GML开发基于物理引擎的平台游戏 | Lynda教程 中文字幕 Building a Physics-Based Platformer in GameMake ...

  4. 用Unity开发一款2D横版游戏demo

    # LanW Game Project 目录 (一) 介绍 (二) 安装教程 (三) 开发流程 1.  新建工程 2.  设置人物 3.  控制主角的移动 4.   添加切换动作的动画 5.   镜头 ...

  5. run `npm fund` for details解决,前端开发:项目运行npm install 提示XXX ...for funding run `npm fund`...的解决方法

    run npm fund for details解决,前端开发:项目运行npm install 提示XXX -for funding run npm fund-的解决方法 35 packages ar ...

  6. 微信小程序开发——点击按钮获取用户授权没反应或反应很慢的解决方法

    微信小程序开发--点击按钮获取用户授权没反应或反应很慢的解决方法 参考文章: (1)微信小程序开发--点击按钮获取用户授权没反应或反应很慢的解决方法 (2)https://www.cnblogs.co ...

  7. 【使用Unity开发Windows Phone上的2D游戏】(1)千里之行始于足下

    写在前面的 其实这个名字起得不太欠当,Unity本身是很强大的工具,可以部署到很多个平台,而不仅仅是可以开发Windows Phone上的游戏. 只不过本人是Windows Phone 应用开发出身, ...

  8. python 游戏开发框架_Python开发 基于python实现坦克大战游戏

    这篇文章主要为大家详细介绍了基于python实现坦克大战游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本文实例为大家分享了python实现坦克大战游戏的具体代码, ...

  9. 在 Unity 中基于 Oculus DK1 的开发

    开发环境: Windows 10 专业版 64位(GeForce GTX 970M,驱动版本:378.72) 大朋助手 1.3.2.10,大朋E2(http://www.deepoon.com/dap ...

最新文章

  1. python下载图片、已知url_python实现通过URL下载图片到本地服务器
  2. 【Android FFMPEG 开发】Android Studio 中 配置 FFMPEG 库最小兼容版本 ( undefined reference to 'atof' )
  3. 【译】Diving Into The Ethereum VM Part 3 — The Hidden Costs of Arrays
  4. log4net使用具体解释
  5. Drawing绘图halcon算子,持续更新
  6. linux用户取消密码,[Linux]linux下取消用户名和密码直接登录
  7. angular6--创建项目
  8. java中的垃圾回收机
  9. DelayedOperation分析
  10. IIS7 WCF HTTP 错误 404.3 - Not Found
  11. 软件开发模型_20202021企业软件开发流程(5)软件开发过程模型瀑布模型(2)软件设计、编码...
  12. 解决问题的能力 > 10倍程序员
  13. 第二十九篇、UICollectionView瀑布流
  14. 彻底卸载anaconda
  15. java 区号_区号查询示例代码
  16. Aspose.Words 使用InsertNode()在文档末尾插入分页符
  17. 使用promise解决回调地狱_Promise 技术调研 - 回调地狱的产生原因与解决方式
  18. row_number()的使用
  19. Selenium - 元素等待与智能等待
  20. 学习学习学习学习学习学习学习学习学习学习学习

热门文章

  1. 汽车动力性仿真matlab程序,汽车理论课程设计:基于Matlab的汽车动力性的仿真
  2. 确定位数的C语言程序设计,c语言程序设计
  3. “钱三篇”后续之利息-钱的时间价值!
  4. 使用纯 python 实现 Instruments 协议,跨平台 (win,mac,linux) 获取 iOS 性能数据
  5. python matplotlib设置字体大小_python – Matplotlib表的字体大小
  6. 机器学习-001-SVM线性可分-2020-4-28
  7. LQ0262 棋盘放麦子【大数+亿进制】
  8. 项目总结-网络舆情分析
  9. 【目标检测】YOLO系列——YOLOv1详解
  10. c语言程序设计勘误,《程序设计基础教程(C语言)》勘误表