Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture tiling question

Started by foofightr Jun 6, 2004 at 4:23 PM 7 replies 1k views
Original Post
foofightr
foofightr
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...
3DXD
3DXD
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.
Etnu
Etnu
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.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };
foofightr
foofightr
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?
xmd
xmd
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]
SoaringTortoise
SoaringTortoise
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)
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.