Archived

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

Kronuz

Multiple tiles in one texture.

Recommended Posts

Kronuz    122
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?

Share this post


Link to post
Share on other sites
Cuculain    122
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)

Share this post


Link to post
Share on other sites
Kronuz    122
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]

Share this post


Link to post
Share on other sites
Kronuz    122
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]

Share this post


Link to post
Share on other sites
Cuculain    122
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.

Share this post


Link to post
Share on other sites
Pipo DeClown    804
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

Share this post


Link to post
Share on other sites
Kronuz    122
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]

Share this post


Link to post
Share on other sites
juhaszt    122
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.

Share this post


Link to post
Share on other sites
Kronuz    122
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]

Share this post


Link to post
Share on other sites
But, Pipo, that defeats the whole purpose of using a tileset texture. I don''t think this can be done myself... except by the ubiquitous statement, "use a custom pixel shader." There doesn''t seem to be a way to instruct the default shader to wrap when the UV exceeds a value less than 1 so... Other than adding additional geometry... nope.

Seems these days that if you want anything done, that''s the right answer. Want to have 2,000,000 particles rendering with depth-independent alpha-blending? "Use a custom pixel shader."

Share this post


Link to post
Share on other sites
Tessellator    1394
Yeah, I dont think this can be done because the addressing mode doesn''t exist (although it does on some hardware platforms, just not the PC).

Im having trouble trying to think you could do this in a nice way with pixel shaders, and to be honest, I think that would horribly over-kill for a 2d tile-based set up (unless you''re already using them for some kind of effects).

Best bet would probably just duplicate the vertices so that the tiling is actually explicit in the vertex data.

BTW, I always think its funny when someone tries being cocky and ends up looking the cock, Pipo DeClown.

T

Share this post


Link to post
Share on other sites
Drilian    1067
The best I can come up with is to use one quad for each repetition of the texture. Or use a pixel shader. hehe.

Unfortunately, there''s just no way to tell DX to wrap at 0.2 or 0.5 instead of 1.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
i''m having trouble understanding why a texture transform wouldn''t work here. have you tried it yet?

the idea would be to run the vert UVs, after they''ve been "wrapped," through the transform, which would translate and scale to the piece of the texture you wanted to use.

i guess it depends on when the texture address mode is applied, before or after the transform?

Share this post


Link to post
Share on other sites
VladR    722
What if you just created new texture from that u,v coordinate range that you need ? If it is just few textures than it`s OK to create few new textures. But if you put into big texture many smaller textures (as an optimization point), then it`s of no use of course.

While texture transform might work (haven`t looked at it yet much), the easiest way still may be in dividng the surface into many smaller triangles.

VladR
Avenger game

Share this post


Link to post
Share on other sites
quote:
i guess it depends on when the texture address mode is applied, before or after the transform?


It''s after. Texture transform is performed per-vertex before rasterization. Texture addressing is per-pixel.

Share this post


Link to post
Share on other sites
juhaszt    122
when rendering a triangle and you have only the following information: u1=0.3 (left corner) u2=0.4 (right corner) how can you decide how many tiles should be applied on that triangle????

texture transform will not help here, you can not get the missing information with any transform!!

Share this post


Link to post
Share on other sites
Kronuz    122
Thanks guys, after trying texture transformations, pixel shaders, polygon subdivision... Finally I found that the only acceptable way to tile a part of a texture in a primitive is exactly what juhaszt suggested. To subdivide the primitive into a list of triangles, giving each triangle in the list its proper part of the texture.

I found that it''s also possible to use a pixel shader, and Tride even wrote an example for me (thanks Tride, http://www-imagis.imag.fr/Membres/Sylvain.Lefebvre/repeat). But since it needs very new hardware work, it''s an unacceptable solution.

Also, texture transformations will definetily not work with this, since texture transformations are done before coordinate wrapping.

Thanks for your help.

Share this post


Link to post
Share on other sites