PDA

View Full Version : Planet texture generation code



SilverWarior
01-04-2012, 10:07 PM
Hi guys!
Does anyone have some code for generating planets textures. If not any tutorial on this mater would be verry halpful.

LP
01-04-2012, 10:34 PM
For a more general-purpose solution, Terragen (http://www.planetside.co.uk/) can be quite useful. In Photoshop, one of the best texture generation tools is Filter Forge (http://www.filterforge.com/).

Finally, you can create textures in code by calculating perlin noise (http://devmag.org.za/2009/04/25/perlin-noise/). Doing so in real-time can be complicated, but on GPU it is quite a possibility.

Ñuño Martínez
01-04-2012, 11:37 PM
Do you know the "Sand game"? You can do something similar. Clean the texture to 0. Then "drop" a "sand grain", that is, select a coordinate and if there are a "lower land" around it let the grain "fall" to this lower place and start again. Add some random when you look around for "lower land".

Carver413
02-04-2012, 06:29 PM
I am working on some texture generating stuff as part of my framework.in the lower right is a typical noise fuction. all of these were created with a script which to me makes more since because of the tweaking involved to get the look right.the other advantage is that scripts are much smaller the actual bitmaps so they can be generated when needed rather then stored. in the future I hope to have a full array of noise functions and a real time editor to aid with script creation.


BITMAP4:TestMap = {400,400} []
VECBYTE4:Blue = [0,0,200,255]
VECINT4:Frame = [10,10,80,32]
VECBYTE4:LiteBlue = [100,100,255,255]
VECBYTE4:Red = [150,50,100,255]
ARRINT:Weaved = {8}
[%11110000,
%10010000,
%10010000,
%11110000,
%00001111,
%00001001,
%00001001,
%00001111]
ARRINT:Diamond = {8}
[%10000001
%01000010,
%00100100,
%00011000,
%00011000,
%00100100,
%01000010,
%10000001]
ARRINT:Block = {8}
[%00011000,
%00011000,
%01111110,
%11100111,
%11100111,
%01111110,
%00011000,
%00011000]

Map(TestMap,LiteBlue,Blue)
Clear()
SetMapTags(PenMode,Alpha)
SetInk(Pattern,Weaved,GradSlot,Color1,Frame,100,10 )
Fill(Frame)
SetInk()
Smooth(Frame,1)
Rectangle(Frame)

MoveFrame(Frame,2,0)
SetInk(Pattern,Block)
Fill(Frame)
SetInk()
Smooth(Frame,1)
Rectangle(Frame)

Frame = [10,44,80,32]
SetInk(Pattern,Block)
Fill(Frame)
SetInk()
Smooth(Frame,2)
Map(TestMap,Red,Blue)
SetInk(Pattern,Diamond)
Fill(Frame)
SetInk()
Map(TestMap,Blue,Blue)
SetInk(GradSlot,Color1,Frame,40,12)
Fill(Frame)
Map(TestMap,LiteBlue,Blue)
Rectangle(Frame)
SizeFrame(Frame,-2,-2)
Rectangle(Frame)

Frame = [92,44,80,32]
Map(TestMap,Red)
SetInk()
Fill(Frame)
Map(TestMap,LiteBlue,Red)
SetInk(Cloud,Color2,4)
Fill(Frame)
SetInk(Cloud,Color2,2)
Fill(Frame)
SetInk(Cloud,Alpha,1)
Fill(Frame)
SetInk(GradSlot,Alpha,Frame,40,12)
Map(TestMap,Blue)
Fill(Frame)
Map(TestMap,LiteBlue)
Rectangle(Frame)
SizeFrame(Frame,-2,-2)
Rectangle(Frame)


http://www.dreamincode.net/forums/topic/66480-perlin-noise/

WILL
02-04-2012, 10:08 PM
procedurally generated would be quite neat and save you a ton of space for assets. :)

You may have longer load times as result though.

pitfiend
02-04-2012, 11:40 PM
if you are on Gimp, you can try this ones:
- http://gimp-texturize.sourceforge.net
- http://fimg-gmplugins.sourceforge.net
I guess that there is a perline somewhere in Gimp too.

EDIT: in this place http://devmag.org.za/2009/04/25/perlin-noise/ you can find a way to create your own textures using perlin.

Carver413
03-04-2012, 07:10 PM
procedurally generated would be quite neat and save you a ton of space for assets. :)

You may have longer load times as result though.

Using scripts to create textures doesn't necessarily mean slow. if we are able to create a texture from a script then we could save that texture same as any. we can create and save textures as they are needed and dispose of them when they are no longer needed. because they are scripts they can be influenced by the game that uses them.

WILL
03-04-2012, 09:37 PM
That's completely true. You could have the game detect the textures, if they are not found then generate the textures the first time it's ran.

igmac
03-04-2012, 11:26 PM
Does anyone have some code for generating planets textures.

What kind? A single large texture to wrap on a sphere? Or were you wanting interpolated texture maps? Also, from what distance? Close up, or the sort of thing you'd see in orbit around a planet?

SilverWarior
04-04-2012, 02:35 AM
I will probably use Perlin noise for generating textures, hgeightmaps, etc.

igmac
04-04-2012, 08:11 AM
You mention heightmaps, from which I gather it's not a planetary view? So am I correct in assuming that you are actually generating a terrain map rather than a planet map? Something for close up view where you only ever see a very small portion of the terrain at any given time?

SilverWarior
04-04-2012, 06:12 PM
My wish is to have both, but for the moment I concentrate more on planetary view.
Also after doing some research I see that perlin noise can come in handy in other fields aswell, even for things that I wasn't even planing before.

igmac
04-04-2012, 06:55 PM
for the moment I concentrate more on planetary view.

http://mygimptutorial.com/the-ultimate-gimp-planet-tutorial

That works pretty good for a spite type view. If you're looking for a cylindrical projection to wrap around a sphere, maybe try Gimp and the phfluuh plugin. But I haven't tried that myself yet.

SilverWarior
05-04-2012, 11:01 AM
Lets me get something clear. I wan't to have planet texture generation capability inside my game so that I can generate necessary texture when I need them. For instance before entering star system for the first time. This is posible becouse traveling from one star system to another do takes some time.
I did manage do make my own implementation of Perlin noise but unfortunatly my implementation is too slow. So if anybody of you guys have decent Perlin noise code I would apretiate if you could share it.

SilverWarior
07-04-2012, 11:59 PM
Good news I found a bug in my code wich was making it runs so damn slow. So now my implementation of perlin noise like algorithm works with decent speed.
But since I now use Delphi random function it only generates me real numbers between 0 and 1 while original Perlin Noise algorithm uses real numbers from -1 to 1.
So I was wondering if anybody of you have code for random number generator wich is capable of generating random numbers between -1 and 1.

igmac
09-04-2012, 07:21 AM
capable of generating random numbers between -1 and 1.

r := random(2) - 1

Jimmy Valavanis
09-04-2012, 08:36 AM
r := 1 - 2 * random;

SilverWarior
09-04-2012, 10:33 PM
Thanks guys but I already solved the problem.
r := (Random -0.5) *2;

My Perlin noise like procedure is now done to the part that I can get mostly same results as from one of example programs I found on the web. No source code unfortunatly so I cant do any real speed comparison.
I might do partial rewrite of it so it will give me more options for postprocessing. This way I belive to get much better results.
But since I already spent more time on this than I expected I must postpone this for a while and start working on the rest of the game. Having best planet generation algorithm does me no good if I don't have a game in wich to use this algorithm.

WILL
10-04-2012, 12:03 AM
How did it turn out? :)

SilverWarior
10-04-2012, 12:55 AM
Sorry Will no pictures yet.
There is still lot of work needed to be done in planet generation algorithm. Currently I would need to rewrite my Perline noise like procedure so that instead of generating 2D array of height points wich are then used for calculation rest of the heightpoints on the map it will fill some custom list, with custom objects each representing height point. But besides height this objects would also contain information for points relative position (probably just 3D point). This would alow me sorting them so that I would be able to easily divide my map into various height regions:
1. LowestHeight to 0 = undersea area (mostly flat with smoth height variations)
2. 0 to 15 = beach areas (nise eazy sloped beaches)
3. 15 to 50 = plains (mostly flat with smoth height variations)
4. 50 to 100 = lowlands (various smal hils)
5. 100 to 150 = highlands (various larger hils and hil plathous)
6. 150 to 200 = mountains (various mountains and mountain ranges)
7. 200 to Max height = mountain peaks
Besides making verry nice heightmas this will also provide me with good information to determine wich texture will be used where.
If all would work as I imagined I should get verry realistic maps out of it. But as I sad before completing it would probably take another week time of work if not even more. So I'm afraid that you will have to wait some time after the competition to see my planet generation algorith finally in action.

whtemple1959
05-11-2012, 01:40 AM
SilverWarior,
I am attempting the impossible.
Part of my plan is to start with a planet as the game area as opposed to a square. I have been looking for a google earth, earth 3d, ossimplanet equivalent for Pascal but have not found anything...until I found this post.
I would be very interested in learning about your progress.
Thanks in advance,
Bill

SilverWarior
05-11-2012, 05:45 AM
whtemple1959 welcome to PGD first.
Unfortunately I haven't done much progress so far. As you might nit know this was part of myGame project with whic I intended to ener 2nd PGD mini competition. But since there was a time limit I had to abandon further development on this part and try to finish rest of the game. Unfortunately I was unsecsessful as the time ran out before I managed to create games GUI (spent more time on this mater than I planed).
Even after the 2nd PGD mini competition was over I had not resumet work on this becouse I got idea of making a library which would alow me to easily make GUI for any of my future games.
I must also admit that I haven't done much programing in the last mont or so. I0m having problem getting myself to do any work.

My original goal was to use perling noise function to generate heightmap texture, use some postprocessing on this texture for finetuning and then finaly use the heightmap to generate planets surface texture. I didn't have intention to make actuall planet model but only to make texture which I could render on a sphere so that it will look atleas a bit similar to planet.
Sure I could apply heightmap to the sphere to actually gain elevated terrain but this was deffinitly out of my reach for a project which needed to be done in a month time.

You are saying that you intent to use sphere for game map instead of square map. What dimensions do you intent to use? If you want lots of percision you have to realize that this will require lots of space for textures.
For instance Google Earth suposingly uses more than 150 TB of data for storing all the surface images.
http://www.gearthblog.com/blog/archives/2006/09/news_roundup_google.html

Now if you want quickest answer about how to implement planetary map in your game I recomend you to get in contact with Sascha Willems the author of game named Projekt Weltherrscher.
http://www.pascalgamedevelopment.com/showthread.php?13968-Projekt-Weltherrscher-quot-Phase-2-quot
He is using planetary map in his own game and I'm sure he will be glad to help you out. I only think that he has no algoriithm for radom map generation but I might be wrong (havent tried latest version of his game).

User137
05-11-2012, 01:30 PM
Gimp is your best friend if you want a simple planet done ;) I just drew all kinds of noise and blurs with different colors, then finally apply "Make seamless" effect. This makes the texture wrap from sides so that you can use it as texture, without visible edges when coords 0 and 1 clash. Different planet types ended up looking like this:
https://docs.google.com/open?id=0B7FII3MhcAHJUHhhbVRnam9rTVU
Each have 2 cloud layers which rotate the planet at different pace.

SilverWarior
05-11-2012, 04:16 PM
Yes I agree but if you remember I was trying to make algorithm which would randomly generate planet textures inside my game.

User137
05-11-2012, 04:39 PM
Depends on what you need from the texture. To backtrace actions you would do with Gimp, and replicating with Pascal is not that hard. But does it need to support close-up generation, like zooming in tiny section of the planet and generate a new high quality texture to that? Then you need a real formula, and can't rely on random, blurring or anything like that. I could suggest sine-waves in multiple layers and in different frequencies. You can have 1 set of waves with X-coordinate and other for Y, then sum them up for RGB or heightmap representation.

Say, sin(X) does a very static wave that you can see repeating. But (sin(X)+sin(0.9+0.31235*X)*0.7124) will not make any repetitions. Although, for it to wrap around seamlessly you might want it to have some repeat, scale it with proper PI-multiplications etc...

AthenaOfDelphi
05-11-2012, 08:22 PM
Guy W. Lecky-Thompson wrote a couple (maybe more books) on this subject which I found very interesting.

