Note that there are some explanatory texts on larger screens.

plurals
  1. POBuggy UV coordinates of sphere in OpenGL?
    primarykey
    data
    text
    <p>I am having buggy texture map on my sphere. The issue is well known but solution is rare.</p> <p>This is my code for generating UVs for a sphere.</p> <p>T = trinagles, Nv = vertex normals.</p> <pre><code>for (int i=0; i&lt;nbF; i++) { float tx1 = atan2(Nv[T[i].v1].x, Nv[T[i].v1].z) / (2.0f*M_PI) + 0.5f; float ty1 = asinf(Nv[T[i].v1].y) / M_PI + 0.5f; float tx2 = atan2(Nv[T[i].v2].x, Nv[T[i].v2].z) / (2.0f*M_PI) + 0.5f; float ty2 = asinf(Nv[T[i].v2].y) / M_PI + 0.5f; float tx3 = atan2(Nv[T[i].v3].x, Nv[T[i].v3].z) / (2.0f*M_PI) + 0.5f; float ty3 = asinf(Nv[T[i].v3].y) / M_PI + 0.5f; float n = 0.75f; if(tx2 &lt; n &amp;&amp; tx1 &gt; n) tx2 += 1.0; else if(tx2 &gt; n &amp;&amp; tx1 &lt; n) tx2 -= 1.0; if(tx3 &lt; n &amp;&amp; tx2 &gt; n) tx3 += 1.0; else if(tx3 &gt; n &amp;&amp; tx2 &lt; n) tx3 -= 1.0; out_UV[T[i].v1].u = tx1; out_UV[T[i].v1].v = ty1; out_UV[T[i].v2].u = tx2; out_UV[T[i].v2].v = ty2; out_UV[T[i].v3].u = tx3; out_UV[T[i].v3].v = ty3; } </code></pre> <p>Output: <a href="http://i.stack.imgur.com/luhgZ.jpg" rel="nofollow">http://i.stack.imgur.com/luhgZ.jpg</a> ![enter image description here][1]</p> <p>As you can see in the figure, my code is generating long strip at one side of the sphere. The solution is here .. <a href="http://sol.gfxile.net/sphere/index.html" rel="nofollow">http://sol.gfxile.net/sphere/index.html</a> but couldn't figure it out.. How can I solve this issue ? any suggestion?</p> <pre><code># Update 1:# </code></pre> <p>This code also doesn't work for me.. I don't know what wrong in it. still the same ugly seam I am getting. ???</p> <pre><code>for (int i=0; i&lt;nbV; i++) { out_UV[i].u = (float) atan2(Nv[i].x, Nv[i].z) / (2.0f*M_PI) + 0.5f; out_UV[i].v = (float) (asin(Nv[i].y) / M_PI) + 0.5f; } float nx = 0.9f; float nv = 0.8f; for (int i=0; i&lt;nbV-2; i++) { if (out_UV[i].u - out_UV[i+1].u &gt; nx) out_UV[i+1].u += 1.0f; if (out_UV[i+1].u - out_UV[i].u &gt; nx) out_UV[i].u += 1.0f; if (out_UV[i].u - out_UV[i+2].u &gt; nx) out_UV[i+2].u += 1.0f; if (out_UV[i+2].u - out_UV[i].u &gt; nx) out_UV[i].u += 1.0f; if (out_UV[i+1].u - out_UV[i+2].u &gt; nx) out_UV[i+2].u += 1.0f; if (out_UV[i+2].u - out_UV[i+1].u &gt; nx) out_UV[i+1].u += 1.0f; if (out_UV[i].v - out_UV[i+1].v &gt; nv) out_UV[i+1].v += 1.0f; if (out_UV[i+1].v - out_UV[i].v &gt; nv) out_UV[i].v += 1.0f; if (out_UV[i].v - out_UV[i+2].v &gt; nv) out_UV[i+2].v += 1.0f; if (out_UV[i+2].v - out_UV[i].v &gt; nv) out_UV[i].v += 1.0f; if (out_UV[i+1].v - out_UV[i+2].v &gt; nv) out_UV[i+2].v += 1.0f; if (out_UV[i+2].v - out_UV[i+1].v &gt; nv) out_UV[i+1].v += 1.0f; } </code></pre>
    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.
 

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