Archived

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

small textures into one 256x256 texture...and the WRAP effect?

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi game programmers, I have many small textures in my scene. Then, I wrote a routine to put them in larger textures - 256x256 (I hope to increase the fps with this...). My method is: VOID ClasseMalha::ManipulaTextura(int xi, int yi, int xf, int yf, int tamanho) { . . . D3DXMATRIX MatEsc, MatTransl; // É necessário retirar uma fina borda (espessura de 1 píxel) // da seleção para não se ter problemas com o mipmap xi = xi+1; yi = yi+1; xf = xf-1; yf = yf-1; D3DXMatrixTranslation( &MatTransl, (float)xi/tamanho, (float)yi/tamanho, 0.0f ); D3DXMatrixScaling( &MatEsc, (float)(xf-xi)/tamanho , (float)(yf-yi)/tamanho, 1.0f ); D3DXMatrixMultiply( &MatEsc, &MatEsc, &MatTransl ); MatEsc._31 = MatEsc._41; MatEsc._32 = MatEsc._42; MatEsc._33 = MatEsc._43; DispositivoD3D->SetTransform( D3DTS_TEXTURE0, &MatEsc ); . . . } It works fine when the mesh doesn''t have wrapped textures. Please, what should I do to resolve the wrapped problem? (considering that I want to apply the wrap effect only in the area of interest in the large texture) Normally, I apply wrapped effect using 3d studio max. I made a test: I compared the fps with four 128x128 textures vs one 256x256 texture that contain those four and I didn''t notice a significant difference. I believe the results will be better with many textures... thanks for the attention.

Share this post


Link to post
Share on other sites
Please, what should I do to resolve the wrapped problem? (considering that I want to apply the wrap effect only in the area of interest in the large texture)

What problem are you having? You say later on that it simply isn''t going any faster.

Plus, you can click "Edit", which is above and to the left of your post, to edit.

Share this post


Link to post
Share on other sites
Hi, Adriano.

In my experience it's best to batch multiple images in one texture, only if you're not going to use wrapping.

In fact, as far as I know, there's no way to wrap a 'subtexture' (at least using the fixed function pipeline) other than having your meshes divided into many quads and applying the 'subtexture' to each quad.

Also, in your code you comment:

quote:

// É necessário retirar uma fina borda (espessura de 1 píxel)
// da seleção para não se ter problemas com o mipmap



"It's necessary to take out a thin border (1 pixel wide) from the selection so not to have problems with mipmapping." If I translate correctly...

I can assure you one pixel won't be enough. The further away form the camera your object goes, the wider the border has to be. To make things look right, you'll have to loose at least a third of your texture if you don't want neighboring tiles to bleed on each other.

My advice is, keep your textures each in their own file. Batch only those which belong to small objects on which you're not using texture wrapping. If your scene is getting a low FPS count, make sure you're optimizing your meshes so as to set each texture just once per frame.

Good luck,



Mariano Ruggiero
Lead Programmer
ONIRIC GAMES

[edited by - Night Elf on November 27, 2003 10:37:40 PM]

Share this post


Link to post
Share on other sites
OK PlayGGY,

I will try to explain the problem:

Suppose that I have a wall (mesh) and I will map it with a small brick texture. Of course I will make a wrap. I can make this in the D3D code or I can use a modelling software like 3d studio max and export a file (a x-file, for example).
I choice to use 3d studio max (it is very practical).

OK, as the brick texture is very small (64x64, for example) SDK DX guide recommends that I place it into one 256x256 texture, that is the fastest.
My simple code scales and translates the 256x256 texture in way to fit the region that contains the bricks (the small texture).
The problem is that when I "select" that region, the other parts of the 256x256 texture appears. It doesn''t happen if I use no wrap. In other words: if there is no wrap, the selected region appears perfectly.

Thanks for the attention.

Share this post


Link to post
Share on other sites
Muchas Gracias Mariano,

Yes, you translated correctly.
...it seems that there are not great advantages in use multiple images in one texture, since there is a limited application of the mipmapping.
In your experience, do you have a significant increase of the fps with multiple images in one?

Thanks.

Share this post


Link to post
Share on other sites
Well, the fewer textures the faster, so putting multiple textures in one file has its advantages. But as it has quite a few limitations, I use it very rearly...

You should be able to use a fair amount of textures without hurting performance too much, but it depends on the hardware. But the key, as I said, is to apply your textures only once per frame.



Mariano Ruggiero
Lead Programmer
ONIRIC GAMES

Share this post


Link to post
Share on other sites
Hi Mariano,

Thanks for your answers.
You said that the key is "set the textures only once per frame".
Well, normally I used DrawSubset method to render my meshes... something like:

for(DWORD i = 0; i < NroMateriais; i++)
{
DispositivoD3D->SetMaterial(&Materiais);
DispositivoD3D->SetTexture(0, Texturas[i]);
malha->DrawSubset(i);
}

I thought to create one (big) x-file for each texture, so the SetTexture is called once per frame... but if I have many objects, my frustum/culling method will be limited...
Please, could you explain a better way (using DrawSubset method) to set the textures only once per frame?

Thanks for your attention and your patience.

Adriano.

Share this post


Link to post
Share on other sites
OK,

I was already using the following:

DWORD *pAdj = new DWORD[malha->GetNumFaces()*3];
malha->GenerateAdjacency(0.0f,pAdj);
malha->OptimizeInplace(D3DXMESHOPT_ATTRSORT, pAdj, NULL, NULL, NULL);

If I understood, the OptimizeInplace method reorders the faces of the ONE ID3DXMesh (is it right?)

Suppose that you have a small 3D city, where the roof of the houses have the same texture. Each house is one ID3DXMesh.

If I call the render function, like:
...
house1->RenderMesh();
house2->RenderMesh();
house3->RenderMesh();
...
where RenderMesh() sets materials, textures and draws the subset of the mesh, the roof texture will be set more than once per frame, right?


Share this post


Link to post
Share on other sites

house->RenderMesh, rather than actually rendering anything, could add the list to a group of buckets (sorted by mesh type). This would allow you to do higher level culling and limit yourself to visible objects. Then (psuedo code):

foreach subset in house
foreach house in list
Drawsubset house(subset)
end
end




Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites