# 7.1 introduction
## 7.1.1 geometry choice
- 使用mesh based terrain,而不是高度图
- 为了artist flexibility
## 7.1.2 texture choice
- 用texture atlias,在若干sample间差值得到结果
- 还reliable on precomputed data
- 好处自然是省空间(比起那些每个点都是不重复texture uv的方案)和bandwith
# 7.2 content creation and editing
## 7.2.1 workflow
- 首先是做出最简单的terrain layout和简单模型来给designer test functionanlity
- 对terrain model做erosion(world machine?).object mesh做vertex AO. texture也开始制作
- 导入in game editor,地形被分成若干chunk,lod生成
- manual paiting(terrain和mesh object)
# 7.2.2 determining soil type
- soiltype是precomputed,就是拿贴图存
# 7.2.3 procedural rules stored in LUT
- 这个是没使用的方法
- 用LUT(slope, height value)来决定terrain type
# 7.2.4 procedural and manual paiting stored in UV-space tilemap
- 有个覆盖整个terrain的map,rgb存tint color,a存terrain type
- 这样地形上的一大块就是同一个terrain type和tint color
- 这个map的精度可能成为问题
- sample的时候用bilinear filtering,这样index过度就有了,但是也会导致不相邻的index间blend不对,可以通过duplicated index来解决(比如sand0,grass1,rock2,0到2的直接过度就是不可能的)。不过这个问题被一笔带过了
# 7.2.5 Procedural and Manual Painting Stored in Mesh vertices
- xxxxx
# 7.5 runtime shading
- 核心算法是:在shade一个点时根据terraintype在atlas上找多个点,然后根据权重blend
- atlas的不同block不应该在生成mipmap时混在一起,可以先互相独立地生成atlas然后再拼起来
- 由于用了atlas,需要能在subblock里正确地wrap,得自己模拟硬件的mipmap计算机制
- 但是由于自己算的uv derivative会在wrap的不能正确,所以会有接缝(只要正好在tile的边缘)
- 有多种做法,要balance性能和正确性
- 1. 手工地正确地算miplevel,extra ALU cost,而且手工指定miplevel还导致texture fetch变慢,从而又引入了latency。可以手工调节GPR的数量来增加并行度来hide latency
- 2. 有些平台也有直接返回应该用的miplevel的指令
- 3. 还可以用dynamic branch,如果2个sample点都在中间那就直接用硬件sample就好
- 4. 有个获得应该用的sample miplevel的办法:弄张简单地贴图,每层mip上存上当前mip的等级。这样在这上面sample出来的就应该是当前正常情况下用的miplevel。然后用这个结果去tex2dlod
- 最终使用的是dynamic branch那套,另外mipmap只生成4级,这样seam就不是1像素的mip了(可是用了dynamic branch后不久不应该再有seam了吗?还是说也不用dynamic branch了?)
- 另外atlas改成1x16,这样x方向可以完全没问题
- lighting: simple lambert diffuse + hemispherical ambient
- shadowing: precomputed blurred static shadowmap, crossing fading with a cascaded dyanmic and blurred ESM(exponential shadowmap)
# 7.6 performance
- 10km2 600k triangle 14MB 6ms
- 切块使得16bit indices可能 小于1km2的block
- 有kdtrree culling
- LOD就是通过skip vertex来生成的
# 7.7 possible extensions
- heightmap based geometry可以更compact,但是没法处理steep slope的texturedistortion。说是可以考虑在grid里存position offset(就是说要能offset原本固定间隔的heightmap vertex?)
- texturing方面。可以考虑sample2次,分别用不同的tiling factor,这样既有细节也有宏观特征(如果使用但一个tiling factor,远近的表现不能兼顾(走近了如果tiling factor不够小,则进出没细节。反之在远处看,如果tiling factor不够大,就能看出明显的重复来)
- another option
- reduce tiling factor, blend in desaturated detail texture up close.就是说tiling factor只保证远处看时ok,近处看的细节用一张额外的detail texture来搞?
- defactor method
- 近处用per pixel splatting,远处用detail teture,transition region可以用专门的blendmap来搞(和diffuse的rgb pack在一起)
- 可以用ambient aperture lighting(好像就是菊哥说的bent normal,用一个锥(normal和disk半径)来大概指出surface受到的lighting来自哪个方向
- 还提到可以cache previously computed fragment data,但是摄像机应该经常在移动吧?