Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I understand you want to tile only a subset of the texture, right? Then things get complicated.</p> <p>Assume we want to tile u-coord between u1 and u2 values, u1 &lt; u2.</p> <p>Then we need a function f(u), so that</p> <pre><code>f(0.0) = u1 f(0.5) = (u1+u2)/2 f(0.9999) = u2 f(1.0) = u1 f(1.5) = (u1+u2)/2 f(1.9999) = u2 f(2.0) = u1 and so on... </code></pre> <p>An appropriate function is <code>f(u) = frac(u) * (u2-u1) + u1</code></p> <p>The same goes for v-coord, <code>f(v) = frac(v) * (v2-v1) + v1</code></p> <p>Notice that it's tiling without mirroring. If you need mirroring, then the function should be a triangular-wave function, which is <code>t(x) = arcsin(sin(pi*(x-0.5)))/pi+0.5</code> and <code>f(u) = t(u) * (u2-u1) + u1</code>. Using trigonometric functions can be expensive though.</p> <p>I don't know if it's possible with fixed pipeline, but you can do it easily in pixel shader (HLSL code):</p> <pre><code>// float2 tex_coord -&gt; (u,v) from vertex shader, in [0,n] range, // n - number of repetitions // float2 tex1, tex2 -&gt; constants, subrange of [0,1] coords that will be tiled // no mirroring float4 color = tex2D(sampler, frac(tex_coord) * (tex2-tex1) + tex1); </code></pre> <p>or</p> <pre><code>// mirroring, t(x) = arcsin(sin(pi*(x-0.5)))/pi+0.5 float4 color = tex2D(sampler, t(tex_coord) * (tex2-tex1) + tex1); </code></pre> <p>EDIT: a better way to compute triangular-wave function: <code>t1(x) = abs(2(0.5x-floor(0.5x+0.5)))</code> or <code>t2(x) = abs(2(frac(0.5x+0.5))-1)</code> (not exactly the same as t1 but correct for non-negative numbers).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload