🔒 Locked
Texture repeating
Advertisement
Original Post
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.
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?
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?
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.
Shoot, well when I did it my own way, I was getting small filtering artifacts. So I guess I will not try that now.
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)
In a PS2 Pixel Shader, in HLSL you can use the floor() function to do what you want:
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.
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.
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?
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?
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement