Plain Text View of SCN.TXT


Remove Frame

----- SCN -----

The SCN ray-tracing format
 
Version 1.5

Anto'nio Costa, 1993
[email protected]


Table of Contents

Table of Contents 2
1. Introduction 3
2. Overview and Motivations 3
3. Syntax 3
3.1. Viewing 4
3.2. Ambient and Background 4
3.3. Lights 5
3.4. Surfaces 5
3.5. Objects 6
3.6. Transformations 10
3.7. Textures 10
4. Annex 11



1. Introduction

The SCN (SCeNe format) was invented to replace a very simple format called 
SFF for the RTRACE ray-tracer. It is used to describe environments (geometry, 
topology, attributes, etc.) that are processed by programs called ray-tracers, 
although it can be used by other programs.

2. Overview and Motivations

The RTRACE ray-tracer uses a very simplistic format (its only advantage is 
the simplicity!). It reads only numbers (and strings for file names), but 
its syntax is very rigid.  To avoid this, I decided to create a much more 
elaborated, easy to write and flexible scene description format, which I 
called SCN. To avoid modifying the RTRACE input code, a translator from 
SCN to SFF was implemented as a separate program (SCN2SFF), meant to be 
used as a preprocessor for RTRACE (in UNIX and DOS, these two programs 
can be used in a pipe like scn2sff | rtrace).

3. Syntax

The SCN format does not have sections like SFF, it supports comments and 
even other preprocessor constructs (for example, cpp and m4 for UNIX and 
DOS). Another important difference is that it has default values for some 
scene parameters, which means that they do not have to be specified at all. 

The basic components of SCN are:

comment - they start anywhere on the line with some special character 
like ; # or % and terminate in the end of line.

integer - any valid integer number, an integer expression inside 
parenthesis or the result of the int() function. 

Examples:

0
1
-2
(1 + 2); 3
int(10 / 3); 3

real - any valid integer or real number, a real expression inside parenthesis 
or the result of any real-valued function like sin(), cos(), etc. 

Examples:

0.0
1.5
(1 + 2.1); 3.1
log(2); 0.6931

color - a triplet of RGB reals between 0 and 1. In certain cases, the 
RGB reals may be bigger than 1 or negative (color_extended). It is also 
possible to use names that represent the RGB values or the mono keyword 
followed by just one real. 

Examples:

0 0 0; black
1 1 1; white
1 0 0; red
white
red
mono 0.5; medium gray

point - a triplet of reals representing X Y and Z values or the result of 
any point-valued function like normvector(), addvector(), etc. 

Examples:

0 0 0; world origin
10 5 1
1 (2 + 1) (10 * sin(0.1)); 1 3 0.0175

normvector(1.1 2.5 -2.3); 0.3081 0.7001 -0.6441

addvector(1 2 3, 4 5 6); 5 7 9

vector - similar to a point, but cannot be equal to 0 0 0.

filename - a set of characters (letters, digits and others) with no blanks 
between. It is recommended to use only file names like those of UNIX and DOS.

expression - anything inside parenthesis. An expression can be integer or 
real. The expression operators are + - * / ^  and | . 

Examples:

(1 + 2); 3
(1 - 2); -1
(1 * 2); 2
(1 / 2); 0.5
(1 ^ 2); 1.0
(5 | 3); 2

function - there are many functions available. The integer/real-valued with 
integer/real arguments are int(), sin(), cos(), tan(), asin(), acos(), atan(), 
sqrt(), rtod (), dtor (), exp(), log(), abs(), max() and min(). The 
dotvector() function has two vector arguments and returns a real 
number. There are also functions with point/vector arguments that return 
point/vector quantities like normvector(), addvector(), diffvector(), 
scalevector() and crossvector(). 

Examples:

tan(dtor(45)); 1.0
rtod(atan(1)); 45 degrees
log(exp(2)); 2
abs(-1.5); 1.5
max(0, 1); 1
dotvector(1 0 0, 0 1 0); 0.0
scalevector(1 0 0, 2); 2 0 0
crossvector(1 0 0, 0 1 0); 0 0 1

3.1. Viewing

To specify viewing parameters one can use the following instructions:

eye point - where the camera is (default is 5 0 0); from can also be used.

look point - where the target of the camera is (default 0 0 0); at can 
also be used.

up vector - the camera vertical direction (default 0 1 0).

fov real [real] - the horizontal/vertical fields of view (default 22.5 
degrees); angle can also be used. If there is just one value, then both 
fields of view are equal.

Examples:

eye5 1 1
look0 1 0
;default up is 0 1 0
fovrtod(atan(320.0 / 200.0 * tan(dtor(15)))) 15; 23.21 15

3.2.Ambient and Background

To specify the ambient and background colors, there are the following 
instructions:

background color - the background color; default light_blue_sky (approx. 
0.1 0.5 0.7).

ambient color - the ambient color (diffuse global lighting); default 
0.1 0.1 0.1 (dark gray).

Examples:

background white
ambient mono 0.2

3.3. Lights

To specify lights attributes, there are several instructions:

light point point [color_extended] - this is a point light that irradiates 
in any direction. If any of the color components is negative, then there is 
no distance fall-off. Default color is white.

light directional vector [color] - this is a light like the Sun that 
irradiates along a direction, with no distance fall-off.

light spot point vector color_extended [angle [factor]] - this light 
illuminates inside a cone defined by the angle (default 45 degrees) with 
a transition that can be sharp (factor near 1) or 
smooth (factor >> 1). The default value for factor is 1.

light extended point color_extended radius samples - a spherical light sampled 
samples2 rays.

Examples:

light point 2 6 1 yellow
light directional -1 -1 -1; white
light spot 0 5 0 0 -1 0 red 30 2; smooth 30 degrees spot
light extended -3 5 3 green 0.5 8; 0.5 radius light sphere

3.4. Surfaces

A surface is a non-geometric attribute that each object must have so that 
it can be rendered. When a surface is defined in a certain scope, it is 
considered the current surface and many objects may share it without having 
to name it explicitly. There is even a default surface (surface white mono 0.9 
mono 0.1 3 0). To specify surfaces, there are the following commands:

surface color [diffusion specularity phong metalness [transparency]] - phong 
and metalness are reals, the others are colors. Defaults 0.9 0.9 0.9, 
0.1 0.1 0.1, 3, 0 and 0.1 0.1 0.1; if only transparency is omitted, then its 
default is 0 0 0.

surface strauss color smoothness metalness [transparency] - all are colors; 
default transparency is 0 0 0. This is an alternative to the previous 
command that uses a more intuitive way of specifying attributes.

surface matte color - 100% diffuse surface.

surface plastic color smoothness phong - plastic surface (high diffusion, 
small specularity and phong factor).

surface metal color smoothness phong - metallic surface (small diffusion, 
high specularity and phong factor, maximum metalness).

surface dielectric color transparency refraction - non-opaque surface (no 
diffusion, small specularity, large phong factor and no metalness). Needs 
a refraction index.

surface glass color transparency - transparent surface with refraction index 
near 1.52 and similar to dielectric.

refraction real - this specifies the current refraction index.

Examples:

surface blue mono 0.7 mono 0.3 15 0.7; matte
surface strauss brown mono 0.9 mono 0.1; matte
surface matte red; 100% matte
surface plastic beige mono 0.8 0.5; plastic
surface metal white mono 0.9 0.9; metallic
surface dielectric white mono 0.8 1.2; translucent
surface glass white mono 0.95; white glass

3.5. Objects

The supported objects in SCN can be of two types. The objects of the first 
type define a closed volume, while the others do not and must be handled with 
care inside CSG operations (see the list primitive below).

Any object may inherit global attributes like surface, textures and 
transformations or else define its private attributes using the data keyword 
before its geometric information. It is also possible to group several 
objects and make them share some attributes using the group ... ungroup 
keywords. 

Example:

transform none
surface matte white                 ; current surface
box ...                             ; white
group
  surface matte red                 ; current surface inside block
  transform rotate y 45 ...         ; current transform inside block
  sphere ...                        ; rotated, red
  cone surface matte green data ... ; rotated, green
  cube bump data ...                ; rotated, red, bump texture
  cylinder ...                      ; rotated, red
ungroup
prism ...                           ; white

The closed objects are:

sphere [... data] center radius - a sphere.

box [... data]center sizes - an axis aligned box.

cube [... data]center size - an axis aligned cube.

cone [... data]apex base base_radius - a cone.

cylinder [... data]apex base radius - a cylinder.

cone truncated [... data]apex apex_radius base base_radius - truncated cone.

wedge [... data]point point point depth - a wedge is defined by a triangular 
face and an extrusion vector whose length is depth; the face is defined 
counterclockwise and the vector points in the Right Hand Rule direction 
(this convention is general in SCN).

tetra [... data]point point point point - a general tetrahedron (composed 
of four triangles).

prism [... data]depth vertices point ... point - a prism defined by a 
polygonal face and an extrusion vector similar to wedge.

pyramid [... data]depth vertices point ... point - a pyramid.

