Talk:GLSL Programming/Unity/Textured Spheres

Texture coordinates in the 0-1 range?
You refer to UVs being in the 0-1 range, but that seems wrong to me. I am used to being able to create UVs outside the 0-1 range, and if the "lowp" modifier is used, on iOS, tiling textures go haywire, due to the -2 to 2 range at that precision. A correction or clarification would be helpful. -Jessy- (the previous contribution was added by JessyUV at 18:22, 1 July 2011)


 * Hi JessyUV, one convention on wikibooks is to sign your comments with --~, which adds your username and a time stamp.
 * You are right, UVs outside the 0-1 range are allowed (in fact, texture wrapping modes were introduced to deal with them). But in the end, any texture coordinate outside of the 0-1 range is mapped to a coordinate in the 0-1 range and then the color is fetched from the texture image at a position with coordinates in the 0-1 range. I'll try to clarify it in the text. Thanks. --Martin Kraus (discuss • contribs) 20:38, 1 July 2011 (UTC)


 * I'm sorry if this is outside the scope of the article, but as someone who started writing shaders after a few years of 3D modeling, I still don't get how that works, and the confusion throws me off when reading. A technique that I've used, in order to use tiling along with texture atlases, is to weave edges back and forth over themselves, in order to not go outside of a given boundary in 0-1 2D space.  So the delta of UV coordinates for an edge will keep changing signs.  It seems to me, that if "tiling" UVs were remapped 0-1, there would need to be information stored about that delta, so the texture would not be wrapped in the wrong direction, as with every other edge in that "weaving" approach.  Is there some OpenGL spec page you can link to that would provide clarity?  --JessyUV (discuss • contribs) 19:20, 9 July 2011 (UTC)


 * I'm afraid I don't understand your weaving technique. You might also have used the mirrored repeat mode (which isn't available in Unity as far as I know)? Maybe I need to clarify that the UV texture coordinates at the vertices can be outside of the interval 0 to 1. Even the coordinates given to the "texture2D" instruction can be outside of the interval 0 to 1. The mapping to the interval 0 to 1 is only performed internally by "texture2D" according to the wrap mode (repeat or clamp in Unity). Hmmm. Here is an description from opengl.org of this mapping: "edge value sampling". And here the somewhat more detailed explanation in the OpenGL Programming Guide: here (search for the section Repeating and Clamping Textures ). Does this help? --Martin Kraus (discuss • contribs) 01:14, 10 July 2011 (UTC)


 * This is all making sense, now. Clarifying that clamping happens in the fragment shader, and not the vertex shader, or prior, is what I believe is necessary to understand.  Thanks! --JessyUV (discuss • contribs)


 * OK, I've tried to clarify it. Note that OpenGL and OpenGL ES 2.0 allow for vertex programs that provide access to texture images. However, this is an optional feature in OpenGL ES 2.0 and I'm not aware of any mobile GPU that implements it. --Martin Kraus (discuss • contribs) 11:15, 10 July 2011 (UTC)