Thursday, December 17, 2009

Procedural graphics books, sites & resources

(I will constantly edit this post to add what I know. Please add your own suggestions in the comments)

Books: (links go to Amazon)

-Computational beauty of nature by Gary William Flake.

Great book, goes over lots of ideas about how you can write code imitations of the wonderful patterns of nature. He includes source code to his books written in C, I have often looked at these while coding myself.

-The Fractal Geometry Of Nature by Benoit B. Mandelbrot

Mandelbrot coined the word "fractal", brought the field into the computer age and discovered the Mandelbrot set.

-Real Time Rendering (parts, some include) 11.1 Sources of three-dimensional data pg 438

-Texturing & Modeling: A Procedural Approach

-Computer Graphics by Foley, Van Damme etc - various chapters

-Graphics gems - Various techniques spread out among the (many) books

Online Articles:

The AI System for Left 4 Dead by Valve -article describing procedural gameplay. Left 4 Dead is a first person shooter where you are part of a small team and have to fight your way out through a zombie hoarde. The monsters, guns and excitement level is adjusted based on the intensity of the player experience.

The demoscene uses procedural graphics to generate impressive scenes in incredibly small code sizes. A collection of some on pouet.net

Sunday, December 13, 2009

Diffusion limited aggregation

Click the image on the left to view the canvas demo.

This is an example of diffusion limited aggregation - a natural process where randomly moving particles stick together, to form clusters. A good example is crystals.

An initial seed is fixed in place, then particles are randomly moved around until they hit part of the main cluster, where they stick. This leads to a bigger cluster and feeds back on itself, producing a stochastic fractal (Stochastic means a random process)

Code comments:
I wrote this after looking at the C code for "diffuse.c" from The Computational Beauty of Nature (see books). An optimisation I copied from there is to constrain the particles to within 10 pixels either side of the cluster, to stop particles wandering off where they would never hit anything. This shouldn't have too much effect on the resulting graphics but is much faster (especially at the start)

Tuesday, December 8, 2009

Future blog posts

I thought I should write about the goals and future directions on the blog. The main point for me is that regularly publishing updates will encourage me to do more, and better coding as I explore procedural graphics. I hope others can learn or enjoy them too.

The demos so far are in canvas, as I started learning Canvas recently. Thoughts on canvas:

-Very easy to share. Just load a page to view demo, and view source to read the code.
-Javascript the language is good and bad, but I miss having a good editor.
-Canvas is really slow.

2d vs 3d: After a certain level of scene complexity, I find it easier to do things in 3d rather than 2d, as you can just create the points and lots of things are taken care of for you. I don't think the web is a great platform for 3d graphics, and so I will be using Java applets and Open GL.

TODO:

canvas:
-Stochastic fractals (see Diffusion)
-A few more generated nature scenes etc like "Forest Night": beach, city scape, snowflakes
-A stripped down format for drawing shapes in canvas
-A polygon, shape etc editor for canvas
-I don't know the word for this subject, but visualisations of entity interactions - eg predator prey, termites, game of life, boids, daisy world, iterated prisoner's dilemma etc

Java applets:
-Procedural city generation (from my existing C++ code)
-Terrain generation (eg mountains)
-Texture generation (eg I have seen algorithms that move pixels randomly in 3d, take a 2d slice and the texture looks something like marble)
-Plant generation (including 3d L-System turtles)

Animation demo


Click the image on the left to view the demo. (requires FireFox/Chrome)

Note (22/1/2010): I think there is a bug here to do with loading the image. If you see a cross and no picture, click reload and it should fix the problem (I'll fix it properly soon)

The TV should show an image off the web, mixed with random static. You can change the image to something supported by your browser. Andrew M found out animated .gifs work, for instance copy "http://www.moonbattery.com/BashKeyboard.gif" to the URL at the bottom.

If you right click on a canvas element, you can get an URL for the current image. I then used that as the input for another tv, to get the recursive picture going on the right.

This was made for me to further learn HTML5 canvas, including animation (using callbacks in .js), CanvasPixelArray, masking and using images.

Tuesday, November 24, 2009

L-System


An L-System in javascript & canvas. You can use a drop-down box to alter which fractal is drawn and how many iterations to perform.

An L-System is a way of describing self-similar fractals, like plants - it works by changing symbols according to rules and performing multiple iterations.

To display, the final string is interpreted by a turtle which uses them as instructions (eg go forward, turn left, etc)

The wikipedia article is worth a look, it is where I got the axioms & rules from.

Warning: If you alter the values and set them to high it may freeze your browser

UPDATE: L-System version 2

Monday, November 23, 2009

Forest Night

The idea is you're lying on your back in a forest, looking at stars.

Click the image on the left to view the demo. Press reload to view a different version.

Written in Javascript / HTML Canvas (use Firefox, or anything other than Internet Explorer)

Field of flowers


A field of flowers

Click the image on the left to view the demo (warning: takes a few seconds)

Written in Javascript / HTML Canvas (use Firefox, or anything other than Internet Explorer)