ZSystem: fractal universe generation

Two OpenGL programs, ZSystem t2 and zterrain, built on the design below. The OpenGL helper library in their MSVC folders carries the line “Copyright (c) 1998 Gremlin Interactive Ltd. Written by Mark Lord”.

ZSYSTEMS
--------



Fractal universe generation system



Terms
-

The SEED of an object is a random seed which is used to create
pseudo-random numbers.

A PARAM is a named piece of data.

The PARAMLIST of an object is a set of named pieces of data.

The INDEX of an object is it's position in it's parent's list
of objects.

The ADDRESS of an object is a string of INDEXes.  This uniquely
defines it and it's PARAMLIST - object can be generated from
this information.

An OBJECT is stored as a pointer to it's object function.

An OBJECTLIST is a list of OBJECTs each with their own
PARAMLIST.

The CACHE is a set of OBJECTLISTs stored against their
ADDRESSes.  The cache is a fixed size and a least recently
used scheme will probably be used to expire entries when space
is needed.

An object function creates a set of subobjects from it's SEED
and PARAMs.  This set is cached using the ADDRESS as a key and
the object function is only called again if that entry has been
removed from the cache.

The ZSYSTEM object which is passed around to all functions
contains global state information for the system like the CACHE
and the universal OBJECT. (Each ZYSTEM has it's own cache -
it's not global to the program)



The cache
-

Cache operation:
  Given an ADDRESS returns an OBJECTLIST if one is stored for that ADDRESS
  Can add an OBJECTLIST for a given ADDRESS



Object functions
-

An object function creates an OBEJCTLIST from a PARAMLIST and a SEED.
This is then cached against the ADDRESS of that object.  If the
OBJECTLIST is already cached then the object function does not need to
be called.  If a function does not produce an object list then

At the lowest level objects give way to primitives.  How does this work?



ZSystem code
-

There is a lot of global state (which is passed around as a ZSYSTEM
object)

You create a ZSystem with a specific entrypoint which is a universe
object function.  And then you can render this universe from any
viewpoint.



ZSystem data
-

A ZSystem object has associated with it some dynamic data:

Cache - stores subobjects and parameters so they don't need to be
        recalculated.
Params - Parameters for the current object function
Seed - Current random seed



ZSystem state
-

An object function



ZREGION



void MySubObject(ZSYSTEM zs)
{

}



void MyObject(ZSYSTEM zs)
{
  ZREGION *r = ZsGetParam("region");

  ZSystem_Param(zs, "colour", 0xFF6699);
  ZSystem_Param(zs, "shape",  5);

  ZsObject(zs, MySubObject);

  ZSystem_Begin(zs, ZSubObject);
    ZSystem_Param(zs, "region", r2);
  ZSystem_End(zs);

  // ...
}

Source

Lewpen's pattern generator

“Lewpen's pattern generator” is the window title of a family of programs that each compute a 256 × 256 animated pattern every frame: Pattern, New Stylee and PatternsMK2. The first PatternsMK2 build survives in several named variants (“3 differences - spots before your eyes”, “4 differences - coloured 3d”, “6 differences - mad”), and as this capture:

A screen capture of PatternsMK2 version 1 (recorded 28 April 2010), played by Ruffle. demo.swf
A grey-scale pattern of interlocking swirls

Source

ZGo: networks of functions

ZGo takes the pattern generator a step further. Its design notes, in four parts:

ZGO
---

The basis for ZGo is a network of functions which generate a piece of graphics.
By modifying the initial parameters to the network over time the graphics will animate.
DATA TYPES
----------

With ZGo 1 I'm going to stick to 256x256 images

Integer
-

A 32-bit integer

Real
-

A floating-point value

Channel
-

256x256 array of unsigned bytes

Image
-

Array of up to 4 channels:

  1 Channel  - Greyscale
  2 Channels - Greyscale, Alpha
  3 Channels - Red, Green, Blue
  4 Channels - Red, Green, Blue, Alpha



IMPLEMENTATION
--------------

Data items will be described using a common structure:

typedef struct
{
  char name[64];
  int type;
  void *item;
}
ZGO_DATAITEM;
FUNCTIONS
---------

A function takes a set of data items, performs some operation on them and returns a set of data items.

eg.

  Fade (IMAGE im1, IMAGE im2, REAL alpha) -> (IMAGE im3)

There are two types of function - native functions and user functions.
Native functions are stored in DLLs which have a defined interface (see below)

User functions are networks of functions (both native and user) which have an input and output interface
All will be made clear



IMPLEMENTATION
--------------

Functions are stored one per DLL in a functions folder.  The DLL contains a function to perform
the ZGo function on the input data and some functions to get information about the ZGo function.

DLL Exported Functions
-


function



DATASET WRAPPER
-

ZGO_DATASET*  ZGo_DataSet_Create()
void          ZGo_DataSet_Delete(ZGO_DATASET* ds)

void          ZGo_DataSet_AddItem(ZGO_DATAITEM* di)
int           ZGo_DataSet_NumItems()
ZGO_DATAITEM* ZGo_DataSet_GetItem(int index)



FUNCTION WRAPPER
-

There is a wrapper on top of the DLLs to call the ZGo functions.

ZGO_DATASET* ZGo_Function_Call(char* fname, ZGO_DATASET* in)
NETWORKS
--------

A network is a set of connected functions.  The outputs of functions are connected to the inputs of others.



NETWORK WRAPPER
---------------

ZGO_NETWORK* ZGo_Network_Create()
void         ZGo_Network_Delete()

ZEffect, an early Java version

Java applet, run by CheerpJ. Main class: ZEffect

ZGo in Java: PatternsMK2 version 4

Java applet, run by CheerpJ. Main class: ZGoTest
ZGo output: grey streaks like folded silk
ZGo output: an embossed, rocky grey texture

ZGo in C++: PatternsMK2 versions 5 to 8

Back in C++, ZGo became a class per function: reals, images, matrices, cameras, 3D objects, distortions, faders and the arithmetic between them. Version 7 is saved as “just before complete scene 1”; version 8 adds MakeCamera1, MakeObject1 and MakeScene1. Alongside sit ZGo1, a first C++ program with a plugin, and ZGoBuilder, a Java applet titled “LKS Site3D v0.01” with the comment “Zero-Now 3D Web site v0.01” (only its source survives).

Source

Triangle rendering in Windows

A Win32 program for drawing texture-mapped triangles; its About box reads “Copyright (C) 2000”. The work is in the Heffer library, with two text files of triangle fillers for 16-bit screens. triangle.cpp opens with a hand-scheduled inner loop:

VERSION 1 - 8 clocks

    ;AGI

    mov eax, ebx
    add edx, 0x00000000       //  SM

START:

    rol eax, width

    and eax, mask
    adc ebx, 0x00000000       //  SM

    add esi, 0x00000000       //  SM

    mov ax, [eax+0x00000000]  //  SM

    mov [edi+ebp], ax

    mov eax, ecx

    rol eax, width

    and eax, mask
    adc ecx, 0x00000000       //  SM

    add edx, 0x00000000       //  SM

    mov ax, [eax+0x00000000]  //  SM

    mov [edi+ebp+1], ax

    mov eax, ebx

    add ebp, 2
    jnc start

Source

PixelText

PixelText 001
-------------

  . Basic render framework

The font is drawn in a text file, one letter beside the next:

 aaa  aaaa   aaa  aaaa  aaaaa aaaaa  aaa  a   a aaaaa aaaaa a   a a     a   a a   a  aaa  aaaa   aaa  aaaa   aaa  aaaaa a   a a   a a   a a   a a   a aaaaa
a   a a   a a   a a   a a     a     a     a   a   a      a  a  a  a     aa aa aa  a a   a a   a a   a a   a a       a   a   a a   a a   a  a a   a a     a
aaaaa aaaa  a     a   a aaaa  aaaa  a  aa aaaaa   a      a  aaa   a     a a a a a a a   a aaaa  a   a aaaa   aaa    a   a   a a   a a a a   a     a     a
a   a a   a a   a a   a a     a     a   a a   a   a   a  a  a  a  a     a   a a  aa a   a a     a  a  a   a     a   a   a   a  a a  aa aa  a a    a    a
a   a aaaa   aaa  aaaa  aaaaa a      aaa  a   a aaaaa  aa   a   a aaaaa a   a a   a  aaa  a      aa a a   a  aaa    a    aaa    a   a   a a   a   a   aaaaa

Source

PolyCSG: boolean operations on polygons August 2002

Constructive solid geometry for 2D polygons: XOR, AND, subtract and OR of polygons, rendered a scanline at a time. The changelog at the top of PolyCSG.cpp runs through the eleven versions; version 007 is dated 26 August 2002:

PolyCSG 001
-----------

. Basic render framework up and running

PolyCSG 002
-----------

  . Added Image class
  . Converted buffer to Image class

> First draft of polygon class

  . Polygon edge rendering (scanline based)
  . Not yet tested

PolyCSG 003
-----------

  . Solid rendering

  . Added scanline class
  . Use scanline class for polygon rendering
  . Moved classes to seperate cpp & h files

  . Pass polygon into buffer to render

PolyCSG 004
-----------

  . Removed Poly.render - have to use Image.drawPolygon
  . Added first CSG option - XOR
  . XORPoly.render used to render

PolyCSG 005
-----------

  . Get poly subclass rendering working ( Image.drawPolygon )
  . Add ANDPoly class
  . Polygon intersection (AND) up and running!

PolyCSG 006
-----------

  . Fix in ANDPoly class ( oka && okb -> oka || okb )
  . Added SUBPoly
  . Added ORPoly

PolyCSG 007
-----------

  2002/08/26 01:00 (while smackdown was on after playing cards at the house - Steve won)

  . Added getVScanline function to all polys
  . Added or,and,sub class declarations to main file
  . Renamed Image.drawPolygon to Image.fillPolygon
  . Renamed Image.drawScanline to Image.fillScanline + made private
  . Added Image.drawPolygon, Image.drawScanline, Image.drawVScanline
  . Removed Poly.render (use Image.fillPolygon instead)

  NOW SUPPORTS RENDERING FILLED AND UNFILLED POLYS

PolyCSG 008
-----------

  ~ Antialiased poly functions
  . Added Image.blendCol
  . Initial AA tests.. need edge gradients stored in scanline points

  . RotatePoly class added
  . Poly.firstPoint, nextPoint & peekPoint added

  POLYGON ROTATION WORKING

  . Added pixel text functions to Image

PolyCSG 009
-----------

  . Added TranslatePoly class
  . Fixed memory leak in Redraw() - was not deleting all Poly's

  > Interesting poly shapes

TODOs
-----

  . Poly.recalc function instead of re-making tree each time
    - starts off manual (must be called from main code)
    - change to automatic (use frame counter to avoid re-recalc-ing)
  . TranslatePoly class
  . Predefined polygon classes
    . Regular
    . Star
    . Cog
  . Demo showing different effects

  . Get translation and rotation working for boolean op polygons

  . Optimisation: know v & h bounds of polygon to make render loop quicker

The same class library went on into the RTRay raytracer and the animations below.

Source

Circle animation, Oil and Waves

Three small animations on the same Classes library (image, scanline, polygon and raytrace classes), each starting from the PolyCSG / Motion / RTRay changelog. Circle animation adds:

Animation 001
-------------

  . Renders scrolling array of circles with pulsing wave

Oil is the “basic image template”, with version 001 dated 5 August 2004; Waves is built from the same template.

Source