说明
本系列文章是对<3D Apple Games by Tutorials>一书的学习记录和体会此书对应的代码地址
最终的实时渲染效果图

Lighting models(照明模型)

- Constant:使用一个扁平的照明模型,在计算渲染像素的颜色时,只包含ambient信息.
- Lambert:在计算渲染像素的颜色时,只包含ambient信息和diffuse信息.
- Blinn:在计算渲染像素的颜色时,只包含ambient信息,diffuse信息,specular信息,而且specular高光区是用Blinn-Phong法则计算的.
- Phong:在计算渲染像素的颜色时,只包含ambient信息,diffuse信息,specular信息,而且specular高光区是用Phong法则计算的.
- PBR:即Physically Based Rendering基于物理的渲染,包含了真实情况下,物理光源和材质对光的漫反射和吸收.
Materials(材质)
一般也就是textures(纹理).
纹理实际是2D图片按照几何体内部的纹理坐标系展开,包裹在3D几何体表面.所有Scene Kit内部自带的初始形状已经包含了这个坐标信息.
-
Diffuse map(颜色贴图,漫反射贴图):给几何体一个基本的颜色纹理,不考虑灯光和特效:
QQ20170409-111646@2x.png
-
Normal map(法线贴图):在上篇文章的灯光里讲过,灯光是使用形状表面的法向量来决定照亮哪个面的.系统自带形状是使用单一的整个面的向量,而法线贴图则以RGB值定义了精确到每个像素的法向量,这样每个像素对灯光的反应都不同,形成表面崎岖不平的灯光效果.
QQ20170409-111705@2x.png
QQ20170409-111814@2x.png
-
Reflective map(反射贴图):以黑白图片精确定义了材质每个像素的反光程度.就是周围环境的光线在物体表面映射出的图像(实际就是天空盒子图像在物体表面的反光).
QQ20170409-111848@2x.png
QQ20170409-111903@2x.png
需要注意的是
Xcode8之前,反射贴图和前面两个贴法不同,不是直接拉伸包裹在几何体上面的,而是用cube mapping(立方体贴图)来完成的.想像一个立方体,六个面的纹理并排水平放置,就形成了立方体贴图:


Xcode8之后别的形式立方贴图也可以,:

Xcode8还支持了1:2的球面贴图:

- Occlusion map(闭塞贴图):也就是ambient occlusion map(AO贴图,环境光闭塞贴图),只有当场景中有ambient light环境光时才有作用,精确定义了每个像素在环境光作用下的被照亮程度.也就是让几何体的黑色部分不被环境光照亮而变浅.


-
Specular map(镜面贴图,高光贴图):镜面贴图决定了几何体的镜面程度,黑色部分就是不光滑,白色就是光滑反光.会影响Normal map(法线贴图)外部光线照射反光和Reflective map(反射贴图)外部天空盒子图像反光的清晰程度
QQ20170409-111949@2x.png
QQ20170409-112002@2x.png
-
Emission map(发光贴图):在没有光线时,如果物体表面有荧光涂料,就会发光.发光贴图可以用来模拟这种物体.彩色贴图中,黑色不发光,亮色发光强,暗色发光弱.
QQ20170409-112012@2x.png
QQ20170409-112024@2x.png
需要注意的是
在Scene Kit中Emission map(发光贴图)并不真正发光,只是模拟发光效果而已.就是说不能照亮其他物体,不能产生阴影.这点与其他3D创作工具不同. -
Multiply map(乘法贴图,正片叠底贴图):会影响其他所有效果.一般用来给最后的效果调整色彩或者亮度.
QQ20170409-120113@2x.png

-
Transparency map(透明贴图):黑色部分不透明,白色透明.
注意:球体内部需要开启double-sided mode才能看到
QQ20170409-120138@2x.png

- Metalness and Roughness maps(光泽度和粗糙度贴图):Xcode8引入的新特性,Physically Based Rendering (PBR)灯光模型可以使用Metalness和Roughness贴图.
WX20171203-142500@2x.png

skybox天空盒子
设置方法如图,也可以用代码设置

let scene = SCNScene()
scnView.scene = scene
scene.background.contents = "skybox01_cube.png"
当使用Cube map立方体贴图时,Scene Kit支持以下几种图像模式
1. A horizontal strip image where `6 * image.height == image.width`水平排列宽高6:1
2. A vertical strip image where ` image.height == 6 * image.width`竖直排列宽高1:6
3. A horizontal cross image where `4 * image.height == 3 * image.width`水平十字交叉宽高3:4
4. A vertical cross image where `3 * image.height == 4 * image.width`竖直十字交叉宽高3:4
5. A lat/long image where ` image.height == 2 * image.width`经纬度图片宽高1:2
6. A NSArray of 6 images. This array must contain images of the exact same dimensions, in the following order, in a left-handed coordinate system: +X, -X, +Y, -Y, +Z, -Z (or Right, Left, Top, Bottom, Front, Back).图片数组6张


网友评论
let gemSous = SCNGeometrySource.init(vertices: poinS)
let gemElem = SCNGeometryElement.init(indices: indexs, primitiveType: .triangleStrip)
let gem = SCNGeometry.init(sources: [gemSous,gemSous1], elements: [gemElem])
你研究下这几个类 应该就可以了