Procedural generation of textures

Tips for creating and manipulating planet textures for Celestia.
Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Procedural generation of textures

Post #1by Chuft-Captain » 27.07.2007, 11:04

Does anyone have available a utility or script that will take as it's input a series of RGB values (as numbers, perhaps comma separated) and generate as it's output a lossless image of a specified size with pixels matching the colours specified by the input values?

Cheers
CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #2by selden » 27.07.2007, 11:41

ImageMagick includes appropriate functions.

e.g.
convert -size 2048x2048 xc:skyblue \
-pointsize 12 \
-fill white -stroke gray \
-draw "line 0510,1493 1523,1493 " \
-draw "line 1016,1999 1016,0142 " \
-draw "line 1016,0049 1016,1906 " \
-annotate 0x0+1020+1485 " 0.0 " \
tmp.png galactic_map.png

This just gives you a flavor of what it can do. It's not intended to do exactly what you asked.
Selden

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #3by Chuft-Captain » 27.07.2007, 15:48

Here's some pseudo-code which may make it clearer what I want to do...
The pixelcolor() function would apply some rules based on the pixel position and possibly other factors to determine the colour of the pixel and return the appropriate bytes for output.
Is Imagemajick up to this sort of task do you think? I'm not so much looking to process an existing image (although that would be useful too) but rather generate an image from scratch based on some simple or complex rules encoded by the pixelcolor() function.
At the moment I've coded these rules into a spreadsheet, but getting the appropriate color bytes, header and other control bytes output in the correct order in order to create a valid BMP or PNG file is problematic from EXCEL.

Code: Select all

{
writefileheader();
for 1 = 0 to 2047
{
    for j = 0 to 2047
    {
        write( pixelcolor( i, j, otherfactor ) );
     }
     writescanlineterminator();
}
writefileterminator();
}


The pixelcolor() function needs to be reasonably clever, so an alternative (if ImageMagick doesn't have the nescessary logical constructs and math libraries), would be to export the spreadsheet values as CSV's and then use a tool such as IM to read this and transform into the appropriate file-format.

PS. I'm a baby with regards to internal structure of BMP's or PNG's etc, so please excuse any mis-conceptions or mistakes. I'd appreciate any expert advice in this area. ie. how to construct correct header and file structure etc... :wink:
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 21 years 3 months

Post #4by ajtribick » 27.07.2007, 16:02

It might be overkill, but you could set up POV-ray to do that (has a lot of procedural textures built in, and you can specify user-defined functions).

Since the textures are defined in 3D, you can use a spherical camera in the centre of a sphere to get an image you can map onto a planet in Celestia.

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #5by selden » 27.07.2007, 17:35

By itself, ImageMagick can be used to create the image files. (Of course, IM includes many types of standardized image manipulation functions.) You could write a program which creates scripts which specify particular IM commands which set specific pixels to specific colors. That way the program doesn't have to worry about the actual file formats, just about the pixels.
Selden

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #6by Chuft-Captain » 28.07.2007, 01:59

I think what you're suggesting Selden is to use another language to generate IM commands and then run the resulting script in IM to generate the image. Am I reading you right?

If this is the case, then it suggests that IM's scripting language does not have looping, conditionals, and access to math functions such as SQRT, POWER, RAND, etc...,
...otherwise you would be suggesting to use IM's scripts to do the whole job in one hit, wouldn't you. :?: :(

Cheers
CC

PS> Chaos, thanks also for the info, but yes I think it probably would be overkill. I'm only looking to generate 2D maps, initially just night-textures.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #7by selden » 28.07.2007, 03:21

ImageMagick itself is not a programming language. It is a set of utility programs which are used to manipulate images. All of its utility programs include within them an interpreter for the commands that can draw pixels, lines, circles, etc.

There is an optional package associated with ImageMagick which is a programming language based on perl. I've never used it because I've never needed to use perl. I use other languages, like Fortran (and now Lua :) )

You really need to take the time to read ImageMagick's documentation. Asking other people to read it and interpret it for you will only lead to misunderstandings and confusion.
Selden

Avatar
LordFerret M
Posts: 737
Joined: 24.08.2006
Age: 68
With us: 18 years 3 months
Location: NJ USA

Post #8by LordFerret » 29.07.2007, 03:01

Chuft-Captain wrote:... PS. I'm a baby with regards to internal structure of BMP's or PNG's etc, so please excuse any mis-conceptions or mistakes. I'd appreciate any expert advice in this area. ie. how to construct correct header and file structure etc... :wink:

If it's any help...

Some good reference here -
http://en.wikipedia.org/wiki/Windows_bitmap

and here -
http://www.fileformat.info/format/bmp/egff.htm

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #9by Chuft-Captain » 30.07.2007, 13:49

selden wrote:There is an optional package associated with ImageMagick which is a programming language based on perl. I've never used it because I've never needed to use perl. I use other languages, like Fortran (and now Lua :) )
Thanks Selden... that's promising news.

selden wrote:You really need to take the time to read ImageMagick's documentation. Asking other people to read it and interpret it for you will only lead to misunderstandings and confusion.
Apologies if I've wasted your time Selden. I'm on narrow-band so I try to avoid long downloads only to find out the software doesn't do the job...so I try to get opinions first if I can. (It also helps to avoid a huge investment of time spent learning a tool only to find it doesn't do what I want)
Your answers (especially the fact that it includes a programming language) gives me hope that it may be worth the download...looks like I'll be learning PERL sometime soon.
(t00fri will be pleased! :wink:)

LordFerret, thanks for the references...I suspect however that if I learn ImageMagick it will take care of all the format details, so I won't need to worry about the internals anymore. I would need this information if I was to resort to writing my own tool, but that was always going to be unlikely given the number of other tools already out there.

Cheers
CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #10by selden » 30.07.2007, 14:12

CC,

The documentation is all on the Web and isn't quite as large a download as the software itself :).
http://www.imagemagick.org/
http://www.imagemagick.org/Usage/

There's also a Web forum where you can read about others' experiences.
http://studio.imagemagick.org/magick/
Selden

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #11by Chuft-Captain » 30.07.2007, 14:29

I'm reading http://www.imagemagick.org/script/api.php as we speak Selden. :lol:

Looks promising... as I know a little C, .NET, Pascal, and TCL.
(Although I note that the .NET wrapper does not currently expose pixel-level commands) ... I suspect there's a little more reading for me to do before I dive in and choose an API, however IM itself looks like a very complete and capable tool.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS


Return to “Textures”