武俠世界,基於Ogre的地形分析

2021-05-27 08:15:39 字數 2612 閱讀 1460

早期的天龍八部跟武俠世界基本相似。

.scene

場景的一些基本資訊,包括light,skydome,環境光,霧以及場景中靜態模型staticentity等。摘錄部分檔案如下:

<?xml version="1.0" encoding="utf-8" standalone="no" ?>

...

.terrain

地形的分塊方式,乙個tile由n個grid組成,tile為ogre的mesh,grid不可再分。scale為grid縮放比例。heightmap,gridinfo分別對應相應的檔案,lightmap場景陰影圖。中包含地形所需的紋理資訊。將對應的texture再次細分。關於地形使用兩層紋理的材質,ogre中材質概念包含shader。摘錄部分檔案如下:

<?xml version="1.0" encoding="utf-8" standalone="no" ?>

...

...

fairterrain.material中包含材質terrain/onelayer,terrain/onelayerlightmap等,部分如下:

material terrain/onelayer

fragment_program_ref terrain/onelayer_ps

texture_unit

} }

// fixed-function pipeline

technique

} pass

} }}

fairyterrain.program中相應的vs,ps

vertex_program terrain/onelayer_vs cg

}fragment_program terrain/onelayer_ps cg

fairyterrain.cg中的shader

void onelayer_ps(

in float2 uv0 : texcoord0,

in uniform sampler2d layer0,

in float4 diffuse : color0,

in float4 specular : color1,

in float fog: fog,

out float4 ocolour : color)

void onelayer_vs

( float4 pos :position,

float4 vertexcolor:color,

float4 vertexcolor2:color1,

float2 tex :texcoord0,

float4 normal :normal,

out float4 oposition :position,

out float4 odiffusecolor :color0,

out float4 ospecularcolor :color1,

out float2 oorigtex :texcoord0,

out float ofog: fog,

uniform float4x4 worldviewprojmatrix,

uniform float4 eyeposition,

uniform float4 lightposition,

uniform float4 lightdiffuse,

uniform float4 lightposition1,

uniform float4 lightdiffuse1,

uniform float4 lightspecular,

uniform float4 lightspecular1,

uniform float4 ambientcolor,

uniform float4 ambientmat,

uniform float4 specularmat)

if(diffuselight1>0)

//specularcolor *=defaultspecular;

ospecularcolor.rgb = vertexcolor.xyz*specularcolor.rgb*specularmat.rgb;

ospecularcolor.a = 1;

}

.gridinfo

先前有文章介紹過:

.heightmap

地形高度圖

.region

代表地形中不可行走區域

.wcollision

遊戲中用來實現「碰撞」的,下圖粉紅色區域即為wcollision資訊:

橋的下面是熔漿,不允許行走的,但是可以從橋上通過,而遊戲不是根據橋這個mesh來實時檢測玩家所應該處的高度,而是通過wcollision裡所記錄的資訊來判斷的。

部分摘自:

整合OGRE和bullet的地形

把ogre和bullet的地形整合在一起比預想中的麻煩。主要是兩個問題 通過heightfield生成三角形網格的方式不一樣,以及heightfiled定址方式不同 ogre轉換成float陣列後,以坐下角為 0,0 點,而bullet的btheightfieldterrainshape類是左上角 ...

Ogre 1 7 2中的地形教程

讀者可以對照著ogre1.7.2中的terrain.h原始碼進行閱讀加深理解,藍色部分均為原始碼 去除了一些具體場景比如新增mesh,設定setambientlight等與terrain無關的操作 下面這段 在setupcontent 函式中,使用過ogre1.6.5的一定對createscene ...

基於patch的地形PVS資料預處理 續

前面一篇說了pvs資料的預處理,當時是用純cpu來計算patch之間的可見性。後來聽說有個idirect3dquery9介面可以判mesh的可見性,就試了一下,果然比用純粹cpu計算快了很多。計算同樣的512地圖的pvs資料,原來的演算法需要4.7小時,利用gpu之後縮短到了不到800秒,快了大約2...