I know...but I'm using phong shading not gouraud which really doesn't change much. I am renormalizing the normals or I'm telling Direct3D to do it...but I'm still getting the flickery crap.
I will implement a pixel shader or vertex shader very soon in HLSL...but not quite yet.
Voxels are what got me starting doing terrains and yes I've coded several and I have one in DirectX except that I changed something and now I don't have any height in it. I optimized it so much that I...optimized myself out of the code. I'm totally lost when I look at it. Shame, shame Bubba, I know.
The heightmap is 256x256 and the cellsize for those shots I think is about 10. The tile screenshot is using a cellsize of 4 and a texture increment the same size as the texture which causes it to tile nicely and yet gives a lot of detail up close. I can't tile the terrain texture because it is not tileable and looks ugly when it is done. The clouds are not going to stay there and I've changed the bitmap since those shots because that one sucks. You can clearly see the grid in the sky. Not anymore. Also using 2 alpha blended cloud layers so I can simulate some pretty cool stuff. The sun glare is simply going to be a pure white quad the size of the screen alpha blended depending on the sun's position (alpha coeficient is derived from sun's position). This will cause a white out. Cheesy but it works. Also I'm looking at some docs concerning real-time volumetric fog - might use this for the clouds...but major framerate hit for this.
BTW if anyone wants to help with models contact me. I do not have a 3D modeling program so I'm SOL right now. Also I rather suck at creating textures so I need some artists. Any help would be greatly appreciated. I'm a programmer and therefore I suck at art.
By the way the blockiness you are talking about comes from the fact that the map has a definite resolution and you are attempting to project a map on the screen that has more resolution than your map.
There are several things you can do.
First you need to select a cellsize for your world and a magnification factor. Larger cellsizes produce smoother terrain because the changes are not so abrupt but you will get flatter land unless you up the magnification factor. If its too high...same problem. Small cellsizes work well except that you must reduce the mag factor by a lot or you will have some very spikey terrain. Cellsize should be larger than 3. Any less and you effectively eliminate the magnification effect on the terrain. You will get nearly an exact representation of the heightmap on screen....which is blocky.
So here are things to remember:
1. Too blocky -> increase cellsize
2. Too flat -> increase magnification
Also you must change the walking speed of the player relative to your cellsize. Larger cellsizes will require bigger 'steps' or you will feel like you are crawling. Smaller cellsizes require smaller steps or you will feel like you are zipping across the terrain at light speed and it gives your terrain a very 'small cramped' feeling.
Here is some basic code to get you started:
Code:
...
...
int mapsizex=256;
int mapsizey=256;
int maxworldx=mapsizex*cellsize;
int maxworldz=mapsizey*cellsize;
int vertexnum=0;
float view_mag=3.0;
int cellsize=10;
for (int worldx=0;worldx<maxworldx;worldx+=cellsize)
{
for (int worldz=0;worldz<maxworldz;worldz+=cellsize)
{
int mapx=worldx/cellsize;
int mapz=worldz/cellsize;
TerrainVertexes[vertexnum].x=worldx;
TerrainVertexes[vertexnum].y=GetMapHeight(mapx,mapz)*view_mag;
TerrainVertexes[vertexnum].z=worldz;
vertexnum++;
}
}
...
...
And a simple average filter.
Code:
int numRows=(maxworldz)/cellsize;
int numCols=(maxworldx)/cellsize;
for (int i=0;i<numRows;i++)
{
for (int j=0;i<numCols;j++)
{
int pos_i=i+1;
int pos_j=j+1;
int neg_i=i-1;
int neg_j=j-1
if (neg_j<1) neg_j+=(numCols-1);
if (pos_j>numCols) pos_j-=(numCols-1);
if (neg_i<1) neg_i+=(numRows-1);
if (pos_i>numRows) pos_i-=(numRows-1);
int index0=neg_i*numCols+neg_j;
int index1=neg_i*numCols+j;
int index2=neg_i*numCols+pos_j;
int index3=i*numCols+neg_j;
int index4=i*numCols+j;
int index5=i*numCols+pos_j;
int index6=pos_i*numCols+neg_j;
int index7=pos_i*numCols+j;
int index8=pos_i*numCols+pos_j;
int h0=TerrainVertexes[index0].y;
int h1=TerrainVertexes[index1].y;
int h2=TerrainVertexes[index2].y;
int h3=TerrainVertexes[index3].y;
int h4=TerrainVertexes[index4].y;
int h5=TerrainVertexes[index5].y;
int h6=TerrainVertexes[index6].y;
int h7=TerrainVertexes[index7].y;
int h8=TerrainVertexes[index8].y;
int finalheight=(h0+h1+h2+h3+h4+h5+h6+h7+h8)/9;
TerrainVertexes[index4]=finalheight;
}
}
Can also be done with a matrix....but easier to show this. You can also linear interpolate:
vi=v1+f1*(v2-v1);
where f1 varies from 0 to 1.
or bi-linear interpolate:
v1i=v1+f1*(v2-v1);
v2i=v3+f1*(v4-v3);
vf=v1i+f2*(v2i-v1i);
where f1 and f2 vary from 0 to 1.