Inifinite Game Universe: Mathematical Techniques (ISBN 1-58450-058-1) (http://www.amazon.com/Infinite-Game-Universe-Mathematical-Development/dp/1584500581/ref=sr_1_1?ie=UTF8&qid=1352145995&sr=8-1&keywords=infinite+game+universe)
Infinite Game Universe: Level Design, Terrain and Sound (ISBN 1-58450-213-4) (http://www.amazon.com/Infinite-Game-Universe-Volume-Development/dp/1584502134/ref=sr_1_4?ie=UTF8&qid=1352145995&sr=8-4&keywords=infinite+game+universe)

I'll confess I've only really read the first one properly, it's about the maths behind things like sequence generators, pseudo random number generators and fractals (to name a few) which you can use to seed levels from a single number. I was reading them because I wanted to be able to store a huge game universe in an absolute minimum amount of data. Anyone old enough to recall the game Whirlygig and the ST and Amiga? I believe that used seeding techniques for scenario generation and had something like 33 million levels and yet fitted on a single sided 3.5" disk, a mere 360KB.

Anyhow, I digress. There is a lot of information about this sort of procedural generation and seeding available on-line. User137 is quite correct though, for more than a handful of planets, building them by hand will be too much effort and maths will have to take center stage to generate them. As he has alluded to, the trickiest part is the seamless texture, but if you use 3D Perlin noise to generate your data values (this is seeded and so will be repeatable if memory serves and more importantly, it is seamless so you don't have to worry about that specifically) you can use a polar coordinate scheme to map a position on the sphere to a position on a bitmap and generate your textures dynamically. Perlin noise can also, again if memory serves correctly, scale well so you can zoom in fairly easy.

I say 'if memory serves' alot, because I did spend a lot of time looking into this stuff myself about 6 years ago... I've consumed a few crates of beer since then and I've slept quite a lot so my memory of the details isn't 100%, just the principles.

whtemple1959
05-11-2012, 08:39 PM
Hello,
I do beg every body's forgiveness as I struggle to understand the dynamics of programming and how best to express my vision and goals.
To start, a game that I enjoy playing is a 2D game of course played on a square surface. If you start at point a and move in a straight line to the right when you come to the edge you can go no further. Now in my mind you should be repositioned to the the left side and be able to continue on your path.
It is my impression that the only why to accomplish this goal is to have a spherical game space...of course I could be wrong.
As a beginning base for my project I would prefer this 957as a game space. With the ability to zoom into street level yet not have the streets or buildings one would find in say google maps. Natural Earth does have the appropriate dataset although there would need to be some work done as when their maps are zoomed in they get blurry. But, I am sure there is a height map, shapefile that can resolve that issue.
Then there is the issue of the actual ...algorithm... to create the proper paths such as something like these.958

Now, not being a programmer much less a game programmer, I can image that there is some process to achieve this goal. But, I am not yet knowledgeable enough to understand it.

I, in my project am attempting to fly from space, land, drive in a vehicle until I come to the ocean, then board a ship etc. etc.
Once I figure out the 3D terrain then I hope I can then combine it with other open source code snippets to finish the project...easier said then done.

So, I guess the real question is. Does a terrain engine or a game engine allow for this type of path following? Will I need a PhD in mathematics to program the behavior or has some wizard already figured it out? If there is an engine that will allow embedding satellite imaging to create a natural earth terrain could some one suggest it to me?

As always all advice an d admonishments are appreciated.
Bill

Sascha Willems
06-11-2012, 05:57 PM
I just read your comment on my profile page, so I guess it's better to answer here than via private messaging :

What you're planning to do is a huge undertaking, and even a skilled programmer may need several years to implement what you want to do. So prepare to learn a lot, especially when it comes to 3D realtime graphics, physics, path finding and optimizations.

Zooming in from space to the "street level" of a planet is a very complex thing to implement. You need a smart (and performing) way of storing your data (even with a high-end GPU and much RAM you won't be able to keep all necessary data in memory all the time), some continuous level-of-detail algorithm with advanced visibility checks to actually only draw what's visible (again same as storing all data isn't possible, rendering everything, if not visible or too far away, would be too much for your hardware). And these are just the basic. Adding good physics is another thing and many physics engines won't be well-suited for such a continuous scaling from space to ground.

A very good place to learn about the techniques necessary for what you're about to do is http://vterrain.org

When it comes to rendering planets and all the stuff they contain this page is a treasure chest of knowledge. So maybe take a look at their articles, though most of them will be very hard to understand unless you're pretty good at programming and have done something in terms of terrain renderning.

So as an advice you should just start at ground level, render a limited terrain (using maybe octrees for visibility checks, to learn about this important feature) with basic physics that allow the player to walk on the terrain. Then start adding objects like trees and roads, include a phyisics engine for the vehicles and then zoom out stept by step, always adding to your base.

SilverWarior
07-11-2012, 08:04 AM
@whtemple1959
Are you just trying to transform OpenTTD to work on globe or are you trying to make the game to work with real 3D graphics?
If it is the first option than it can be done but you will have to lower the detail to only have roads and railroads between large cities. Reason for this is the fact that you will never manage to sucsesfully simulate everything if there would be too much detail.
I'm not sure for OpenTTD but original Transport Tycoon Delpuxe had the limitation of how mny of each structures, roadrs, rails can be on any map. And it was quite low so when playing on largest maps you quicly got to that limit which prevented you to build further.
This was all implemented so that game simulation kept running smothy even on bit weaker computers. I asume that OpenTTD has theese limits a lot higher since todays computers are much more powerfull. But still I don't think that they are enough powerfull of sucsessfully running simulation of the whole world with such detail as present in OpenTTD.
But if you plan on making your game in full 3D graphics than you will have to scale down your simulation part even further becouse processing 3D graphics is quite demanding.

User137
07-11-2012, 09:01 AM
Some things can be learned from minecraft. It's not world size that makes a difference, but how much you show it at the time. If you need a real Earth model, you need to stream it from existing data sources. I'm not sure if Google-maps contain height information. If it does, you can use splines to smoothen out the details in between. Then again i'm not sure if that also counts as "blurred". There simply isn't height data in 10 meter accuracy propably anywhere, and such database would be measured in terabytes.

Could add that with Earth data we are working in 2D pretty much. So possible optimizations go propably for quadtree, not octtree. Any data can be indexed or arranged in such a way that you can look them up quickly. Especially for project like this, you can expect that "player" doesn't make any changes to the terrain, so it's possible all the data can be in static sized blocks. That simplifies things.

Oh, also the Earth topic might go on another thread entirely? Not so related to texture generation at all now.

SilverWarior
07-11-2012, 11:51 AM
Some things can be learned from minecraft. It's not world size that makes a difference, but how much you show it at the time.

Yes Minecraft can be good exampla of how to have huge maps with low memory consumption.
But From what I understand whtemple1959 is trying to make real time strategy game similar to OpenTTD. For RTS you need to have whole map loaded at all times.


I'm not sure if Google-maps contain height information.

Google-Maps do contain height information but it is only available through Google Earth application and not Online Maps.


There simply isn't height data in 10 meter accuracy propably anywhere, and such database would be measured in terabytes.

I belive Google Maps do have such acuracy.


Especially for project like this, you can expect that "player" doesn't make any changes to the terrain, so it's possible all the data can be in static sized blocks.

If he is trying to make somekinda remake of OpenTTD he will probably alow player to modify terrain as it is posible in OpenTTD.

User137
07-11-2012, 02:03 PM
Yes Minecraft can be good exampla of how to have huge maps with low memory consumption.
But From what I understand whtemple1959 is trying to make real time strategy game similar to OpenTTD. For RTS you need to have whole map loaded at all times.
&
If he is trying to make somekinda remake of OpenTTD he will probably alow player to modify terrain as it is posible in OpenTTD.
Nope, only need to load parts where things are happening and even then just what is needed.

Need bit more information maybe. From whtemple1959's message it sounded like RPG or adventure game. In any case, you can't have the whole world "living" at the same time. If you have key structures like airports or such, they can be separate objects from the terrain entirely. Can send aircraft to different airports and so on. Just when you load their area you would see them visually. Single cars in city streets, there's no reason to simulate that for whole world at all times.

Slightly related on topic is 1 of my units in nxPascal (http://code.google.com/p/nxpascal/source/browse/trunk/src/nxData.pas). Capable of keeping a huge world loaded up in memory at the same time. Unused parts are compressed, and used parts are automatically recompressed after certain time of no use.