Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The triangle strip you generate for the visible part of the terrain will have texture coordinates which increase from left to right. When these get very large, you will have precision issues.</p> <p>For your UV coordinates, you need to subtract the <em>same</em> value from all the coordinates in your triangle strip. Generally, take the integer part of the lowest coordinate (probably the far-left or first coordinate in your case), and subtract that from all the UVs you generate. Or use it as a baseline to generate the others, whichever you prefer.</p> <p>So if the left hand side of the screen has a U value of 100.7 and the right hand side has a U value of 129.5, you actually want to output values ranging from 0.7 to 29.5. (if you still have precision issues, you might squeak out a bit more by centring the range on zero, using negative co-ords).</p> <p>The alternative, if you need to have a discontinuity in the texture coordinates within a single strip, and to get maximum precision, is to introduce degenerate triangles, which are zero-area, and thus don't get rendered, while you change the tex-coords. You do that by repeating vertices, but with the adjusted tex-coords, before continuing.</p> <p>Based on your code above, I'd suggest something like this:</p> <pre><code>// This line should happen only once per-strip. float U_Off = floor(pt0.x / 512); // The inner loop then looks like this: for (int j=1; j&lt;hSegments+1; j++) { pt1.x = p0.x + j*dx; pt1.y = ymid + ampl * cosf(da*j); _borderVertices[_nBorderVertices++] = pt1; float xTex0 = pt0.x/512 - U_Off; float xTex1 = pt1.x/512 - U_Off; _hillVertices[_nHillVertices] = CGPointMake(pt0.x, 0); _hillTexCoords[_nHillVertices++] = CGPointMake(xTex0, 1.0); _hillVertices[_nHillVertices] = CGPointMake(pt1.x, 0); _hillTexCoords[_nHillVertices++] = CGPointMake(xTex1, 1.0); _hillVertices[_nHillVertices] = CGPointMake(pt0.x, pt0.y); _hillTexCoords[_nHillVertices++] = CGPointMake(xTex0, 0.0); _hillVertices[_nHillVertices] = CGPointMake(pt1.x, pt1.y); _hillTexCoords[_nHillVertices++] = CGPointMake(xTex1, 0.0); pt0 = pt1; } </code></pre>
 

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