现在的位置: 首页 > 综合 > 正文

Ogre 1.7的地形系统

2013年09月06日 ⁄ 综合 ⁄ 共 5181字 ⁄ 字号 评论关闭

Ogre 1.7,包含一个新的地形组件:OgreTerrain Component,有如下功能:

  1. 独立于场景管理器的可选的OgreTerrain Component和Paging Component。
  2. 地形可编辑功能
  3. Hierarchical geometry batching,LOD越低,batch数目和vertex数目都会减少。最低LOD的时候,整个地形页就是一个单一的batch,这对于大型分页地形来说,比一般使用的固定tiles的地形系统有明显优势。
  4. 采用Skirts技术处理terrain crack。
  5. 内置的splatting layers支持,可配置的sampler inputs和pluggable material generators。
  6. 支持在后台线程中进行全局normal maps和light map的生成
  7. 内置地形的加载和保存,包括在后台线程中进行加载/处理
  8. LOD实时适用于相机设置(viewport sizes & LOD bias)

OgreTerrain在使用Paging Component的时候,并没有完全遵照Paging Component的设计。

  1. TerrainPaging:负责管理SectionFactory和管理TerrainPagedWorldSection(创建),这些本来是由PageManager来管理的。
  2. TerrainPagedWorldSection:负责管理GridStrategy和一个TerrainGroup(而不是一组Page)
  3. TerrainGroup:负责地形加载,使用了TerrainSlot。加载代码参考:TerrainGroup::loadTerrainImpl(TerrainSlot* slot, bool synchronous)
  4. Grid2DPageStrategy::notifyCamera > TerrainPagedWorldSection::loadPage > TerrainGroup::loadTerrain > TerrainGroup::loadTerrainImpl > Terrain::Terrain

Ogre 1.7使用了新的Sample Framwork,Sample Framwork实现了一个简单的game state 管理,可以进行多种场景的切换。

Sample_Terrain作为一个插件被SampleBrowser加载。

 

TerrainLayerSamplerSemantic

/** Enumeration of types of data that can be read from textures that are
specific to a given layer. Notice that global texture information 
such as shadows and terrain normals are not represented
here because they are not a per-layer attribute, and blending
is stored in packed texture structures which are stored separately.
*/
enum TerrainLayerSamplerSemantic
{
    /// Albedo colour (diffuse reflectance colour)
    TLSS_ALBEDO = 0,
    /// Tangent-space normal information from a detail texture
    TLSS_NORMAL = 1,
    /// Height information for the detail texture
    TLSS_HEIGHT = 2,
    /// Specular reflectance
    TLSS_SPECULAR = 3
};

 

TerrainMaterialGenerator

按名管理一组Profile和一个TerrainLayerDeclaration(一个TerrainLayerDeclaration = 一组TerrainLayerSampler + 一组TerrainLayerSamplerElement)

TerrainMaterialGeneratorA

实现normal mapped, specular mapped terrain material。在Terrain要通过Terrain::getMaterial获得该Terrain的Materla的时候,会调用TerrainMaterialGeneratorA::SM2Profile::generate如何动态生成Terrain Material(值得参考)。不过它是一个Terrain使用一个Material,这点不符合我的需要。

Terrain

OgreTerrain 的Terrain分隔成hierarchical tiles,按Hierarchical geometry batching渲染。

