27th October 2008, 12:39 PM | #1 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Texture clamping and repeating
I'm looking for clarification and/or correction on the clamping of texture and the texrep parameter. In essence, what should the clamping mode be when no texrep parameter is specified? That is, should an image start wrapping around the other side even if the texture coordinates are 1.0?
My question stems from switching from custom OpenGL code to render AC3D models to OpenSceneGraph. Our custom code would set the OpenGL clamping mode to not repeat (CLAMP_TO_EDGE I think) unless there was a texrep line. Well, OSG behaved differently and I'm not sure which one is considered "correct." In this thread on the osg-users list: http://www.mail-archive.com/osg-user.../msg17192.html I have attached an example model (may not have show up on the archives yet). If our custom code behavior is not considered correct, what is the correct way to change the AC3D model? |
27th October 2008, 02:40 PM | #2 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Re: Texture clamping and repeating
Here are some screenshots since it appears my message may not have made it into the osg-users mailing list archive.
One screenshot is of the model in AC3D where you can see the repeating a little bit (the one with the grey background). One is of the model rendered in OSG without any clamping (you can see the African desert in the Atlantic and vice versa). The remaining screenshot is of the behavior I am looking for (i.e., texture clamped to edge). Last edited by jcummings; 27th October 2008 at 02:49 PM. |
27th October 2008, 05:15 PM | #3 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,565
|
Re: Texture clamping and repeating
Can you point out the specific differences - I'm finding it hard to tell.
|
27th October 2008, 05:27 PM | #4 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Re: Texture clamping and repeating
No problem. If you will notice, the one called "old_behavior.jpg" (which is the one on the bottom) and the one called "ac3d_behavior.jpg" (which is the one in the middle with the grey background) both have a blue line running through the middle of Africa and a sand-colored line running through the Atlantic Ocean.
The image called "desired_behavior.jpg" (which is the first image) does not have these extra lines. It uses the GL setting GL_CLAMP_TO_EDGE to avoid those lines. Does that help or should I post other images? |
27th October 2008, 05:37 PM | #5 |
Senior Member
Professional user
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
|
Re: Texture clamping and repeating
I think I understand where jcummings is going with this.
jcummings - from purely a graphics programmer perspective, "clamp" would be the correct answer for non-repeating\non-tiling textures. This assumes, however, that you have a rule for your art team that uvs cannot go outside the [0-1], which isn't always the case. However, I think AC3D has the correct behavior with "wrap" because of the specific use-case. AC3D allows uvs outside [0-1], which it needs to as many formats it imports also allows uvs outside [0-1]. When most artists create texture coordinates outside the [0-1] range, they are assuming it will tile. This is really the only reason an artist would do this, and many people use this "trick" especially with editors that don't support explicit repeat modes. If you wanted to be really sexy about it on your importer, I would take the min and max of the uv coordinates. If the uvs are within the 0-1 range and repeat mode is disabled, set your addressing mode to "clamp" to minimize seams. If any uvs are outside the 0-1 range, then set your addressing mode to "wrap" and assume it was intentional. This should give you the best of both worlds. |
27th October 2008, 05:52 PM | #6 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Re: Texture clamping and repeating
lisa- yes, you understand where I am headed with this thread.
I do like the idea of simply testing the UV range. I have done a half-hearted version of this by turning on wrap (GL_REPEAT in my case) when there was a "texrep" line and clamping (GL_CLAMP_TO_EDGE) if it was not present. Clearly I didn't encountered models with larger UV ranges- but it happened to work for my situation. It sounds like testing the range may be all I need to do? In other words, is testing the UV ranges the best approach or is there another feature that I'm missing in AC3D? Is it simply that the .ac file format doesn't have a formal definition for clamping and it is up to user to figure out the "best" thing to do? |
27th October 2008, 06:03 PM | #7 |
Senior Member
Professional user
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
|
Re: Texture clamping and repeating
Andy can answer that better than I can, but AFAIK there's no formal setting for "clamp" in AC3D.
Testing the range should do the trick though. I'm hard-pressed to think of a common use-case that would be otherwise. |
3rd November 2008, 10:35 AM | #8 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Re: Texture clamping and repeating
Andy, is there a way to explicitly set the clamp mode or is it ambiguous?
|
3rd November 2008, 02:56 PM | #9 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,565
|
Re: Texture clamping and repeating
It's fixed to repeat at the moment.
|
3rd November 2008, 03:07 PM | #10 |
Junior Member
Junior member
Join Date: Jun 2007
Posts: 7
|
Re: Texture clamping and repeating
|
Tags |
clamping, texture, texture clamping, texture repeat |
|
|