tex-filtering, esp with tiles and the 62x62 hack

Discuss the future of Warzone 2100 with us.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

seeking to determine the exact behavior, i've made two debugging tilesets, the first of which shows tile seam rendering clearly, and the second is rotationally seamless, and can be used to test whether or not the renderer is accurate (though the first can do this also). each of these tilesets contain only one tile, duplicated identically about 90 times.

Image

before i go on, i'll reiterate on a bug that i may or may not have posted a bug report on: as seen in the above image, even when an entire tileset is fully replaced, many (if not all) maps still show the original tileset for some tiles, and the new tileset for all others... does anyone know why this occurs?

back on topic:

first tileset:

example tile:
Image

filtered
Image

unfiltered (after per's code reversion)
Image

as seen from the filtered render, the colorized border is only displayed with something like 1/5th of a texel (what should have taken 5 pixels to render on screen took only 1 or two). as some of us know, the reason for only a sliver of that border being rendered is because each tile is being rendered as a 62x62 tile, and the texture filtering algorithm makes every immediately adjacent pixel to that 62x62 square "bleed" in to the tile during rendering; the same problem exists with pie modelling, and warzone's 3d artists learned to inset each texture coordinate by one texel for filtered polygons -- some examples of unadjusted texture mapping can be seen on the default propulsion pies: in-game, a green set of half-tracks might have a magenta (or some other color) edge on most polys because of this bleed-through.

the effect is small enough that pixel padding operations may work, most preferrably those initiated and cached by the engine (as opposed to having to manually pad the original tiles). If we can agree to N-2 texture dimensions (62x62, 126x126, etc) as a standard, than it may be a good solution, however, many artists have worked on tilesets that are N-dimensioned, and one cannot maintain rotational seamlessness by cropping the tiles down, and they would lose substantial quality and most likely would end up non-rotationally seamless if scaled down by two pixels.  therefore, if we were to choose a pixel padding approach, i believe that N+2 textures are far more effective because they would retain compatibility, at the expense of either texture access speed (devurandom confirmed that non-power-of-two textures take longer for a gfx card to access) or stored texture size (padding the memcached texpage in both directions with blank pixels until the texpage is power-of-two -- good texture sorting algorithms could minimize the ill effects of this). in the next few days, if i remember, i'll make and test a 62x62 rotationally seamless tileset with a 1-pixel pad, and see how that works: if it displays as intended, than a 66x66 solution (unchanged 64x64 tiles with an engine-calculated 1-pixel pad) may be the path to least resistance for all people involved.

better yet is if we can find an gl texture clamping method that prevents bleed -- it seems likely that one exists, as this is no small issue.

the possible solution of blending tiles obviously has the compatibility/performance drawbacks, but also there's a good chance that doing so simply won't look good at all, and in many cases, such as blending water and sand, would certainly look too cartoonish and artificial.

one issue i'm also seeing: on the corners of many tiles in both screenshots, an extra brightly colored texel appears where it does not exist in the original tile. are the tiles compressed using a lossy algorithm before loading them into memory, or is this some kind of rendering/loading bug?

second tileset:

example tile:
Image

filtered
Image

unfiltered (after per's code reversion)
Image

as seen, after per's change, tiles are once again rendered correctly, though more pixelated.
Chojun
Regular
Regular
Posts: 518
Joined: 25 Nov 2006, 17:49
Contact:

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by Chojun »

Thanks, Kage.
The best thing to do when your philosophies don't stand up to debate is to lock the thread and claim victory.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

Chojun wrote: Thanks, Kage.
?
Chojun
Regular
Regular
Posts: 518
Joined: 25 Nov 2006, 17:49
Contact:

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by Chojun »

good work :)
The best thing to do when your philosophies don't stand up to debate is to lock the thread and claim victory.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

oh. by the sound of it, i had thought i had stumbled on to some heated debate that had started in my absence...
User avatar
lav_coyote25
Professional
Professional
Posts: 3434
Joined: 08 Aug 2006, 23:18

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by lav_coyote25 »

nope - excellent work... not all comments are to be taken as ... a bad thing... ;D


do you mind if the above makes it into some form of a addon to the documents project?
‎"to prepare for disaster is to invite it, to not prepare for disaster is a fools choice" -me (kim-lav_coyote25-metcalfe) - it used to be attributed to unknown - but adding the last bit , it now makes sense.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

lav_coyote25 wrote: do you mind if the above makes it into some form of a addon to the documents project?
take it, copy it, modify it: whatever is fine.

also, if anyone wants to use any of these tilesets for testing, lmk and i can provide them in 1.x, 2.x, or tile-per-file compatible formats.

also to be seen from the screenshots from the second tileset is an example of how warzone tiles can either rotate any of four ways, or flip along either axis: so rotationally seamless tiles aren't actually good enough for warzone -- they also have to be mirrorably seamless (or symmetric along the edges).
User avatar
DevUrandom
Regular
Regular
Posts: 1690
Joined: 31 Jul 2006, 23:14

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by DevUrandom »

mirrorably seamless... Sounds like fun for artists. ;)

I can just copy test0-tile.png and test1-tile.png, I assume? Create 90 copies of it, rescale it to the appropriate resolutions and have WZ load them?
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

if you've got my texpage2mipmap.py script, imagemagick, and a terminal handy, you can just copy test?-tile.png to the same dir as the texpage2mipmap.py script, run

Code: Select all

convert -size 576x640 tile:tile0-tile.png tertilesc1hw.png
convert -size 576x640 tile:tile1-tile.png tertilesc2hw.png
then run texpage2mipmap.py (either through a graphical filemanager, or in a terminal), then move "tertilesc?hw{-*,.radar}" to ~/.warzone2100/mods/global/name-of-some-mod/texpages/

then run `warzone2100 --mod name-of-some-mod`

then any alpha map (desert) will show the first tileset, and any beta map (urban) will show the second tileset.

note: all the above assumes bash. if anyone wants to try this in a dos shell, or something else, lmk, and i'll try to translate the commands
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by Per »

Kage, can I download your test tiles from somewhere to debug that not-all-tiles-replaced bug you found? Did you try this only by replacing them as a mod, or did you also try replacing the "real" tiles?
"Make a man a fire, you keep him warm for a day. Set a man on fire, you keep him warm for the rest of his life."
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

the below instructions will allow you to create the full tilesets from the individual tiles in my first post, but i do see the benefit in having an official debug-tiles mod.

thus, here it is

i'd appreciate it if someone would upload that mod to svn, or elsewhere, as i don't have enough bandwidth for everyone to download from my server and still maintain smooth multiplayer gaming (i could set up qos stuff, but i'm too lazy).
Per wrote: Did you try this only by replacing them as a mod, or did you also try replacing the "real" tiles?
only as a mod. certainly replacing the provided tiles in warzone.wz would work, but obviously it's unreasonable for tileset modders to have to do that.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

pixel padding works! screenshots below.

third tileset:

example tile:
Image

filtered
Image

unfiltered (after per's code reversion)
Image

like the second tileset, this one is rotationally and mirrorably (need a better term) seamless, but this one was originally designed as a 62x62 tile with the outermost pixel on each side copied outwards so that the final resolution was 64x64, and thus both filtered and unfiltered versions look very similar (the tileset is fairly pixelated, so filtering doesn't help much), except that the filtered render is slightly distorted (but not noticably so).

therefore, i am confident that a 66x66 (or "n+2") hack would remove the seam rendering problem while still allowing terrain texture filtering, assuming that the tiles themselves are seamless when both rotated or flipped in any direction.. again, the 66x66 hack would use normal 64x64, and other power-of-two tiles, and would algorithmically pad them with a border whose pixels are identical to the immediately inner adjacent row/column.  i also can suggest a method to effectively and reasonably deal with the extreme corner pixels without blending or averaging. also, caching of such tiles n+2 tiles may be prudent. most importantly a 64x64 hack, instead of a modified version of the 62x62 hack (which would require the original tiles to be n-2 to be effective) allows the existing seamless tiles made by such people as grimmoroe, eikie, and others, to be used and display correctly when rendered with texture filtering without any modifications, and the expense of a slight hit to memory usage (if managed correctly, this memory impact can be very minimal).

and of course, ideally, we'd find a way to implement correct texture clamping so that no hacks of any kind are needed, but for now, this should serve as a good solution, and while we're at it, we might as well try to implement something like trilinear filtering support.
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by kage »

the debug-tiles.wz mod has been given the third tileset (gamma/mountains) and has been bumped up to version 1.0.  it's in the same place as last time, but here's another link

more information on the bug where some of the map tiles are stuck as the original ones from warzone.wz, and some can be modded in: the minimap uses only the modded-in radar file, which is as it should be.
Kayiaxo
Trained
Trained
Posts: 209
Joined: 27 Aug 2007, 11:35

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by Kayiaxo »

I find some of the titles funny, could be nice for "fun maps"
As for the title stuff thats only half rendered thats for the devs :P
Image
Credits to Kacen for making the image.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: tex-filtering, esp with tiles and the 62x62 hack

Post by Per »

kage wrote: before i go on, i'll reiterate on a bug that i may or may not have posted a bug report on: as seen in the above image, even when an entire tileset is fully replaced, many (if not all) maps still show the original tileset for some tiles, and the new tileset for all others... does anyone know why this occurs?
Your tileset has names like tile-0.png, but it should be tile-00.png. Expand those single digit files with a zero. Maybe I said fixed this stupidity, but I guess I lied :P
"Make a man a fire, you keep him warm for a day. Set a man on fire, you keep him warm for the rest of his life."
Post Reply