torus [... data]out_radius in_radius start_angle end_angle [out_samples 
in_samples] - a torus is centered in 0 0 0 and lies in the XY plane (0 
degrees is in the X axis direction and increases counterclockwise). Actually, 
a torus is composed by a collection of Phong triangles whose density is 
defined by out_samples in_samples (default 16 8).

text3d file [... data]filename - text primitives stored in a file (high 
quality 3D letters, symbols, etc).

Examples of these objects:
   
   
   
   
The opened objects are:

cone open [... data]apex base base_radius

cylinder open [... data]apex base radius

cone truncated open [... data]apex apex_radius base base_radius

prism open [... data]depth vertices point ... point

pyramid open [... data]depth vertices point ... point

pyramid truncated open [... data]depth apex_scale vertices point ... point - 
this is an opened pyramid with the apex face scaled by apex_scale in relation 
to its base face (0 is an opened pyramid and 1 is a opened prism).

disc [... data]center normal radius - a circle.

ring [... data]center normal out_radius in_radius - a circle with a hole.

patch [... data]point ... point (12) - a bicubic patch is defined by its 
corners and eight exterior points arranged like with 4 5 8 9 being the 
patch corners. The patch normal points toward the reader.

patch file [... data][point [point]] filename - a group of patches stored in 
a file; first point defines a translation and second a scaling.

polygon [... data]vertices point ... point - polygon without holes.

polygon file [... data][point [point]] filename - a group of polygons stored 
in a file.

triangle [... data]point point point

quadrangle [... data]point point point point - four-sided polygon.

triangle normal [... data]point vector point vector point vector - a triangle 
with normals in its vertices (also called Phong triangles).

triangle normal file [... data][point [point]] filename - a group of Phong 
triangles stored in a file.

torus open [... data]out_radius in_radius start_angle end_angle 
[out_samples in_samples] - an open torus.

Examples of opened objects:
   
   
   
   
  
Finally there are instructions that allow the creation of complex objects:

csg operation [... data]begin - begin of a CSG operation. The type of 
operation may be union, intersection or subtraction. A CSG (Constructive 
Solid Geometry) is a binary operation performed on two object operands 
(which may also be CSG's).

csg next - this instruction separates the definition of the left (first) 
operand of the CSG from the right (second) operand.

csg end - this instruction terminates the CSG.

Examples of CSG:

   
There is also one instruction that joins several simple objects into a 
primitive object. This is mandatory for CSG or else errors will appear in 
the picture:

list [... data]begin - start of a list of objects, at least two.
list end.

This instruction must be used in a CSG context when at least one of the 
operands is composed of opened objects (please note that each CSG operand 
must bound a finite volume). 

Example:

list surface matte brown begin ; a new object similar to a pencil
  cylinder open  0 -1 0   0 1 0   0.3
  cone open      0 1.3 0  0 1 0   0.3
  sphere         0 -1 0           0.3
list end

3.6. Transformations

A transformation is an operation that modifies the geometry of an object. 
Normally, transformations are concatenated to previous transformations, 
although it is possible to do it in other ways.

transform none - discards all previous transformations.

transform scale factor [factor factor] - scaling transformation.

transform translate point - translation.

transform rotate x angle - rotation about the X axis (angle in degrees).

transform rotate y angle.

transform rotate z angle.

transform rotate vector angle - rotation about an axis passing through origin.

transform general point point point [point] - any transformation matrix 
(3x3 or 4x4).

3.7. Textures

A texture modifies in some extent the characteristics of a surface. It is 
possible to apply transformations to textures and even keep them independent 
from object transformations.

texture none - discards all previous texture transformations.

texture scale factor [factor factor].

texture translate point.

texture rotate x angle.

texture rotate y angle.

texture rotate z angle.

texture rotate vector angle.

texture general point point point [point].

texture local - generate all the necessary texture transformations to access 
objects without considering their previously defined object transformations. 
The keyword invariant is also accepted. 

Example:

sphere
  transform scale 0.2 1 2
  transform rotate y ANGLE ; ANGLE is defined elsewhere
  texture local
  blotch 0.5 surface matte yellow
  surface matte red
  data 0 0 0 1

When generating animations, for example, it is important that textures stick 
to objects independently of their position, scale, etc or else it will 
produce a undesirable effect. If ANGLE varies from 5 to 30 degrees, the 
texture still applies correctly to the object and does not float strangely.
  
The available textures are:

Name		Parameters

checkers	surface   [transform]

blotch		scale   surface   [filename]   [transform]

bump		scale   [transform]

marble		[filename]   [transform]

fbm		offset   scale   omega   lambda   threshold   octaves   
		[transform]

fbmbump		offset   scale   lambda   octaves   [transform]

wood		color   [transform]

round		scale   [transform]

bozo		turbulence   [filename]   [transform]

ripples		frequency   phase   scale   [transform]

waves		frequency   phase   scale   [transform]

spotted		[filename]   [transform]

dents		scale   [transform]

agate		[filename]   [transform]

wrinkles	scale   [transform]

granite		[filename]   [transform]

gradient	turbulence   direction   [filename]   [transform]

imagemap	turbulence   mode   axis   filename   [transform]

gloss		scale   [transform]

bump3		scale   size   [transform]

Examples:

sphere round 0.5 data 0 0 0 0.5
sphere bump 0.7 scale 20 data 0 1 0 0.5 ; scale of bump is smaller
sphere bump3 0.5 0.5 scale 1 4 1 data 0 -1 0 0.5 ; strange!

4. Annex

To simplify the creation of scenes, it is sometimes a good idea to use a 
preprocessor to perform automatic text manipulation. Two good programs are 
cpp and m4, which are available in UNIX and DOS. Example taken from a 
scene representing a molecule:

#define dull mono 1 mono 0 0 0
#define shiny mono 0.8 mono 0.2 50 0.8

#define ATOM_O(x,y,z) \
sphere\
 surface 1 0 0 dull\
 data x y z 1.4

#define ATOM_C(x,y,z) \
sphere\
 surface 0 0.97 0.3 dull\
 data x y z 1.8

#define ATOM_N(x,y,z) \
sphere\
 surface 0 0 1 dull\
 data x y z 1.5

#define ATOM_P(x,y,z) \
sphere\
 surface 0.19 0.41 1 dull\
 data x y z 1.9

% Atoms
ATOM_O(35.815,45.746,7.218)
ATOM_C(35.906,47.181,7.388)
ATOM_P(35.309,46.286,11.717)
ATOM_N(31.936,45.793,7.469)
ATOM_C(34.643,47.649,8.077)
...

The main advantage of this technique is to simplify the creation of the 
scene and to make the resulting file a lot smaller. To trace this 
scene (suppose it is called demo.scn) the following commands can 
be used:

scn2sff C demo.scn | rtrace ...
orcpp demo.scn | scn2sff - | rtrace ...

Other auxiliary programs that produce SCN files are:

* sol2scn - a translator from AUTOCAD (versions 11 and 12) solid modeler 
(AME). Supports all AME primitives except chamfer and fillet.

* pdb2scn - a translator from PDB (Protein Data Bank) molecular files from 
BNL to SCN. 

Adapted from a program made by Doug Warner (Pittsburgh Supercomputing 
Center and Carnegie Mellon University).

* 3ds2scn - a translator from 3D STUDIO ASCII files to SCN. This program is 
an AWK  script.

* chem2scn - a translator from CHEMICAL (DOS chemistry program) to SCN. It 
is mainly an AWK script.

* irit2scn - a translator from IRIT data files to SCN. Adapted from a 
program made by Gershon Elber.

* mol2scn - a translator from ALCHEMY (DOS chemistry program) MOL files 
to SCN. It is also mainly an AWK script.

* tri2scn - a translator from Mike Carson's RIBBONS (molecular programs) TRI 
files to SCN. It is an AWK script.

* iv2scn - a translator from Silicon Graphics INVENTOR IV files to SCN. 
Some features not yet supported. It is mainly an AWK script.

There are other programs that translate directly to SFF instead of SCN. 
The most important is:

* nff2sff - a translator from Eric Haines NFF (Neutral File Format) to 
SFF. He also made a collection a test programs for renderers called SPD 
(Standard Procedural Database) that output in NFF.

SCN2SFF has also been ported to Macintosh by Reid Judd (preprocessor options 
not supported).

All these translators are available by anonymous ftp at asterix.inescn.pt 
[192.35.246.17] in directory pub/RTrace and subdirectories (also at 
wuarchive.wustl.edu and many other sites - find them with archie or xarchie).

It is also recommended the reading of SFF ray tracing format for knowing 
how RTRACE  handles the translated SFF scene. It contains also more 
detailed explanation of the text3d primitive and textures.

 exponentiation.
 remainder.
 Radians TO Degrees.
 Degrees TO Radians.

For more details about textures please read the SCN2SFF manual (scn2sff.man 
in UNIX).

AWK is a powerful pattern recognition language available for UNIX and DOS.

Also recommended is the reading of RTRACE manual (rtrace.man in UNIX).


----- end of SCN -----