Multiple tiles in one texture.

Started by
19 comments, last by Kronuz 20 years, 10 months ago
In DirectX8, if we want to have a texture tiled, that''s easy, we only need to enter the uv texture coordinates as a range above 1... but what about if we want to tile just a part of the texture and not all of it? To say, let''s think about a "tile set" or an array of tiles contained in one texture, loaded from a single bitmap. I have been trying to do this, but since I''m new to DirectX I haven''t been able to figure this out. Should I use a texture transformation matrix or what?
"Fools rush in where fools have been before" - Unknown
Advertisement
That''s easy. For instance if you just want a quarter of your source texture to cover a tile - say the upper right quarter - use:

(u, v)
(0.5f, 0.0f) - (1.0f, 0.0f)
(0.5f, 0.5f) - (1.0f, 0.5f)

I see what you are saying.... but that way I would only get that part of the texture rendered just once on the primitive, but what I need is to have that part of the texture tiled (rendered several times, or wraped) on the primitive.

Let's say we have a bmp file with several images a "tile set" or tile array (each number irepresents a image or sprite; the image 1 and 3 are 30x40 pixeles; the x represents not usable or empty space):

111223333
111223333
111222333
1114444xx
5554444xx
5554444xx

After loading the bitmap we end up with a texture like the next one (the asterisks represent empty space left there by DirectX to make the texture a 2^n texture sqare)

111223333*
111223333*
111222333*
1114444xx*
5554444xx*
5554444xx*
**********
**********
**********
**********

What I want is to be able to tile a single image (a part of the texture) to a primitive. For example what should I do to wrap image 4 in a rectangle like this:

4444 4444 4444 4444 4444
4444 4444 4444 4444 4444
4444 4444 4444 4444 4444
4444 4444 4444 4444 4444

4444 4444 4444 4444 4444
4444 4444 4444 4444 4444
4444 4444 4444 4444 4444
4444 4444 4444 4444 4444

I was thinking about using the hardware to do this tiling, but without having a separate texture for each tile in the "tile set". I was told that it might be possible using pixel shaders, but I don't know how to... besides I think there should be an easier, better way to do it.

there is an article that explains how this was possible a long time ago (1997) using Direct3D retained mode function CreateWarp
The article is: "Texture Wrapping Simplified" at

http://msdn.microsoft.com/archive/en-us/dnardir3d/html/msdn_wrapfun.asp

Check under the Texture origin (ou, ov) parameter.




[edited by - Kronuz on May 26, 2003 2:19:04 PM]
"Fools rush in where fools have been before" - Unknown
"If you haven''t read, don''t bother asking." -Me

So go read an article/tutorial about texturemapping/texturecoordinates and I''m sure you know how to find one.

.lick
Pipo DeClown, I have been reading all I can about this matter, I wouldn't be asking if I hadn't. Do you really think everybody is that idiot to ask something before researching a little? I could bet you didn't even "read" the question, since for what I've seen and read, there is no simple way found on "tutorials" explaining how to accomplish this kind of tiling.

[edited by - Kronuz on May 26, 2003 2:41:16 PM]
"Fools rush in where fools have been before" - Unknown
I think I understand what you mean. The wrap addressing mode is the normal way for this sort of thing. However you want to tile just a part of a texture within the same primitive if I understand correctly? - Sorry don''t know if it is possible to do that. Would be interesting to know though.
quote:Original post by Kronuz
Pipo DeClown, I have been reading all I can about this matter, I wouldn''t be asking if I hadn''t. Do you really think everybody is that idiot to ask something before researching a little? I could bet you didn''t even "read" the question, since for what I''ve seen and read, there is no simple way found on "tutorials" explaining how to accomplish this kind of tiling.

[edited by - Kronuz on May 26, 2003 2:41:16 PM]


If you have really read about it, you would understand that the whole picture in UV equals 1.0 1.0. If you take both values less than 1.0 would mean its a point somewhere inside the picture.
If you have 3 vertices(triangle) and all of the UV-values are inside of the picture, you WONT get the hwole picture?
Get it? No? Read it again.

.lick
Pipo DeClown, it looks you're the one who don't get it, read the question again, and check the example I posted. I don't just want to show a part of the "picture", I want to tile (wrap) that part of the picture in a primitive.


[edited by - Kronuz on May 26, 2003 3:03:19 PM]
"Fools rush in where fools have been before" - Unknown
Hi Kronuz,

I had the same problem and I could find only one solution.
I had to use triangle list (no strip), and so it is possible to calculate the right UV coordinates for each triangle. So that means that the size of the triangle must be smaller (but sure not bigger) than the bitmap tile!!!! All the UV coordinates of the triangle must be 0<=UV<=1 !!
Calculating the right UV coordinates one part of a bitmap can be tiled. Not a beautiful solution, and perhaps can not be used in every case, but I really could not find better solution.
programmer
juhaszt, I think I get it now... the thing is to subdivide the primitive in several triangles to texture each right?

[edited by - Kronuz on May 26, 2003 8:33:22 PM]
"Fools rush in where fools have been before" - Unknown

This topic is closed to new replies.

Advertisement