PDA

View Full Version : texture splatting



Nick's a Novice
04-15-2006, 03:22 AM
I'm kind of stuck at a point here in my graphics engine. I was hand painting transition textures, but that is getting old realy fast. I read charles blooms article on texture splatting, and it seems to be the way I want to go with this. My terrain is loaded into a display list, and then displayed. I am calling the list twice and blending the two for my shadow volumes. It is a 200x200 array of vertices right now drawn using triangle strips. I have 3 different textures thus far but I would like to use as many as 10. I got the basic concept behind the texture splatting, but I'm a little dense when it comes to transitioning between concept and actual code. What I need is pseudo-code for blooms concept; basically a step by step walk through on it. Thanks in advance! Also if you think there is a better approach to fading between these multiple textures that still gives it a very realistic look let me know. Thanks again!

-Nick

ZbuffeR
04-15-2006, 10:23 AM
Did you read http://www.rainboxstudios.com/viewarticle.php?a=2 ?

(second google result for "charles blooms article on texture splatting" so I guess so)

Nick's a Novice
04-15-2006, 02:25 PM
yes I read that one, but I had a little trouble following it, i think because it used glew.lib. For my situation I have an array of 200x200 vertex points stored in:
float terrain[200][200][3]

I also have an array of the desired textures:
int teXtures[200][200]

which stores 0=grass, 1=dirt, 2=sand, etc.

I would like to create the terrain using multi-texturing to avoid too many passes. If anyone has a step by step walktrough to this or a similar code example, I would be greatly appreciative.

Nick's a Novice
04-15-2006, 11:44 PM
here is the code I'm using to display the terrain currently. It basically just draws the triangles for each texture. what do I need to do from here to get splating working. I want to use multitexturing and render it in 1 pass if possible.


void Terrain::GenerateLandL()
{

int tt=1;
srand((unsigned int) time(0));
g_land = glGenLists(1);
//float ms=1/MAP_X;
glNewList(g_land, GL_COMPILE);

for (tt=0; tt<=2;tt++)
{
if (tt==0)
{
glBindTexture(GL_TEXTURE_2D, rocks);
glColor4f(0.3f, 0.3f, 0.1f, 1.0f);
glBegin(GL_TRIANGLES);
}
else if (tt==1)
{
glEnd();
glBindTexture(GL_TEXTURE_2D, land);
glColor4f(0.6f, 0.6f, 0.6f, 1.0f);
glBegin(GL_TRIANGLES);
}
else if (tt==2)
{
glEnd();
glBindTexture(GL_TEXTURE_2D, rocks2);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
}
for( int z=0; z < MAP_Z-1; z++ )
{
for( int x=0; x<MAP_X-1; x++ )
{
if(detailmap[x][z]==tt)
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
//for each vertex we load a point from our terrain file insert that code here
glColor3f(terrain[x][z][1]/255.0f, terrain[x][z][1]/255.0f, terrain[x][z][1]/255.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(terrain[x][z][0], terrain[x][z][1], terrain[x][z][2]);

glColor3f(terrain[x+1][z+1][1]/255.0f, terrain[x+1][z+1][1]/255.0f, terrain[x+1][z+1][1]/255.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(terrain[x+1][z+1][0], terrain[x+1][z+1][1], terrain[x+1][z+1][2]);

glColor3f(terrain[x][z+1][1]/255.0f, terrain[x][z+1][1]/255.0f, terrain[x][z+1][1]/255.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(terrain[x][z+1][0], terrain[x][z+1][1], terrain[x][z+1][2]);

glColor3f(terrain[x][z][1]/255.0f, terrain[x][z][1]/255.0f, terrain[x][z][1]/255.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(terrain[x][z][0], terrain[x][z][1], terrain[x][z][2]);

glColor3f(terrain[x+1][z][1]/255.0f, terrain[x+1][z][1]/255.0f, terrain[x+1][z][1]/255.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(terrain[x+1][z][0], terrain[x+1][z][1], terrain[x+1][z][2]);

glColor3f(terrain[x+1][z+1][1]/255.0f, terrain[x+1][z+1][1]/255.0f, terrain[x+1][z+1][1]/255.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(terrain[x+1][z+1][0], terrain[x+1][z+1][1], terrain[x+1][z+1][2]);


}

}
}
}

glEnd();

glEndList();
}

Nick's a Novice
04-18-2006, 01:11 PM
Anyone got a simple way of explaining texture splatting for this setup?