Batching is also highly configurable, since you set a 'min batch size' and 'max batch size'. These 2 metrics determine how much the terrain is split up. A batch is any patch of triangles at a hierarchy level. The leaves of the quadtree that represents the hierarchy can range from the maximum batch size, to the minimum batch size at their lowest LOD, and then after that 4 adjacent patches at the min batch count get grouped into one parent patch at the min batch size to drop LOD. So, a large difference between the min and max batch size gives you more LOD levels at lowest level of the quad tree, so more flexibility in LOD picking (because each low-level patch can make its own LOD decision - when moving up the tree all 4 patches have to agree that it's time to drop LOD for it to happen), but at the expense of less efficient batching. You can tweak the absolute and relative values of these batch sizes to get the balance you need between vertex count and batch count.  

Terrain::prepare(StreamSerialiser& stream)

地形文件.dat的加载和解析是在TerrainGroup::handleRequest调用中从Terrain::prepare(StreamSerialiser& stream)开始,数据加载到System Memory。

  1. 通过TerrainGlobalOptions,得到全局选项。
  2. 从.dat中读取TERRAIN_CHUNK_ID标示的chunk。读取的内容如下:
    1. TERRAIN_CHUNK_ID
      1. The alignment of the terrain (OgreTerrain可支持悬挂地形)
      2. Terrain size (along one edge) in vertices (地形长宽尺寸,按vertex计算)
      3. The world size of the terrain (地形的世界坐标尺寸)
      4. Maximum batch size (along one edge) in vertices; must be 2^n+1 and <= 65(tile的最大尺寸,按vertex计算)
      5. Minimum batch size (along one edge) in vertices; must be 2^n+1(tile的最小尺寸,按vertex计算)
      6. the position of the centre of the terrain (地形的中心点)
      7. The height data (每个height是32bit)
    2. TERRAINLAYERDECLARATION_CHUNK_ID (samplers + elements + Layers)
      1. sampler 的数目(sampler that will be used with each layer)
      2. 读取所有的sampler,每个sampler都保存在TERRAINLAYERSAMPLER_CHUNK
        1. TERRAINLAYERSAMPLER_CHUNK_ID
          1. sampler descriptive name that is merely used to assist in recognition
          2. The format required of this texture
      3. elements数目(sampler that will be used with each layer)
      4. 读取所有的elements,每个elements都保存在TERRAINLAYERSAMPLERELEMENT_CHUNK
        1. TERRAINLAYERSAMPLERELEMENT_CHUNK_ID
          1. The source sampler index of this element
          2. The semantic this element represents
          3. The colour element at which this element starts
          4. The number of colour elements this semantic uses (usually standard per semantic)
      5. 读取所有的layers,每个layers都保存在TERRAINLAYERINSTANCE_CHUNK
        1. TERRAINLAYERINSTANCE_CHUNK_ID
          1. The world size of the texture to be applied in this layer
          2. List of texture names
      6. Packed layer blend data
        1. size of the blend maps for a terrain
        2. 读取所有的的blendmaps,放入到mCpuBlendMapStorage
      7. derived data
        1. TERRAINDERIVEDDATA_CHUNK_ID
          1. normalmap
          2. lightmap
          3. colourmap
          4. compositemap
    3. 读取完了地形数据后,构造整个QuadTree。

QuadTree的每个TerrainQuadTreeNode都有一个SceneNode和MovableObject和Renderable。 最后得到的是一个QuadTree树和一个ScreenNode树,QuadTree节点都为TerrainQuadTreeNode。ScreenNode树深度为2。一个单边513的Terrain会得到如图示的2个树。QuadTree是在TerrainGroup::handleRequest调用Terrain::Prepare中建立的;而ScreenNode树是在TerrainGroup::handleRequest中调用TerrainQuadTreeNode::load建立的。

 image

  1.  
    1. Terrain::distributeVertexData按照OgreTerrain的LOD算法,找到拥有vertex的TerrainQuadTreeNode,然后调用assignVertexData,开始创建缓冲区VertexDataRecord。VertexDataRecord包含了vertex data和index data。

Chunked LOD (http://tulrich.com/geekstuff/sig-notes.pdf)

眼睛看过太多的地形渲染算法了,但是最后发现脑子里遗忘的永远是现在就要用到的。为了掌握和改造OgreTerrain,又要翻出http://tulrich.com/geekstuff/sig-notes.pdf这篇文章来复习Chunked LOD

参考:

New Terrain Early Shots

Ogre终于开始改进其对地形渲染的支持

Paging as a core feature - design notes

Chunked LOD (http://tulrich.com/geekstuff/sig-notes.pdf)

Building Ogre Trunk (1.7)

Building CEGUI

PCRE for Windows (Win32)

Blend maps: enhanced terrain texturing

抱歉!评论已关闭.