Procedual Terseness

Published October 17, 2007
Advertisement
The Most Communicative Of Fingers

This entry was going to be a bit longer, but:

OWW MY LMF ASPLODE!


Yeah. It's the classic tale of "boy meets girl, girl rejects boy," except you replace "boy" with "finger," "girl" with "wall," and "rejects" with "breaks."

Sometimes playing wallyball can be considered dangerous.


Procedural Textures

As part of the framework for the game I am currently writing, I'm going to have as much texture data as possible be procedural and cached in on the fly. There are a few reasons for this choice (many of which should be obvious):

  • Less disk usage - very useful if I hit my target of, oh, say, a certain game console
  • Non-repeating textures - textures don't have to tile. I can keep caching in new ones.
  • Seriously, I suck at texture art - This way, the computer does it for me!


I'm still working on the method, but here are a few examples:



Click to enlarge

These are all generated on-GPU, using ps_3_0 shaders. The noise implementation comes straight (thank you, copy-and-paste) from GPU Gems 2, which is an awesome book.

The idea is that objects (especially static world objects) will have unwrapped UV coordinates (like you'd use for lightmaps). To generate the textures onto the objects, I'll do the following:

  1. Create a texture that is the requisite size (or pull it out of a pool, which is more likely
  2. Render the objects into the texture, using the UV coordinates as the position (scaled from [0,1] to [-1,1] of course).

  3. Pass the position and/or normal to the pixel shader, use it to generate the texture data
  4. Repeat for as many textures as the object needs (some combination of diffuse color, normal, height, glossiness, etc).


Should be pretty easy. Obviously, there are some patterns that are ridiculously difficult or even maybe impossible to generate efficiently on the GPU, so I'll probably still use some pre-made texturemaps. But as much as I possibly can do on the GPU, I will. The main gotcha will be keeping the amount of texture info that needs to be generated to a minimum, so there aren't any render stalls. That's more of a level design/art problem though (which, because this is being developed lone-wolf, is also my problem).

If you want to see the shaders I've used and the code that I used, here is my sample app (with full source):

ProcTexGen.zip - 29KB.

The source is ridiculously uncommented because I coded it over the span of maybe 3 hours as a quick prototype, and the shaders are, I'm sure, nowhere near efficient. Also, they don't handle negative values very well, which is why many of them add 100 to the coordinates (HACKHACKHACK).

Enjoy! And if you make any awesome textures with it, please let me know :)
0 likes 4 comments

Comments

Trapper Zoid
Ow - that was the exact same finger I sprained a couple of months ago (except obviously on my hand, not yours). I'm assuming you're not left handed like me though, so it isn't quite as disabling? How bad was the break?

The textures look pretty spiffy too; did you have to code up special examples for the different tiles or do you have some tessellation magic going on in there?
October 17, 2007 04:28 AM
Driv3MeFar
Quote:Original post by Drilian
  • Less disk usage - very useful if I hit my target of, oh, say, a certain game console


How much memory overhead is there to generate a texture procedurally? Memory on certain game consoles can be pretty sparse all things considered. Is it really worth the cost to generate these on the fly (or at load time) versus just storing these textures on the disc and loading them at opportune moments?
October 17, 2007 04:28 AM
Saruman
Quote:Original post by Driv3MeFar
How much memory overhead is there to generate a texture procedurally? Memory on certain game consoles can be pretty sparse all things considered. Is it really worth the cost to generate these on the fly (or at load time) versus just storing these textures on the disc and loading them at opportune moments?

Regarding consoles and even casual games on the PC it is much better to burn less disc space and take a few extra seconds to generate textures. XBLA has a limit which can be hit insanely quick, and on the PC casual players don't like to download large packages and you have to make it as small as possible to compete against the flash games, etc.

I don't see where you have any memory overhead as you have generated textures where they are needed so you would likely have them paged and loaded from disc anyways. Also on consoles texture loads aren't exactly free and depending on the situation generating a procedural could be a much better solution as you don't have to pack your data accordingly, queue from disc, etc.
October 17, 2007 09:33 AM
Drilian
Quote:Original post by Driv3MeFar
How much memory overhead is there to generate a texture procedurally? Memory on certain game consoles can be pretty sparse all things considered. Is it really worth the cost to generate these on the fly (or at load time) versus just storing these textures on the disc and loading them at opportune moments?


Minimal. The memory overhead really comes from the shader that generates the texture, which is small - the texture itself shouldn't be any bigger than if I loaded it from disk.

Quote:Original post by Trapper Zoid
Ow - that was the exact same finger I sprained a couple of months ago (except obviously on my hand, not yours). I'm assuming you're not left handed like me though, so it isn't quite as disabling? How bad was the break?


It's a chip fracture just under the knuckle so it's not BAD, but my hand is still out of commision for about a month. The worst part is that I can't ASWD or hold a game controller in a useful fashion right now, so gaming is out :(

Quote:Original post by Trapper Zoid
The textures look pretty spiffy too; did you have to code up special examples for the different tiles or do you have some tessellation magic going on in there?


Thanks :) There's no tesselation, it's all single-quad render. I coded up special pixel shader algorithms for the tile/brick and the hex tiles (in the file procedural.fxh in the zip, if you're interested), anything else is just noise generation.
October 17, 2007 01:11 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement