Hi everyone,
as always I am working on my strategy game. The last few days I reworked the code for terrain transformation to fit the trenches into the terrain (as it is a game set during World War One trenches are a rather important art and gameplay asset)
So a lot of games (like Company of Heroes) adjust only the z-value of the terrain-mesh vertices so the trenches fit in. In order to make this technique look good you need a very dense terrain mesh (like Company of Heroes
). Since I did not want to make the terrain mesh super dense (for various reasons, mostly for an easier workflow) I used a different technique and modified not only the z-value but also the x- and y-value of terrain-mesh vertices that are close to the trench model.
I implemented this some time ago but the result was very unsatisfying. The texture is stretched close to trenches and gaps in the terrain mesh appear at various places (red circles):
I recently came back to this and reworked the code. It is still the full vector-field displacement technique but I added some code for borderline cases (the places where the gaps appeared) and additionaly recalculated the uv-mesh after the deformation. The code for recalculating the uv-mesh
float level_extent = 2 * 11400;
ENTITY* terrain;
...
CONTACT* c;
int i = ent_status(terrain,0); // number of vertices
double multiplier = 1 / (level_extent);
for (; i>0; i--)
{
c = ent_getvertex(terrain,NULL,i);
c.v.u1 = (c.v.x + level_extent * 0.5) * multiplier;
c.v.v1 = 1 - (c.v.z + level_extent * 0.5) * multiplier;
ent_setvertex(terrain,c,i);
}
It took me some time to figure this out because the documentation for
ent_getvertex, ent_setvertex lacks some information. Especially on the various uv-mesh deformations.
But the reworked code makes the terrain look way more clean:
Still not perfect in every single aspect but I am really happy with the outcome. Next I want to improve the terrain shader. I still think the normal maps don't "stand out" enough and dynamic lights doesn't affect the terrain at all by now.
As always: Feedback is very welcomed, wether it is about the terrain or any other aspect of the game!
Best Regards