Table of Contents

FART Scene File Syntax

This document describes the syntax of the scene description files used by the FART Raytracer.

Scene description files are represented in an ASCII-based, hierarchical language.

Example Scene Description File

First, a simple example:

scene {
    options {
        width 400
        height 300
    }
    camera {
        position <5, -5, 4>
        look_at <0, 0, 1>
    }
    light {
        position <10, -10, 50>
    }
    plane {
        position <0, 0, 1>, 0
        material {
            color <0, 1, 0.2>
            reflectance 0.4
        }
    }
    sphere {
        radius 1
        translate <0, 0, 1>
        material {
            color <1, 1, 0>
        }
    }
}

Scene Loading Phases

Scene description files are loaded in three phases.

Phase 1 : Initial Parsing

First, the scene file is parsed and a tree of nodes is created. Basic syntax errors are caught at this point, but placement of nodes is not (such as a “plane” containing a “radius”, or such). for(), while(), if(), and other scripting nodes are simply stored as regular nodes in the tree.

Phase 2 : Script Execution

After the parse tree has been made, it is traversed in order, and scripting nodes are executed. The result of this phase is a new node tree devoid of any scripting nodes, and with exactly one object node for every object in the scene.

Phase 3 : Scene Construction

The node tree produced in phase 2 is traversed (not necessarily in order) in order to build the scene objects which will be used while rendering the scene.

Scene Description File Elements

Identifiers

In various elements, identifiers are required, for example, when giving a name to reusable shapes or materials for easy reference later.

The format of an identifier is:

IDENTIFIER ::= [a-zA-Z_][a-zA-Z_0-9]*

Object Elements

scene

Every scene file must have exactly one scene node, and it must be the top-level node in the file.

Syntax:

scene {
  scene_items
}

scene_items can be any of:

options

Syntax:

options {
  options_items
}

options_items can be any of:

Most of these options can be overridden from the command line. See Executing FART.

camera

Syntax:

camera {
  camera_items
}

camera_items can be any of:

light

Syntax:

light {
  light_items
}

light_items can be any of:

Scripting Elements

Variables

Syntax:

VARIABLE ::= $[a-zA-Z_][a-zA-Z_0-9]*

Variables, which are only used during the execution phase, are differentiated from identifiers by a preceding “$” symbol.

Variables can be declared by simply assigning to them:

$x = 42

If a variable $x exists in an outer scope but a newly scoped $x is desired, one can be created with the local keyword:

local $x

or

local $x = 42

Expressions

Operators:

The operators were designed to work like they work in C. The arguments to modulus are converted to integers.

for loop

for (initial_expression; test_expression; post_expression)
{
  for_items
}

The for loop works like in C. Pretty much anything can go in for_items.

while loop

while (test_expression)
{
  while_items
}

Once again, pretty much any element can appear inside while_items.

if

if (expression)
{
  elements
}
elsif (expression)
{
  elements
}
else
{
  elements
}

Works like in C.

Built-in Functions

Function calls look like they do in C. Here's how to call built-in functions:

function_call ::= IDENTIFIER '(' parameters ')'

parameters ::=
parameters ::= expression more_parameters

more_parameters ::=
more_parameters ::= COMMA expression more_parameters

Here are the built-in functions supported: