Texture mapping: The Third Way

Sunday, August 24th, 2003

Surely there’s nothing I can say about texture mapping that hasn’t been said already? Well I’m going to have a go, on the sub-topic of filtering.

Normally you have this paradigm that says you can have your textures filtered or unfiltered. In the old days [more than 5 years ago] filtering was expensive, because it had to be done in software, but these days it is used by default in 3D hardware acceleration.

To illustrate, here is a detail of a texture map, close up and ever so slightly rotated, rendered without filtering and with filtering respectively:

Un-filtered

Filtered

We [computer programmers & designers] tend to accept that we can choose one or the other… we can have super crappy blocky pixels [in certain circumstances much faster to render] or we can have soft blurry fuzz, using bilinear [or bicubic] filtering. Now my problem with this dichotomy is that sometimes you might not want your pixels to be all fuzzed together… maybe you want them to be square [imagine tarmac with sharp edged lines and block letters on it… filtering will just make it look intolerably blurry]

So what’s wrong with un-filtered textures?

What many people don’t realize is that turning off filtering actually results in two levels of pixellation:

  1. Pixels from the source image appear as whole squares.
  2. Edges between the squares are also pixellated, resulting in jaggies - see detail of white pixel.

Because of 2, non-filtered textures look crappier than they need to. But these jaggies have nothing to do with the source image! If we are rendering a field of sharp edged squares the edges of those squares should look like straight lines, not staircases.

But how can we anti-alias the edges of the squares without the squares themselves becoming blurry? Easy! Un-filtered textures and anti-aliasing are NOT mutually exclusive. We just use a modified bilinear filtering algorithm, but we adjust it so that it only filters the pixel thick edges of the squares [this is a slight over-simplification].

Anyway, I have an algo which does this, allowing a sliding scale of bilinear filtering (from "non" to "full"):

Non-filtered

Edge-filtered

Half-filtered

Full-Filtered

The reason I’m writing this now is because I have been doing some work programming for 3DSMax lately, and was surprised to discover that even though its renderer anti-aliases everything else (so that polygon edges are not jaggy) it still does not do any anti-aliasing within un-filtered texture maps.

Note that the patterns on the cube pictured to the right clearly exhibit jaggies between the checkers, while the actual cube edges are lovely and smooth [just as you’d expect them to be]. This inconsistency makes the rendering look a bit crummy, and makes it hard to imagine a use for non-filtered textures in 3dsMax.

Sneaky!

Thursday, August 21st, 2003

I just got an email that claimed to be from a bank asking for me to visit a site and "re-enter" my details. I have seen these before of course, but this one is subtly different in that the URL appears more "real" ie you can hover your mouse over it and in the status bar it looks valid. Here is an example of the trick:

http://www.officialsite.com

Note how the status bar message reads with the same URL [in MSIE anyway]. Click on it and you’ll get sent to my home page however. It works by using the login syntax for URLs, where you can put http://, only in the above example the username is used as a dummy to look like a domain name, and then loads of spaces are put between this and the @ symbol, so that you don’t see the rest on your status bar.

Until now I have relied on the link appearing in the status bar to tell me reliably where I will be sent… now I realize I can’t even trust that.

Friday, August 15th, 2003

No news

Not much to report right now, since I am actually doing some work for someone else. Here in the meantime is a video that is terribly terribly funny (and clever):

http://ridah.net/stuff/matrixpingpong.wmv (3.4 MB)

Two Point Five D

Saturday, August 9th, 2003

As usual I find myself sucked into trying fancy tricks rather than concentrating on original intentions. The super simple pure 2D concept stuff has taken on a ‘thickness’ dimension for rendering purposes, just to look wizzy. It’s funny, but even though the physics and movements are all still the same, somehow the extruded look adds to a sense of motion [although the frame rate is beginning to suffer; my path rendering algorithm is working a lot harder than was originally anticipated]. Part of the reason I went for this look is the simple challenge of working out a nice algorithm to extract the "sides" of a 2D path as another 2D path. All curves remain perfect curves, there is no tesselation going on. Should be useful for 3D font effects, should I ever want to go there ;)

Battlestar Galactica Remake

Thursday, August 7th, 2003

( link )

Apparently it’s going to be totally different from the original, which may not be a bad thing, since I was never that much of a fan (and the original has dated somewhat). Here’s the quote that gets me though:

"We considered seriously how space travel might happen. In outer space, objects in motion remain in motion. You can’t bank against a gravitational pull. There’s a sense of organized chaos, you have to turn your craft around and fire jets in the opposite direction to slow down — just like the old games. When we were developing the show, I ran around telling everyone, ‘Remember Asteroids! Remember Asteroids!’"

- from Wired article

I am embarrassed to admit I added an optional "fake" factor to to allow for more conventional fighter plane style dogfighting… a dogfight without aerodynamics is a bit like jousting on ice.

Hooray! I’m not alone in wishing to see a decent attempt at realistic space flight! This kind of decision alone could make it worth watching, because it will change the look and feel of the show, and stop it looking like a Star Wars clone. I can’t wait to see how they do space battles though.

Firefly and Farscape

