The following is the code for creating HeightField in Bullet
Code: Select all
//Terrain information
//width: 2049
//height: 2049
//pHeightData: scaled values in [-24.2, 24.2]
//minHeight: -24.2
//maxHeight: 24.2
//upIndex: 1 (y axis)
btHeightfieldTerrainShape*
heightFieldShape = new btHeightfieldTerrainShape(
width, height,
pHeightData, 1.0f,
minHeight, maxHeight,
upIndex, PHY_ScalarType::PHY_FLOAT, flipQuadEdges);
//Scale nothing
btVector3 localScaling(1, 1, 1);
localScaling[upIndex] = 1.0f;
m_pGroundShape->setLocalScaling(localScaling);
//create terrain object
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(0, 0, 0));
btRigidBody* pBody = LocalCreateRigidBody(0, tr, m_pGroundShape);
1.Vertex shader
Code: Select all
output.positionW = input.positionL;
Code: Select all
//e0,e1, ... are the centeres of each edge of the patch
float3 e0 = 0.5f*(patch[0].positionW + patch[2].positionW);
float3 e1 = 0.5f*(patch[0].positionW + patch[1].positionW);
float3 e2 = 0.5f*(patch[1].positionW + patch[3].positionW);
float3 e3 = 0.5f*(patch[2].positionW + patch[3].positionW);
float3 c = 0.25f*(patch[0].positionW + patch[1].positionW + patch[2].positionW + patch[3].positionW);
output.EdgeTess[0] = CalcTessFactor(e0);
output.EdgeTess[1] = CalcTessFactor(e1);
output.EdgeTess[2] = CalcTessFactor(e2);
output.EdgeTess[3] = CalcTessFactor(e3);
output.InsideTess[0] = CalcTessFactor(c);
output.InsideTess[1] = output.InsideTess[0];
Code: Select all
//After tesslating vertecies from Vertex Shader
//I used such vertices to get the height data.
dout.positionW = lerp(
lerp(quad[0].positionW, quad[1].positionW, uv.x),
lerp(quad[2].positionW, quad[3].positionW, uv.x),
uv.y);
dout.positionW.y = gTexHeightMap.SampleLevel(gSmpHeightMap, dout.texCoord, 0).r;