Procedural Texturing Part 2

I tend to write these posts offline, and then post them when I get a chance. That leads to cases like this one, where I keep forgetting to post it, so I end up appending to it instead, leading to a disjointed series of temporally seperated edits.

Enjoy!

– – – – –

Sooo… been ‘sperimenting.

Coming apart at the seams

Coming apart at the seams

As you can see, I’ve managed to get underbelly textures. Unfortunately, that’s not all I’ve managed to get.

The system I’ve set up to apply underbelly and back textures isn’t standard: it’s an inventive approach to the problem. Normally I’d just use multiple textures, but in this case, with so many creature’s all potentially using different textures, that would force the GPU to switch textures very frequently. Forcing the GPU to switch textures means re-sending data from the CPU, causing a bottleneck and performance loss.

So instead I’m trying to use spritesheets: a single texture divided into 9 subtextures. The shader then manually applies the appropriate sections of the texture.

You can see the problem this causes above: white grid seams where the shader tries to stitch the textures together.

This is caused by a system known as mipmapping. Mipmapping is the process of preshrinking textures (a 64×64 texture would be shrunk down to 32,16,8,4,2 and 1 pixel sizes), and rendering the smaller copies when the camera is at a distance, rather than trying to shrink and render the original large copy. This saves performance and looks better: the preshunk copies are blurred, so you don’t end up with flickery aliasing issues.

Unfortunately in this case, the shader is conflicting with the system: since the shader’s texture co-ordinates jump back to 0,0 across a single pixel rather than smoothly wrapping, the mipmapping is tricked into thinking the texture is really really far away, and it uses the tiny preshunk texture on those pixels. Since I haven’t filled out the rest of the texture, this means the pre-shunk texture is white, so the gridlines are white.

Underbelly2

So, how to fix this?

So far I’ve only found two options, neither of which is particularly good. I can turn mipmapping off. This means flickery, aliased creature textures, but at least the grid lines are gone.

Alternatively, I can mirror the subtextures rather than tiling them. This allows me to keep mipmapped textures and the sprite sheet system, at the cost of mirroring the textures. Unfortuantely, this also makes it much harder to ‘read’ the textures: a fall of long hair is a lot less convincing when it symmetrically changes direction every 30cm or so.

This is rather frustrating, because the entire visual improvement upgrade kinda relies on getting this sprite sheet system working. If I can’t get it looking decent, I’ll have to drop a large percentage of the 0.7.0 update and rethink my entire evil plan.

Or I could just shatter the planet by dropping automated nanobombs into every major fault line and detonating them in time with the earths natural harmonic frequency. Yes, YES, eliminate the evidence! It’s perfect, yeeeessssss…

Oh, um I’m… uh… disregard all… that. I’m still looking into other options and totally not devoting all my resources to nanobomb productions. Don’t bother sending any hero’s to stop me. Because there’s nothing to stop. So it would be embarrassing. If you did that. Yeah.

Heh heh heh.
Qu

– – – – –

(edit) Thank you Shawn Hargreaves. I can solve this problem with MATH! And by limiting the mip chain so it doesn’t start sampling white
pixels. And using gutters on my sprites. But mainly MATH!

Oh wait, 3 isn’t divisible into powers of 2. Dammit.

Alright, I can still do this (MATH!), it just requires careful sprite map structuring. The width of the lowest res mip map will need to
be 8, or 16. I think I’ll try 16 first: a bit of aliasing at high distance is worth the extra resolution.

1g = 64pixels
||
g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g
g-1-1-1-1-g -g-2-2-2-g -g-3-3-3-g
g-1-1-1-1-g -g-2-2-2-g -g-3-3-3-g
g-1-1-1-1-g -g-2-2-2-g -g-3-3-3-g
g-1-1-1-1-g -g-2-2-2-g -g-3-3-3-g
g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g

g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g
g-4-4-4-4-g -g-5-5-5-g -g-6-6-6-g
g-4-4-4-4-g -g-5-5-5-g -g-6-6-6-g
g-4-4-4-4-g -g-5-5-5-g -g-6-6-6-g
g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g

g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g
g-7-7-7-7-g -g-8-8-8-g -g-9-9-9-g
g-7-7-7-7-g -g-8-8-8-g -g-9-9-9-g
g-7-7-7-7-g -g-8-8-8-g -g-9-9-9-g
g-g-g-g-g-g -g-g-g-g-g -g-g-g-g-g

This gives us resolutions of 256p for large and 192p for small textures (double if I ante up the sprite size to 2048p: maybe I’ll release that seperately as a HD mod?).

– – – – –

(edit) I’ve started hacking together a rough program to generate guttered sprite sheets per the above, since I’m too lazy to do it manually. I think if I do get all this working, I’m going to put together a few similar development tools, like object visualisers and compilers, so we can see new body parts and tree’s in-engine without having to Initialise Random and go looking through the world. Tools like this are a relatively low investment compared to the time they’ll save when we go into full-scale content production mode.

– – – – –

(edit) I maed a sprite sheet. It’s got gutters and everything.

Grids. Grids are cool.

Grids. Grids are cool.

I used the aforementioned program for this, a quick mash up of XNA and Winforms. It’s very rough, but it should help spreed up production of spritesheets in the future.

And no, I won’t be using ground textures for body cov… actually scratch that that’s an awesome idea. Regardless, the sheet above is a placeholder for testing, not an actual body covering.

– – – – –

(edit) OH GOD SO MANY EDITS.

Turns out there are some… complexities… involved in using only the first 6 mip map levels in XNA. I eventually beat them with the help of SCIENCE!, but there are still some aliasing issues due to falling back to a shader implementation of bilinear filtering. Nowhere near as bad as with no mipmaps, but still noticable compared to proper anisotropic filtering.

Still, I’m not going to give up spritesheets over some flickery pixels. These improvements aren’t just graphical, they’re aesthetic: giving the creature’s body coverings more recognisable shapes and patterns will make it more apparent what they represent.

Here’s what the creature’s look like with a back texture…

Curly back fur! Sexy!

Curly back fur!

… and an underbelly texture…

A soft downey underbelly!

A soft downey underbelly!

Hmm… the eyelids shouldn’t actually be black. That’s a bug, but it actually gives some much needed contrast to the facial features. I’ll have to see about mimicking that in the actual engine.

… and here’s a few furry Primum specium’s, because I never got any way back in the 0.6.0 Gameplay Trailer.

IT'S SO FLUFFY I'M GONNA DIE!!!!

IT’S SO FLUFFY I’M GONNA DIE!!!!

I haven’t done the actual fur polygons part of the shader yet, but the procedural texturing gives the whole thing a much more discernible pattern.

It’s coming up well, though a lot of these upgrades are only going to be available to Shader Model 3.0 users. Sorry guys, SM2.0 just doesn’t have enough arithmetic slots.

Next step: teefs and clors.

– – – – –

(edit) NO! NO MORE EDITS FOR YOU!

Cheers,
Qu

Advertisements
  1. #1 by sylverone on September 27, 2013 - 7:17 pm

    Looking nice. Will there will be dedicated textures for inside the mouth and any such areas where fur wouldn’t go? It would be cool if each creature had a skin texture that would show through in places when appropriate. For instance, my cat has a pink mouth with lots of little spots of black skin coloring inside. It looks a little weird, but that’s nature (and who knows, possibly bad breeding, but what can ya do).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: