Author Topic: Texture Interpolation Request  (Read 1190 times)

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Texture Interpolation Request
« on: December 09, 2013, 02:58:58 pm »
So when you use a texture and the uv position is right on the edge (when at least one position is zero or one), the outside of the texture is interpolated with black. That results in black pixels "on the edge" which looks awful. I was wondering if you could make an option so that the border color of the texture is used for interpolation (instead of black). E.g. the arbitrary point (-5,-7) would be interpolated with (0,0) of the texture and so on.

I'm not sure if this would be easy for you to implement, but it seems like something that should be done "on your side". Alternative I could "frame" the textures before adding them.

Please let me know!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Texture Interpolation Request
« Reply #1 on: December 09, 2013, 03:41:32 pm »
I'm not sure what you mean, because there is no interpolation with black happening. Just like with bilinear filtering, the interpolation happens with adjacent pixels which, in case of 0 or 1 means that it flips to the pixel at the other side (1 or 0). If that one is black, then you'll get the result you are describing. Another "problem" might occur when using an ITextureEffect. Note that the array is a little bit larger than the actual texture. If that causes the problem, just fill the last row with the former one and you should be fine.

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Texture Interpolation Request
« Reply #2 on: December 09, 2013, 06:45:47 pm »
Another "problem" might occur when using an ITextureEffect. Note that the array is a little bit larger than the actual texture. If that causes the problem, just fill the last row with the former one and you should be fine.

That worked! There was no black pixel in the image that I was loading and I couldn't for the live of it not figure out what was going on. Thank you very much!

Now I'm curious. Why is the array a bit bigger?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Texture Interpolation Request
« Reply #3 on: December 09, 2013, 08:07:39 pm »
To compensate for rounding errors in the software renderer. The alternative would have been to add an additional conditional jump per pixel, which i wanted to avoid.

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Texture Interpolation Request
« Reply #4 on: December 09, 2013, 09:54:21 pm »
A bit off topic, but I didn't feel like opening yet another thread (it's related at least):

I read somewhere that there might be hitching with opengl when a texture is shown for the first time. However I'm experiencing that with the software renderer: When the triangles that display a new texture are rotated into view (i.e. they are no longer culled), there is a small hitch.

How would I go about improving on that?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Texture Interpolation Request
« Reply #5 on: December 09, 2013, 10:58:10 pm »
Are you using mip mapping?

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Texture Interpolation Request
« Reply #6 on: December 09, 2013, 11:49:04 pm »
Yes. Is that bad?

Edit: I read the documentation. Is there a way to enforce the creation of the mipmap?
« Last Edit: December 10, 2013, 12:54:47 am by aZen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Texture Interpolation Request
« Reply #7 on: December 10, 2013, 08:11:30 am »
Yes. Is that bad?

Edit: I read the documentation. Is there a way to enforce the creation of the mipmap?
No, it's actually a good thing to use mip maps. Currently, there's no way to enforce it. You should get a log message about the time that it takes to create the mip maps for a texture. How are these times in your case?

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Texture Interpolation Request
« Reply #8 on: December 10, 2013, 09:40:12 pm »
The loading times by themselves are not the problem. I think the issue is that all mipmaps are created in the same frame, when the plane (with many textures) is rotated into view. Will test and report back.

For reference, this is what fixed the initial problem for me (used in the ITextureEffect apply function):
Code: [Select]
            int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
            System.arraycopy(pixels, 0, dest, 0, pixels.length);
            int diff = dest.length - pixels.length;
            System.arraycopy(pixels, pixels.length - diff, dest, pixels.length, diff);
Note: You need to be careful that the data buffer of the BufferedImage "img" is actually an int[] array(!)