开始学习第4章 - 着色器的反射
看完了1、2节,来记录一下。反射主要是利用了 Cubemap 立方体贴图。
认识Cubemap
立方体贴图,就如同名字所说,在一个立方体上有6张图,就这样认为吧。
假想一下 ,在一个艳丽的房间里,有一个表面是镜子的圆球,那这个圆球表面就反射了房间里面的所有东西,就是一个大号的凸镜。
这是到网上找得一张图,很直观的表达了我的意思……
注意标题中说的,静态立方体贴图,为什么叫静态,因为这一次使用的立方体贴图是提前生成好的图片,而不是动态生成的。
这又是什么意思呢?
就拿上面图片中的场景来说,如果是静态的立方体贴图,那么当这个球在移动的时候,球上面显示的东西是不会变动的。
现实生活中的话,球移动,球上面显示出来的内容应该也是要随之变动的。
那么这里使用静态立方体贴图呢,是先学习立方体贴图的知识,后面会学习动态立方体贴图的,在书上是 4.6 这一节。
创建Cubemap
首先来创建一个立方体贴图,在Assets 中右键新建一个 Cubemap。
搭建场景,添加一个Sphere 作为Camera 的容器。因为要借助 Camera 的 API 来生成Cubemap。
转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
下面是我搭建的场景。
下面编写一个Unity编辑器插件来生成CubeMap。
using UnityEngine;using System.Collections;using UnityEditor;pub