Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Working with UV coordinates when they are not in the range of 0 -1

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109

    Working with UV coordinates when they are not in the range of 0 -1

    Hello,

    I am using a loading library which supplies UV coordinates as shown below.

    Note that these coordinates are not in the range of 0.0 - 1.0

    Therefore the textures aren't mapping properly and the end results suck.

    I tried using GLSL's clamp as shown below in the fragment shader but that doesn't work.

    How do I work with these UV coordinates?

    Thank you for your time:

    GLSL shader snippet:

    Code :
    MaterialTextureColor = texture2D(MainTextureSampler, clamp(TextureCoordinates, 0, 1));

    UV Coordinates:

    Note that this is just a textual representation, the coordinates are floats within C++/OpenGL when loaded.

    Code :
    UV Point: S: -53.0558 T: -15.3896
    UV Point: S: 5.99937 T: -15.3896
    UV Point: S: -3.84315 T: 2.00539
    UV Point: S: -3.84315 T: 2.00539
    UV Point: S: 5.99937 T: -15.3896
    UV Point: S: 5.99937 T: 2.00539
    UV Point: S: -53.0558 T: -15.3896
    UV Point: S: -3.84315 T: 2.00539
    UV Point: S: -53.0558 T: 4.29541
    UV Point: S: -3.84315 T: 4.29541
    UV Point: S: -53.0558 T: 4.29541
    UV Point: S: -3.84315 T: 2.00539
    UV Point: S: -3.84315 T: -2.00539
    UV Point: S: -53.0558 T: -4.29541
    UV Point: S: -3.84315 T: -4.29541
    UV Point: S: -3.84315 T: -2.00539
    UV Point: S: 5.99937 T: 15.3896
    UV Point: S: -53.0558 T: 15.3896
    UV Point: S: 5.99937 T: 15.3896
    UV Point: S: -3.84315 T: -2.00539
    UV Point: S: 5.99937 T: -2.00539
    UV Point: S: -3.84315 T: -2.00539
    UV Point: S: -53.0558 T: 15.3896
    UV Point: S: -53.0558 T: -4.29541
    UV Point: S: -2.00539 T: -0.492126
    UV Point: S: 15.3896 T: -0.492126
    UV Point: S: 15.3896 T: 3.75462e^-009
    UV Point: S: 15.3896 T: 3.75462e^-009
    UV Point: S: -2.00539 T: 3.75462e^-009
    UV Point: S: -2.00539 T: -0.492126
    UV Point: S: -3.84315 T: -0.492126
    UV Point: S: 5.99937 T: -0.492126
    UV Point: S: 5.99937 T: 3.75462e^-009
    UV Point: S: 5.99937 T: 3.75462e^-009
    UV Point: S: -3.84315 T: 3.75462e^-009
    UV Point: S: -3.84315 T: -0.492126
    UV Point: S: -4.29541 T: -0.492126
    UV Point: S: -2.00539 T: -0.492126
    UV Point: S: -2.00539 T: 3.75462e^-009
    UV Point: S: -2.00539 T: 3.75462e^-009
    UV Point: S: -4.29541 T: 3.75462e^-009
    UV Point: S: -4.29541 T: -0.492126
    UV Point: S: -53.0557 T: -0.492126
    UV Point: S: -3.84315 T: -0.492126
    UV Point: S: -53.0557 T: 3.75462e^-009
    UV Point: S: -3.84315 T: 3.75462e^-009
    UV Point: S: -53.0557 T: 3.75462e^-009
    UV Point: S: -3.84315 T: -0.492126
    UV Point: S: -15.3896 T: -0.492126
    UV Point: S: 4.29541 T: -0.492126
    UV Point: S: 4.29541 T: 3.75462e^-009
    UV Point: S: 4.29541 T: 3.75462e^-009
    UV Point: S: -15.3896 T: 3.75462e^-009
    UV Point: S: -15.3896 T: -0.492126
    UV Point: S: 5.99937 T: 0.492126
    UV Point: S: -53.0558 T: 0.492126
    UV Point: S: -53.0558 T: -3.75462e^-009
    UV Point: S: -53.0558 T: -3.75462e^-009
    UV Point: S: 5.99937 T: -3.75462e^-009
    UV Point: S: 5.99937 T: 0.492126

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161
    Without understanding why your UV coordinates are outside of the 0..1 range, you could try one of the different texture sampling parameters, eg GL_REPEAT
    glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    Quote Originally Posted by BionicBytes View Post
    Without understanding why your UV coordinates are outside of the 0..1 range, you could try one of the different texture sampling parameters, eg GL_REPEAT
    glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    I tried the different parameters for glTexParameter as specified here but I get the same results.

    Thank you for the suggestion...

  4. #4
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    If you get the same results something is going very wrong and to me it sounds as if your glTexParameter where not actually operating on the correct texture. If you were getting different results, but none of those are what you want, you'd need to explain what mapping you expect and ideally find out what units the existing UV coords are in (maybe texels?).

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    Quote Originally Posted by carsten neumann View Post
    If you get the same results something is going very wrong and to me it sounds as if your glTexParameter where not actually operating on the correct texture. If you were getting different results, but none of those are what you want, you'd need to explain what mapping you expect and ideally find out what units the existing UV coords are in (maybe texels?).
    The problem definitely seems to be the UV coordinates; what I did was this.

    I set the texture coordinates to be the actual color of red and green in the GLSL fragment shader as so:

    Code :
            if (TextureCoordinateDebug == 1) {
    		if (Clamping == 1) {
    			finalColor = vec4(clamp(TextureCoordinates, 0, 1), 0.0, 1.0);
    		} else {
    			finalColor = vec4(TextureCoordinates, 0.0, 1.0);
    		}
    	}

    Both "TextureCoordinateDebug" and "Clamping" are uniforms I change via a key event.

    Regardless of whether clamping is done or not I get the following image:

    If UVs were working OK I should get a smooth gradient from red to green on all of the surfaces.

    Anyone have any ideas? I contacted the Autodesk FBX forums as well.

    Thank you.


  6. #6
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    Fragment shader outputs that are written to the default framebuffers are always clamped to [0,1]. Your 'Clamping' uniform won't have an effect.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    Quote Originally Posted by carsten neumann View Post
    Fragment shader outputs that are written to the default framebuffers are always clamped to [0,1]. Your 'Clamping' uniform won't have an effect.
    I see, that makes sense.

    So how do I get around this problem?

    I asked around on the AutoDESK FBX forums and the response was that the function above I used to retrieve the texture coordinates is the correct function.

    Here is how my textures come out currently:


  8. #8
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    Hmm, can you trim your model down to just a single surface that has the problem? That way it may be possible to determine what is wrong from looking at the numbers. Otherwise you just have a large pile of triangles and it is very difficult to manually correlate numbers with what happens on screen.

  9. #9
    Senior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    Quote Originally Posted by carsten neumann View Post
    Hmm, can you trim your model down to just a single surface that has the problem? That way it may be possible to determine what is wrong from looking at the numbers. Otherwise you just have a large pile of triangles and it is very difficult to manually correlate numbers with what happens on screen.
    You got it.

    Here is a very simple model's coordinates for vertices, normals, and UV's:

    Code :
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.998895 T: 0.992545
    Vertex:  X: 1 Y: 1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.0232662 T: 0.0169165
    Vertex:  X: 1 Y: -1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.998895 T: 0.0169165
    Vertex:  X: 1 Y: 1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.0232662 T: 0.0169165
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.998895 T: 0.992545
    Vertex:  X: -1 Y: 1 Z: -1 Normal:  X: 0 Y: 0 Z: -1 UV Point:  S: 0.023266 T: 0.992545
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 0.333333 T: 0.666667
    Vertex:  X: 0.999999 Y: -1 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 0 T: 0.333333
    Vertex:  X: 1 Y: 0.999999 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 0.333333 T: 0.333333
    Vertex:  X: 0.999999 Y: -1 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 0 T: 0.333333
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 0.333333 T: 0.666667
    Vertex:  X: -1 Y: -1 Z: 1 Normal:  X: 2.98023e-008 Y: 0 Z: 1 UV Point:  S: 4.96705e-008 T: 0.666667
    Vertex:  X: 1 Y: 0.999999 Z: 1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.333333 T: 0.333333
    Vertex:  X: 1 Y: -1 Z: -1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.666667 T: 1.98682e-008
    Vertex:  X: 1 Y: 1 Z: -1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.666667 T: 0.333333
    Vertex:  X: 1 Y: -1 Z: -1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.666667 T: 1.98682e-008
    Vertex:  X: 1 Y: 0.999999 Z: 1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.333333 T: 0.333333
    Vertex:  X: 0.999999 Y: -1 Z: 1 Normal:  X: 1 Y: -2.98023e-007 Z: 4.47034e-008 UV Point:  S: 0.333333 T: 0
    Vertex:  X: 0.999999 Y: -1 Z: 1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 0 T: 1.29143e-007
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 0.333333 T: 0.333333
    Vertex:  X: 1 Y: -1 Z: -1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 2.98023e-008 T: 0.333333
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 0.333333 T: 0.333333
    Vertex:  X: 0.999999 Y: -1 Z: 1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 0 T: 1.29143e-007
    Vertex:  X: -1 Y: -1 Z: 1 Normal:  X: -2.83122e-007 Y: -1 Z: -1.78814e-007 UV Point:  S: 0.333333 T: 0
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 0.666667 T: 8.9407e-008
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 1 T: 0.333333
    Vertex:  X: -1 Y: -1 Z: 1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 0.666667 T: 0.333333
    Vertex:  X: -1 Y: -1 Z: -1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 1 T: 0.333333
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 0.666667 T: 8.9407e-008
    Vertex:  X: -1 Y: 1 Z: -1 Normal:  X: -1 Y: 2.38419e-007 Z: -1.3411e-007 UV Point:  S: 1 T: 0
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.333333 T: 0.666667
    Vertex:  X: 1 Y: 1 Z: -1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.666667 T: 0.333333
    Vertex:  X: -1 Y: 1 Z: -1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.666667 T: 0.666667
    Vertex:  X: 1 Y: 1 Z: -1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.666667 T: 0.333333
    Vertex:  X: -1 Y: 1 Z: 1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.333333 T: 0.666667
    Vertex:  X: 1 Y: 0.999999 Z: 1 Normal:  X: 2.38419e-007 Y: 1 Z: 1.63913e-007 UV Point:  S: 0.333333 T: 0.333333

    The MVP Matrix for this model:

    Code :
    x: 1,000.0 y: 0.0, z: 0.0, w: 0.0
     
    x: 1,000.0 y: -0.00162920682 , z: -1000.0, w: 0.0
     
    x: 0.0 y: 200.0, z: -3.25841356e-005, w: 0.0
     
    x: 0.0 y: 0.0, z: 0.0, w: 1.0

    The wireframe of the model:



    The texture:



    The resultant final image with texture:


  10. #10
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    6
    Did you consider the exporter you use is faulty here?
    This problem obviously doesn't relate to OpenGL, but to bad UVs (to me it seems as reordering vertices without reordering the UVs along and a scaling issue 0-1 vs 0-pixel dimension). However we don't really know what exporter you use, other than it seems to export in FBX format ("Anyone have any ideas? I contacted the Autodesk FBX forums as well." is the only information I can gather from this thread).

Page 1 of 3 123 LastLast

Similar Threads

  1. Texture Coordinates and Depth Buffer to obtain world coordinates
    By snkhan42 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 04-27-2018, 11:52 AM
  2. Replies: 4
    Last Post: 06-08-2016, 07:01 PM
  3. Replies: 0
    Last Post: 07-25-2013, 03:46 PM
  4. Replies: 2
    Last Post: 06-02-2012, 08:10 AM
  5. textures coordinates out of range [0-1]
    By queeroux in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-19-2004, 10:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean