Create a gist now

Instantly share code, notes, and snippets.

@paniq /csgvm.txt Secret
Last active Dec 28, 2015

What would you like to do?
CSG Virtual Machine
CSG virtual machine:
each register represents a 3D space with unspecified bounds, and has two parts:
D: signed distance
- typically internally stored as an interval over the selected region
the program is applied to. holds a floating-point lower and upper bound.
M: material
- an N-element vector of linear interpolable floating-point values
- albedo: red, green, blue
- roughness
- metallic
- emissive
- etc.
for clarity, we'll refer to registers as spaces from now on.
the machine has at least three spaces, S0 as the main and S1 and S2 as spare
spaces, to allow temporary creation and accumulation of shapes created using
CSG intersection.
requirements for operations:
each operation, or a contiguous list of operations must be cullable
by an optimization process; while operations are always executed in order
of declaration, culling optimizations test this list against repeatedly
subdivided axis-aligned bounding boxes, and remove operations that do not
contribute to surface creation or material changes.
this means that operation output must always describe a surface and material;
spaces should never store anything but intervals over a surface
function and their associated materials. this is something to keep in mind
when designing new operations.
it would also be useful to keep all operations in L2 metric, so the output
of blending union / difference / intersection operations remains predictable
for the user. this is however not a requirement of the VM.
these are known operand attribute names and associated types:
SOURCE: register
TARGET: register
PRIMITIVE: integer
typical choices:
ORIGIN: 3 x float
SIZE: 3 x float
BASIS: 3 x float packed versor (|q| = 1)
MATERIAL: N x float
FEATHER: float
IR operations
%o = empty
%o = full
%o = primitive [prim size origin basis]
%o = material %x [material]
%o = add %a %b
%o = sub %a %b
%o = and %a %b
%o = sadd %a %b [feather]
%o = ssub %a %b [feather]
%o = sand %a %b [feather]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment