Archived

This topic is now archived and is closed to further replies.

NotTaxes

Dynamic Texture Masks?

Recommended Posts

Howdy, what I am trying to do now is get fuzzy interfaces between adjacent textures. Let''s say that I have a Rock texture and then the terrain moves to Grass. Applying these on a per-triangle basis gives me a rectangular interface between the two like this GGGGG GRGGG RRRRR and the rock in the middle line looks really weird and blocky. I can go the route of creating 100''s of interlocking tiles (that is, create a unique rock/grass tile for when the block to the left is grass, the one above is grass, the one to the right is grass and the one below is Rock... if you follow me), but that is huge amounts of work. I figure that the best way of doing this is to create alpha-tiles that are just grey-scale bitmaps and then somehow blend them with the two merging textures. So, we would have: Blend Grass Texture with Map Texture to create a new Grass texture with alpha-bits faded out. Draw the Rock Texture. Draw the blended grass&alpha texture onto the rock, causing an effect that blends from the rock to the grass. I could then use 50 or so Alpha textures to create blends between any two textures (diagonal lines, curvy bits, corners, etc). I tried using texturestages, but I can''t get the grass&rock textures to blend properly and still yield an alpha-channelled bitmap... it creates instead a grass tile with one half painted black. Can someone with more knowledge of texture stages perhaps supply a quick code snippet? Would be hugely appreciated. ''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
Oh... also, the SDK says that some vidcards doen''t support multi-texturing. Am I right in thinking that multi-texturing = multi-texturestages and if so, does anyone know what the lowest generation card is that supports mt? That is, if I code this thing to run on Voodoo 2 and higher, is that going to be cool? Yeah, I can check the devcaps to find out what''s available on the installed machine, but I''d rather be able to say, "I''m going to write for xyz generation hardware" than write the thing, only to find out it only runs on VeryHighEnd only.

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
Hi.

I decided too it would be safer to not use multiple textures. I used instead square bitmaps and a series of black and white mask bitmaps to make transitional tiles. Then I punch them into my textures.

This is the code I use, I''m sloppy I know but every now and then I do tidy things up a little bit. The masks are 24-bit as well, yes, very wasteful. Anyway it might give you some ideas.
   
//*********** TEXTURE WITH BITMASKS CODE HERE **********

x = 22;

struct stTextureFile
{
char UnderTexture[9];
char OverTexture[9];
char MaskType[9];
};

stTextureFile *TextureFile = NULL;
TextureFile = new stTextureFile[x];

FILE *ControlTexture;

// I have the names of the bitmaps in the control file


if (( ControlTexture = fopen("Texmast.mff", "rt")) == NULL)
{
MessageBox(g_hWnd, "Open control is screwed", "Error Box", MB_OK);
return false;
}

size_t numreadmaster;

numreadmaster = fread( TextureFile, sizeof(byte), 594, ControlTexture);
fclose(ControlTexture);

D3DLOCKED_RECT Locked;
byte *dest;
int index;

int Ycolourbytes;
int Xcolourbytes;

byte *buffer1 = new byte [49206];
byte *buffer2 = new byte [49206];
byte *buffer3 = new byte [49206];

for (index = 0; index < 49206; index++)
{
buffer1[index] = 0;
buffer2[index] = 0;
buffer3[index] = 0;
}

// Yes I could use memset or zeromem but I don''t trust them


FILE *fp1; //** Bottom image

FILE *fp2; //** Top image

FILE *fp3; //** Mask


size_t numread1, numread2, numread3;

for (x = 0; x < 22; x++)
{
g_hr = D3DXCreateTexture(g_pDevice, 128, 128, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &g_pTexture[x]);

g_pTexture[x]->LockRect( 0, &Locked, 0, 0 );

if (( fp1 = fopen(TextureFile[x].UnderTexture, "rb")) == NULL)
{
MessageBox(g_hWnd, "Open is screwed", "Error Box", MB_OK);
return false;
}

if (( fp2 = fopen(TextureFile[x].OverTexture, "rb")) == NULL)
{
MessageBox(g_hWnd, "Open is screwed", "Error Box", MB_OK);
return false;
}

if (( fp3 = fopen(TextureFile[x].MaskType, "rb")) == NULL)
{
MessageBox(g_hWnd, "Open is screwed", "Error Box", MB_OK);
return false;
}

numread1 = fread( buffer1, sizeof(byte), 49206, fp1);
numread2 = fread( buffer2, sizeof(byte), 49206, fp2);
numread3 = fread( buffer3, sizeof(byte), 49206, fp3);

for (Ycolourbytes = 0; Ycolourbytes < 128; Ycolourbytes++)
{
dest = (BYTE*)((BYTE*)Locked.pBits + Ycolourbytes * Locked.Pitch );
index = 0;

for (Xcolourbytes = 0; Xcolourbytes < 384; Xcolourbytes +=3)
{
// All the +54 bizzo is just skipping over the bitmap header

// If mask bit is black ...

if (buffer3[(Ycolourbytes * 384) + Xcolourbytes + 0 + 54] == 0 && buffer3[(Ycolourbytes * 384) + Xcolourbytes + 1 + 54] == 0 && buffer3[(Ycolourbytes * 384) + Xcolourbytes + 2 + 54] == 0)
{
// Punch in bit from undersurface ...

dest[index + 3] = 0; //** alpha

dest[index + 2] = buffer1[(Ycolourbytes * 384) + Xcolourbytes + 2 + 54];
dest[index + 1] = buffer1[(Ycolourbytes * 384) + Xcolourbytes + 1 + 54];
dest[index + 0] = buffer1[(Ycolourbytes * 384) + Xcolourbytes + 0 + 54];
index += 4;
}
else
{
// Punch in bit from oversurface ...

dest[index + 3] = 0; //** alpha

dest[index + 2] = buffer2[(Ycolourbytes * 384) + Xcolourbytes + 2 + 54];
dest[index + 1] = buffer2[(Ycolourbytes * 384) + Xcolourbytes + 1 + 54];
dest[index + 0] = buffer2[(Ycolourbytes * 384) + Xcolourbytes + 0 + 54];
index += 4;
}
}
}

fclose(fp1);
fclose(fp2);
fclose(fp3);

g_pTexture[x]->UnlockRect(0);

}


El Duderino

Share this post


Link to post
Share on other sites
That''s all pretty cool, but... well, my FPS drop to around 5 ''coz of all the manual pixel shunting. I can pre-cache the stuff, but that lends itself to monsterous memory useage. Any other ideas?

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
Errr ... I wouldn''t suggest doing this sort of thing while the game is supposed to be playing.

Just create the needed textures at appropriate times (level inits) and let the system manage them for you. Even if your textures are 128*128 and 32bits each, that''s 65k per texture. You can have 256 or so of these in 16meg ... and so what if they overflow into system memory, it''s not the end of the world. Way better than 5 fps in any case.

El Duderino

Share this post


Link to post
Share on other sites
Ahhhh. I see... sorry, my math took a dive for the worse and added a 0 to MB required :-)

Thanks for that, will give it a try.

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites