Jump to content
  • Advertisement

Archived

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

foofightr

texture tiling question

This topic is 5277 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

I''ve come to an odd situation in Direct3D. I need to tile a subset of a texture. For example, let''s say the subset is from (0.3,0.3) to (0.7, 0.7) in UV coords like this:
+-------------------+
|                   |
|                   |
|     +-------+     |
|     | tile  |     |
|     | this? |     |
|     +-------+     |
|                   |
|                   |
+-------------------+
 
Is there a SANE way of tiling a subset of a texture like this, using only 1 quad? I''m fairly sure something like this is not part of basic texture UV usage, but I also know that Direct3D implements some pretty funky rendering concepts, so you never know. I can think of two hacks: - take the subset and make it into its own texture, so it can be tiled normally from 0 to X, and cut up the rendering pass (currently using 1 texture and 1 vertexbuffer) to use multiple textures... - keep inserting adjacent quads to manually tile, like the good old days of sprites. this means a varying amount of quads as the original quad grows/shrinks...

Share this post


Link to post
Share on other sites
Advertisement
Couldn''t you use a seperate surface to copy the part you want from the one texture to a matching size surface and then just use that as your primary texture when you want to tile it.

I wish I was a better expert to help you more.

Share this post


Link to post
Share on other sites
When you say you want to tile a subset, where exactly do you want it to be repeated?


+-------------------+
| |
| |
| +-------+ |
| | tile | |
| | this? | |
| +-------+ |
| |
| |
+-------------------+

|
V

+-------------------+
| |
| |
|-----+-------+-----|
| | tile | |
| | this? | |
|-----+-------+-----|
| |
| |
+-------------------+


[/code

like that?

If you just want to extract part of the texture, you can simply copy the bits from one part to another by locking the texture within the region, copying the bits to another surface, and then unlocking.

Share this post


Link to post
Share on other sites
Typically, you find yourself wanting this when you pack a bunch of small textures into a large texture sheet, and then realize that you can''t tile anymore.

Sadly, normal PC hardware isn''t capable of doing this.

You will have to split your geometry at the "1.0" point into two verts; one with the texture coordinate 1.0, and one with the coordinate 0.0. Then you need to repeat a few pixels of each side around the actual texture tile, to account for filtering.

Another option is to write your own texture filter using point filtering and pixel shader 2.0 to sample multiple times, with a custom wrap that you determine.

Share this post


Link to post
Share on other sites
hplus0603 you hit the nail on the head. It''s for my GUI which uses one big texture, and I''d want to tile certain parts of it (to avoid the stretch/pinch look some wide/narrow components currently have. I want to keep the single texture approach, and I can''t use 2.0 pixel shaders (none of my computers even support that), so I guess I''ll do my 2nd hack of manually tiling quads even if it wastes space. Unless you have a better suggestion? Actually, I''m not sure I understand your first suggestion. Isn''t that basically the same as manually tiling quads?

Share this post


Link to post
Share on other sites
ok.... why not do this...


0,0 1,0
***************
* .3,.3 *
* **** *
* **** *
* **** *
* .6,.6*
***************
0,1 1,1

you want to tile the inner portion of your texture right?



Make a function first to display the texture you want.
the input is the screen x& y position where you want to place the quad, width and height of the large texture,
the x and y and width of the mini tex u want, and the teture...

this func calls another func that places the Quad after it calculates all the information....

then you just tile the quads.

void Texture(x_pos,ypos_,tex_width,tex_height,inner_tex,x1,inner_tex_y1,inner_tex_width,inner_tex_height,ID3Dtexture *texture);
{

float x1,y1,x2,y2;

x1=-.5+x_pos/SCREEN_WIDTH +inner_tex_x1/tex_width;
y1= .5-y_pos/SCREEN_HEIGHT+inner_tex_y1/tex_height;
x2=x1+width/tex_width;
y2=y1+height/tex_height;

Quad(x1,y1,x2,y2,texture);

}


for(a=0;a<width;a+=small texture width)
for(b=0;b<width;b+=small texture height)
{
Texture
(x1,x2,Texture_Width,Texture_Height,Inner_Tex_x,Inner_tex_y,Inner_tex_width,_inner_tex_height,texture);
}




then ofcourse for more specific tiling you could add a varible to account for a non full tile and have precise tilling...




ALL THAT!!! OR!


Copy the mini texture to a seperate texture and tile away!


AIM: xmd174
-x m d

[edited by - xmd on June 7, 2004 10:39:17 AM]

[edited by - xmd on June 7, 2004 10:40:10 AM]

Share this post


Link to post
Share on other sites
I''ve been struggling with the same thing. My terrain uses a tile-set texture, allowing me to do some pretty fast rendering because there are no extra settexture calls to deal with.

Except for snaffling a part of the texture out to a new surface and rendering it, there is no way to get the tiling happening. Adding extra quads to achieve the same effect is fine, but in a UI the polycount can get out of hand very quickly.

IMHO, you''re better off splitting your tiles into surfaces on-load/on-render, and work from there (it''s still a good idea to use a tileset because the management is a lot easier, but internally it''s going to be better to split them up on-load)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!