My knowledge of texture generation is probably about 35% book learned, and 65% trial and error. There's no algorithm I've actually used from a book or other resource, per say, but instead the systems for texture generation are just from years of learning game programming and graphical design. Believe it or not, probably my best graphics teacher would be Andre Lamothe (author of the Tricks of the Game Programming Guru's series). His earlier books dealt with DOS, so there was a lot of memory management involved which taught me how textures (or in his case, sprites) were stored in memory. He showed all sorts of different optimization techniques, and cool tricks for manipulating images. His books are probably what got me started. At the end of this post are some books I own which I've used frequently to learn graphical programming. For now, here's kinda how Strata Works does it's thing
As far as texturing goes, all draw methods utilize a system of tiling (as you can see) which is pretty basic. The simple code for it is something like:
TWidth = imgTexture.Width
THeight = imgTexture.Height
for y = 0 to MapHeight - 1
for x = 0 to MapWidth - 1
imgTopography.SetPixel(x,y, imgTexture.GetPixel(x MOD TWidth, y MOD THeight))
next x
next y
That code is HIGHLY unoptimized, however, and is just to illistrate the priciple behind it. It's pretty simple. As far as the Default draw method goes, that's it. For the Strata draw method, I used a bit different of system. I don't exactly want to give away the secret to it, but suffice to say, it's really not as complicated as it may look! I happen to be lying in bed one night and the idea for the Strata system just happened to hit me
. Strata Works is actually the program I made to test the Strata system that next morning, only the whole thing sorta mushroomed into what it is today! The detail system is just like the default draw method, except that it multiplies in the pixel data into other layers. I haven't actually tried this, but someone might want to try taking a color picture from the Textures folder and try it out as a Detail texture. Might get some interresting results!
The lighting system was actually very easy to implement (minus projected shadows... those were a pain). It actually is just a modified Embossing system like you might find in a paint package. The newer system, which you guys will hopefully get a chance to preview within this coming week, is a heavily modified emboss system which takes into account, not only the direction the light is coming from with reguard to compass direction, but also the arc from the horizon. It's a bit more 3-Dimensional now, and your sunsets will actually take into account a real life sun position over your world! Projected shadows were a pain, and I'm not sure I want to fully delv into the complexities of them. They actually didn't even come out as great as I would have liked, but the next Strata Works actually raycasts on the terrain to figure out where the shadows hit. It's a LOT slower than then the other Strata Works, but it's much more accurate!
Strata Works Big Official Announcement!
I've been keeping this a bit under-wraps (with light security), but I can officially say now that I have, infact, been dappling with a fully 3-D Heightmap editor! The height editor was written in Dark BASIC Professional and takes advantage of some of the new U5.8 features for speed. There are currently 3 tools available for it: Level (default), Raise, and Lower. Level works a lot like the level terrain in the old Strata Works. Raise and lower are, actually, slightly different. They both take into consideration a median value (as does Level terrain, but it always has). For raise terrain, only terrain lower than the median will be raised up. Terrain above the median will be retained, so you can preserve mountains and hills which you have already created. Lower terrain works like the exact opposite of Raise terrain. All tools take into consideration the median (current tool height) and intensity. As of this writing, there's no brush size implemented, but I'm definetely puting one in.
The height editor only shows a 256x256 grid of your world. This is a pro and a con. Though you can't see your entire world in one glance if it is larger than 256x256, this does allow you to feasibly works with terrains which can stretch up to 4096x4096 (actually tested at 1024x1024) and possibly greater. Other terrain editors would slow down at these map sizes and become very difficult to work with. Currently, the Height editor is only in black and white. I'm still trying to figure out how I'm going to allow topography texturing, so the upcoming preview will most likely not show your topography texture in the height editor. That may become only available in pretest, but we'll see.
I'd better get back to work on it! Hope I answered your questions enough.
References for Beginners and Intermediates Developers
These are a few books I've learned from. Most of these are outdated, so you could probably find newer, more contemporary development, books on the market (NOTE: Most of these are C++ based books):
Tricks of The Game Programming Gurus by Andre Lamothe. (Dos game programming)
More Tricks of The Game Programming Gurus by Andre Lamothe. (Dos game programming)
Tricks of The Windows Game Programming Gurus by Andre Lamothe. (Similar to above, but geared for Windows and directX)
3D Game Art by Luke Ahearn. (A must have for people new to creating textures with Photo Shop or Paint Shop. Many great texturing techniques!)
Visual Basic Graphics Programming by Rod Stephens. (VB6 based, but great for not only teaching you cool graphics tricks, but also for teaching you how VB6 can interface with the API. Probably too old now, but a definite keeper!)
Beginner's Guide to DarkBASIC Game Programming by Harbour and Smith. (EDIT: Forgot to include this. I haven't really used it much, but bought it out of curiousity. For a complete beginner to programming, this is a great guide for learning Dark BASIC.)
I also have many many more books, but these are my most commonly used books.
Home of DOOP, Strata Works, and Height