While on the subject of SciFi, I can’t understand how Firefly got the axe after just 10 episodes, and yet Farscape survived for 4 seasons! Firefly had less overhead I’m sure (with no aliens and simpler costumes & sets) and it wasn’t a complete load. Farscape seemed to be based on that horrible idea that the only kind of hero is an obnoxious American one, who probably played college football. I don’t know if this is a particularly western phenomenon, but I really despise the popular fantasy of visiting an entire alien culture/world/universe to discover that you are superior to every single person it it! The original set-up in the first episode was also a lame ripoff of Wizard of Oz, with his emergence from the worm-hole right on top of the brother of some powerful warlord. What are the odds, eh?

Contrast Crichton’s cardboard masculinity in Farscape with Mal’s character in Firefly: Crichton is clean-cut, go-getting American, therefore he is a hero. Mal earned his hero status, by having fought and lost on the side of the resistance. He is slightly bitter, but puts it behind him. He does not believe in moral absolutes, though he tends to do the right thing. He is not a hero, nor an anti-hero, and seems more ambivalent than anything [an ambi-hero?]. He’s got pretty good instincts, but he doesn’t go around constantly telling people how important it is to go with your guts [think every other american in space]. OK, so the point I’m obviously trying to make is, Firefly may not have been great, but it didn’t suck ass as much as Farscape.

Holy frijoles!

Wednesday, August 6th, 2003
SCO will not actually tell anyone what the infringing code is specifically (unless they sign an NDA), probably because then Linux developers could just replace it with non-infringing code. The question is, if it is that easy to replace, why do they insist it is so valuable?

As little interest as the Linux world holds for me, I find myself outraged by the ongoing harrassment [of Linux developers and users] by SCO. SCO alleges that Linux contains code which is derivative of Unix source, which they own. They accuse IBM of copying this code from Unix to Linux. Even if this is true, the offending source is unlikely to make up more than a tiny percentage of the Linux codebase. And yet:

That’s right, SCO wants $699 from a user for running Linux, an otherwise free operating system. May they poach in hell.

Clearing out

Sunday, August 3rd, 2003

Further to previous comments about losing track of years at a time, one of the things I have apparently done in the last few years is two thirds of a BA. Unfinished of course, and I almost certainly will never complete it now. I can barely remember doing it at all, and all I really have to show for it are some weird essays on Semiotics:

  1. principle differences between Peirce’s semiotic and the work of scholars in the European traditions of semiology and philosophy
  2. the relevance of semiotics

It’s funny reading them now, especially the first two, since I forget ever being able to write so "academically". Not that they are particularly great essays [the irritating word ‘trope’ isn’t used once!]… For some time standards at Australian universities have been sliding in order to support a more "vocational-training" approach. This is partly why I didn’t bother finishing my degree I think… it was too easy to slide through without really learning much or growing intellectually. Also I was probably too old to really enjoy it. [advice: If you are thinking of higher education, think sooner rather than later]

More Curvy Things

Friday, August 1st, 2003

Have done a little more work with my 2D path routines, so if nothing else I can at least collide perfect circles with them remarkably accurately. I’ve been a bit sidetracked recently by other things, like itself, which is helping me test these routines.

Joy of Physics

One of the most lamentably absent things in computer/video games of the last 30 years is realistic physics. Technical innovation has largely been directed toward improvements in graphics quality and rendering speed, but surprisingly little has been done in the area of mechanical simulation. Fortunately this is now changing, as more and more games implement rigid body dynamics [currently mostly flight sims and driving games, and soon first person shooters like Half-Life 2 and Doom 3]

Elastomania is a brilliant game which demonstrates that physics can be more important than graphics (although it would be good if the graphics were better too) Well maintained fan-site here.

was to be a Newtonian extravaganza, and may still be one day, but a lot of the cool physics is only half implemented, and collision detection between arbitrary 3D objects is and probably always will be an unbelievable pain. Resting contact works great, except when objects inexplicably acquire infinite kinetic energy and fly off into to the nether regions of floating point precision.

Whilst collision detection is vastly different between 2D and 3D, it turns out that 3D rigid body dynamics are only slightly more complex than 2D. This means that a robust physical simulation system in 2D has the potential to be extended into 3D without too much fuss. So now I am thinking, hey, why not get a rock solid 2D system working first [it’s also easier to debug] and then I can retrofit that into any 3D system I want to build. And then I’m thinking, hey, is this the most appropriate use of my time? And then I’m going, like, screw you buddy, I’ll do what I want…

Ctors

The big news on the front is that it now supports constructors, making it a lot more object-oriented. Destructors will also be supported at some point, but since there is no memory allocation in JujuScript there’s less of a need [resources are tracked using reference counting and deleted when no longer required]. It’s very neat, because I also allow intrinsic types to have their constructors overridden! For example, if you want to specify that all double precision floats are initialized to -1, the following snippet is all you need:

function double::construct()
{
   this = -1;
}

I intend to avoid the hideous C++ practice of naming constructors and destructors after the types themselves… yuk! I am unaware of a good reason for doing it that way.

I will probably change the syntax a little before finalizing it… I really have to nail down some of these things… also I am still not sure how much late-binding to support [currently it is all incredibly late binding… so late that you can even add/override methods on the fly using the Eval() function, but this makes it extremely hard to optimize]