Texture Interpolation Request

Started by aZen, December 09, 2013, 02:58:58 PM

Previous topic - Next topic

aZen

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!

EgonOlsen

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.

aZen

Quote from: EgonOlsen on December 09, 2013, 03:41:32 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?

EgonOlsen

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.

aZen

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?

EgonOlsen


aZen

#6
Yes. Is that bad?

Edit: I read the documentation. Is there a way to enforce the creation of the mipmap?

EgonOlsen

Quote from: aZen 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?
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?

aZen

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):

            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(!)