Advertisement

Texture repeat question

Started by January 14, 2019 03:07 AM
15 comments, last by DividedByZero 6 years ago
1 minute ago, _Engine_ said:

You definitely missed what author wanted to achieve. 

Was beginning to think I was missing something too ?

26 minutes ago, DividedByZero said:

Correct.

Don't want to come across as rude, but for the third time, the UV co-ords are mapped around 0.75, 0.75 to 1.0, 1.0.

You can achieve similar via pixel shader. So as normal you are grabbing UV coordinates in pixel shader from vertex input then you are making some normalization and then return back to needed range:

uv = frac((vertex.uv - 0.75f) / 0.25f * 0.1f) * 0.25f + 0.75f;  

But this approach is requiring some tweaks in texture, i.e. additional pixels are needed at edges of desirable area. Otherwise there are will be noticeable artifacts when uv will be either 0.0f or 1.0f.

Advertisement

Sounds great.

I usually do add a buffer around my texture areas as it's not uncommon to get some bleed.

4 minutes ago, DividedByZero said:

Sounds great.

I usually do add a buffer around my texture areas as it's not uncommon to get some bleed.

I little bit mistaken and calculation should be like:

uv = frac((vertex.uv - 0.75f) / 0.25f * 10.0f) * 0.25f + 0.75f;  

If you use mip-maps, you'll get weird lines at the edges too, because when your uvs suddenly snap from 1 to 0.75, the GPU thinks that you must be really zoomed out (1 pixel distance on the screen = 0.25 distance in texture coordinates) so it will drop to a very low mip level automatically. 

You can fix this by using SampleGrad instead of Sample (or tex2Dgrad instead of tex2D). These require you to pass in your own uv derivatives, which you can compute before the 'frac' step, e.g.


Temp = UV*10
Gx = ddx(Temp*.25)
Gy = ddy(Temp*.25)
Uv = frac(Temp)*.25+.75
Color = SampleGrad(tex, Uv, Gx, Gy) 

 

Thanks guys! Awesome help as always.

This topic is closed to new replies.

Advertisement