Skip to main content
gamedev.net
🔒 Locked

Texture repeating

Started by Valor Knight Jan 29, 2006 at 4:36 PM 8 replies 1k views
Original Post
Valor Knight
Valor Knight
Here is my problem: I need to repeat a texture across a mesh an arbitray amount of times. Currently I am doing this, my UV coorinates start from 0 on the top lefthand side, and strech to the other side with a uv higher than 1 so it repeats. It looks great with the entire texture, but now I need to find how to repeat a portion of the texture only. My question: Is there a way to only repeat the uv of 0 to 0.5 from the texture, but have it use the vertex uv of 0 to greater than 1? I only would like to repeat the top corner of the texture. I also need to do this in a .fx file so it can be in the vertex or pixel shader. I have tried a few methods of my own, but they do not work correctly (gaps, uv's are screwy, ect..) Many thanks.
There is no life without honor
Riviera Kid
Riviera Kid
cant you just use a different texture?
if you cant (for whatever reason)

in the pixel shader, remove the integer part of the tex coord (it you have to) and divide by 2?
--------------------------------Dr Cox: "People are tard coated tards with ***tard filling."
Namethatnobodyelsetook
Namethatnobodyelsetook
nVidia's texture atlas demo (I think it was there... maybe it's in one of the DXSDK samples) attempts to do fancy pixel shader tricks to repeat sub textures, but there are small filtering artifacts at the edge of every repeat. If you can live with error, and can use PS2.0, then that is an option. For ps1.1 or fixed pipeline you'll need to repeat geometry to repeat the subtexture.
Valor Knight
Valor Knight
Shoot, well when I did it my own way, I was getting small filtering artifacts. So I guess I will not try that now.
There is no life without honor
DXnut
DXnut
Can you not just put the faces you want to texture differently into another subset of the mesh? An alternative would be to duplicate the vertices that are between the two sections you want to texture differently.
--------------------------Most of what I know came from Frank D. Luna's DirectX books
pcwlai
pcwlai
Currently, there is no standard method is repeating the textures with pure hardwrae sampling, in fixed function or programmable pipelines.
The poorest programmer in the game industry!!
Valor Knight
Valor Knight
It is not a mesh per se, it is vertex/index buffered so It is not storing anything else. I Almost had it, but I was getting a line and if I deviated from my values, I would get a mirror image on top of the current uv. This was done in the vertex shader, So I will try a bit more, otherwise I will not worry about it. (Though it seems like this would be used more often if it was supported)
There is no life without honor
sirob
sirob
In a PS2 Pixel Shader, in HLSL you can use the floor() function to do what you want:

float NewCoords = (OldCoords - floor(OldCoords)) * 2.0f;NewCoords = (NewCoords - floor(NewCoords)) * 0.5f;


What you're doing is first getting only the fraction part of the coords. This gives you a [0,1] range. Then, when you multiply by 2, you get a [0,2] range. After that, you reduce yourself to the fraction, returning to a [0,1] range. Finally, you multiply by 0.5f to get the desired [0,0.5f] range.

This should be pixel perfect, but painfully slow (I havn't tested it, actually). Also, like I said, requires PS2.0.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
Riviera Kid
Riviera Kid
float NewCoords = (OldCoords - floor(OldCoords)) * 2.0f;
NewCoords = (NewCoords - floor(NewCoords)) * 0.5f;

lets imagine OldCoords = 0.5 (we want 0.25)

(0.5 - 0) * 2 = 1

( 1 - 1 ) * 0.5 = 0

am i missing something? that looks wrong

afaic

float NewCoords = (OldCoords - floor(OldCoords)) * 0.5;
is the correct answer.

am i going mad?
--------------------------------Dr Cox: "People are tard coated tards with ***tard filling."
Valor Knight
Valor Knight
Quote:
Original post by sirob
In a PS2 Pixel Shader, in HLSL you can use the floor() function to do what you want:

*** Source Snippet Removed ***

What you're doing is first getting only the fraction part of the coords. This gives you a [0,1] range. Then, when you multiply by 2, you get a [0,2] range. After that, you reduce yourself to the fraction, returning to a [0,1] range. Finally, you multiply by 0.5f to get the desired [0,0.5f] range.

This should be pixel perfect, but painfully slow (I havn't tested it, actually). Also, like I said, requires PS2.0.

Hope this helps.


frac(OldCoords) does the same thing as (OldCoords - floor(OldCoords))

No, it does not work in the pixel shader
 float2 testuv = frac(uvTiled) * 2.0f;     testuv = frac(testuv) * 0.5f;

There is nasty pixel "gaps" in between the repeating texture.
There is no life without honor

Topic Locked

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

Sign in to reply to this topic.