RoughRay Help Contents
The user interface for RoughRay is simple yet usable. You load, save and edit text files as you would in any
other application. The .RRY scripts describe a 3 dimensional scene
which is then drawn on the desktop.
- Animation describes how to trace multiple images and create a video.
- Tracer contains the width, height and ray options.
- Scene contains all the lights camera and geometry.
- Camera describes the camera's configuration.
- Light describes a light source.
- Frame wraps shapes into heirarchies or bone structures.
- Unit Objects are the building blocks of geometry.
- Cube describes a box.
- Plane creates a ground or wall.
- Sphere represents a globe.
- Cylinder describes a pipe.
- Cone describes a two directional cone.
- Paraboloid is a parabola rotated about Y.
- Hyperboloid is a hyperbola rotate about Y.
- Quadric creates a warpable curve from coefficients.
- CSG Objects are shapes created by adding and subtracting other shapes.
- Union takes a logical OR of two shapes.
- Intersection takes a logical AND of two shapes.
- Difference takes a logical NOT between two shapes.
- Misc. Objects are shapes not easily catagorized.
- Mesh creates a shape from a series of triangle faces.
- Surface of Revolution creates a shape from a series of 2D vectors.
- Height_Map creates a shape from external data provided in an image format.
- Random_Map creates a shape from random data.
- Cosine creates a shape from a cosine wave.
- Includes and Defines allow reuse of text.
- Define marks text for later use.
- Include inserts the specified text as if it were pasted.
- Functions and Interpolations return a floating point decimal.
- Interpolation returns a value calculated from a list.
- Functions return values calculated from math routines.
- Loops make it possible to programatically create objects.
.RRY Script
RoughRay saves text files with a .RRY extension. The script
is parsed into tokens without regard to case. Tokens are delimitted by white space which includes 'space', 'tab',
'comma', '{' and carriage return. No white space is allowed within tokens or names. An underscore is used to seperate
words in tokens. File names
must be in "double quotes". Single line comments are denoted by beginning the comment with a semi-colon. Multi-line
comments are enclosed in brackets. The script is seperated into logical blocks that are started with the name of the block
and ended with "end_NameOfBlock" or " }". These blocks are described below. These blocks contain members, most of which have
default values and can be excluded. An outline of a script looks like this:
() are used to denote optional blocks.
(;a comment about the file including the author and what the heck it is supposed to look like!)
(animation ... end_animation)
(tracer ... end_tracer)
(define ... end define) ;reusable objects defined here
(interpolation ... end_interpolation) ;lists of named values that change over time for animation
scene
camera ... end_camera
light ... end_light
(loop ...
(frame
(camera ... end_camera) ;there can only be one camera but it may be placed within a frame
(light ... end light) ;there can be many lights - slows rendering
(intersection
(cube
(rotate translate scale)
(material ... end_material)
(end_cube)
(sphere ... end sphere)
end_intersection)
end_frame)
end_loop)
end_scene
3 Dimensional Space
3 dimensional space is represented by x,y,z coordinates. Depending on the positioning of the camera these coordinates are
interchangeable. With a Camera at 0,0,2 looking at a screen at 0,0,1 the dimensions equal x=right, y=up, z=forward.
You position objects by declaring a Matrix included in a Frame or by using the Rotate,
Scale and Translate fields of an object.
Translate x,y,z specifies a positioning in space.
Scale x,y,z specifies a scaling in width, height and depth with 1 equalling no scaling.
Rotate x,y,z specifies a pitch, yaw and roll in radians.
Each matrix operation is performed as a child of the last. Rotating and then translating means the translation will be rotated.
Animation
Animations string together multiple images into a video file. To animate geometry you use
Interpolation and Functions of time.
Parent: Root of Document
- Frames (integer) specifies the total number of images to draw and add as frames into the video.
- Frames_Per_Second (integer) specifies the speed of playback.
- Output_File ("quoted string") a complete absolute or relative .AVI file specification.
- Start_Time (float) The start time for interpolations.
- End_Time (float) The end time for interpolations.
Camera
The camera describes how rays are cast into the scene. They originate from the camera's translation
and pass through each point of the screen. If they bounce off an object they are illuminated by the light
reaching that object.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis. The Z-axis represents the screen center.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Look_At (vector3) specifies the point to look at.
Cone
Imagine x=y rotated about the y axis. That's a cone. It is a basic shape located at the origin so it
uses it's own matrix for positioning.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Constructive Solid Geometry
CSG is used to build complex objects from simple ones. These are implemented by testing whether
a ray intersects a parent and a child object and then performing a logical operation on these boolean values.
Even though each CSG only operates on two objects the parent and child can also be CSG objects with "unlimited"
nesting. The implementation currently only holds the first entrance and last exit points of the ray as it passing through the
object. Concave CSG objects with transparency will not properly display child objects inside of them.
Efforts have been made to make single sided objects like a plane useful in CSG by creating an "infinite" back face.
This implementation may cause unexpected results.
Cube
Cube specifies a 2x2x2 box about the origin.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Cylinder
Cylinder specifies a one unit tall capped cylinder.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Cosine
Cosine graphs the function y=cos(r) where r is the distance from the origin.
Parent: Scene or Frame
- Phase (float) specifies an angle to add to r. 1.57 will result in a sine wave.
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Define
Define can be used to reduce the amount of typing and text stored. If an object will be reused
wrap it inside a define then use Include to paste the text into the Scene.
You can only use Define for storing objects not object members ie. float values.
Parent: Root of Document, Scene or Frame
- Name (unique token) is used to recall the define.
- Everything after this token up to end_define will be the script pasted on include.
Notes: You must end the define with "end_define" not "}". The shorthand is disabled for obvious reasons. Hence you
cannot nest Defines. The script is inserted just prior to parsing with no regard as to the context of the Define. For example
a sphere defined in one Frame but used in another will be effected by the later.
Difference
Difference is a Constructive Solid Geometry object created from the logical NOT of two objects.
Think of it as the subtraction of the second object from the first. Not associative!
- Material specifies a material or "look" of the object.
- Parent Object (object) specifies the left hand argument.
- Child Object (object) specifies the right hand argument.
Note: The material definition must come before the parent and child to be useful. Otherwise if the parent or child do not
contain their own material definition they will inherit the last material defined.
Everywhere
Everywhere is an object that incompasses all the space. It is only of value as the parent in the Difference
CSG object. It results in the inverse of the child object.
Parent: Difference
There are no fields to specify with this object.
Example: Creating a sky dome.
difference
everywhere { }
sphere { scale 100,100,100 }
end_difference
Frame
A Frame is used to connect objects in a Parent, Child relationship and to group objects into more complex structures
with joints. The Frame holds a single Matrix, multiple objects and child frames.
Parent: Scene or Frame
- Matrix (vector16) holds the frames spacial positioning.
- Bounding_Shape (object) improves performance by first checking hits on this object.
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
- Child Object and Siblings can include CSG or simple objects.
- Frame...End_Frame specifies a child frame. Think of the wrist moving with the forearm.
Functions
A fair number of intrinsic functions are defined for use in place of float values. These include:
Function | Meaning | Arguments |
add | Addition | 2 |
sub | Subtraction | 2 |
mul | Multiplication | 2 |
div | Division | 2 |
flr | Floor (next integer lower) | 1 |
clg | Ceiling (next integer higher) | 1 |
max | Maximum | 2 |
min | Minimum | 2 |
abs | Absolute (remove sign) | 1 |
mod | Modulation (remainder as integer) | 2 |
pow | Value raised to Power | 2 |
log | Logarithm | 1 |
exp | Exponent | 1 |
sin | Sine | 1 |
cos | Cosine | 1 |
tan | Tangent | 1 |
asn | Arcsine | 1 |
acs | Arcosine | 1 |
atn | Arctangent | 2 |
rnd | Random | 0 |
equ | Equals | 2 |
gt | Greater Than | 2 |
lt | Less Than | 2 |
neq | Not Equal | 2 |
ife | If Equal Else | 3 |
and | Logical And | 2 |
or | Logical Or | 2 |
not | Logical Not | 1 |
time | Time as indicated in Animation | 0 |
---|
No parenthesis are used. Calculation is always performed right to left. Use these functions to manipulate
float values based on the time value in Animations, Interpolated values (also based
on time) and in Loop statements to compare and use the counter value.
Example: Positioning an object based on the division of time by the larger of the Sine and Cosine of time.
Cube
Translate 0,0,div time, max sin time, cos time
End_Cube
We need not worry about division by zero as a replacement small value will be used.
Height_Map
A height map uses a Bitmap picture file (.bmp) with color intensities representing heights. The mapping function looks like this:
x=px/pwidth-0.5,y=colorrgb/maxrgb,z=py/pheight-0.5
This returns a unit cube centered at the origin with its top shaped to the color intensities.
- File (double quoted string) the complete file specification.
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Hyperboloid
The Hyperboloid is a hyperbola rotated around y.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Include
Include is used to insert text from another file or a previous Define. This text is then
parsed as if it were typed at the position of the include statement.
- Name (unique token) The text is held in a previous Define.
- File The text is held in a seperate file.
Note: Use either Name or File, not both. Parsing errors in the inserted text will not be selected.
Interpolation
Interpolation creates a sliding scale of values used in Animation.
The values are given in vector2 pairs. The first value is the animation time determined by the formula:
start_time + current_frame*(end_time-start_time)/total_frames
The second value is a float. When the parser sees the name of the interpolation where a float should be
it substitutes a value calculated from the interpolation list.
- Name (unique token) this name will be used later in place of a float value.
- Time,Value Pair (vector2) the time and value.
- ... more pairs
Example: If you want an object to move through the scene during an animation you could use...
interpolation
name interp01
0.0 -10.0
1.0 10.0
end_interpolation
cone translate interp01,0,0 end_cone
Intersection
Intersection is a Constructive Solid Geometry object created from the logical AND of two objects.
The resultant object will contain only the portion included in both objects.
- Material specifies a material or "look" of the object.
- Parent Object (object) specifies the left hand argument.
- Child Object (object) specified the right hand argument. Interchangeable for intersection. Associative.
Note: The material definition must come before the parent and child to be useful. Otherwise if the parent or child do not
contain their own material definition they will inherit the last material defined.
Light
Any number of lights are permitted to illuminate the Scene.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the light source.
- Color (vector3) is the Red, Green, Blue color of the light.
- Strength (float) determines how far the light travels before fading.
Loop
Loops allow for programatically creating objects. You give the loop a name which becomes a loop counter starting
at zero. It then performs a logical test with a function of that value and repeats the body of the loop until the
test fails.
Parent: Scene
- Name (unique string) specifies the name of the loop counter.
Example: Creating a horizontal row of 10 spheres
loop my_loop
lt my_loop, 10
sphere { translate my_loop,0,0 }
end_loop
Material
A Material gives an object a certain "look". It may optionally include a Texture file which will be stretched over the object.
When an object is specified without a material the last material parsed will be used. A default White material is pre-loaded
into the parser.
Parent: Object, Frame or Scene
- Name (unique token) allows reusing the material which is important with texture files.
- Diffuse (vector3) the Red, Green and Blue components of the base color.
- Transparency (float) the amount of transparency.
- Inner_Transparency_Depth (float) how deep into the object light gets before being diffused.
- Gloss (float) the amount of polish when highlighting.
- Reflection (float) the amount of light reflected off the surface of the object.
- Refraction (float) the amount of bend when light travels through an object.
- Density (float) the number of times the texture is repeated over one unit. Default 1.0
- Texture_File (double quoted string) complete path and file name. Must be a bitmap .bmp file.
Example: If you want to reuse a material with texture name it and then recall the name.
material name test
texture_file "c:/test.bmp"
end_material
cube
material diffuse 1,0,0 end_material
end_cube
sphere
position 1,0,0
material name test end_material
end sphere
Matrix
Matrix math is used to position the objects in 3d space. Luckily you don't need to do the calulations
yourself. You can use the Translate, Scale and Rotate fields of an object or frame. You may also explicitly define the matrix
in a Frame. A matrix is a 4x4 grid that holds all the information for determining the size, orientation and position of an object.
Here is how a matrix is put together:
Right.x*Scale.x | Up.x | -Forward.x | 0 |
Right.y | Up.y*Scale.y | -Forward.y | 0 |
Right.z | Up.z | -Forward.z*Scale.z | 0 |
Translate.x | Translate.y | Translate.z | 0 |
It may look complicated but if you leave scaling out and picture Right, Up and Forward as normal vectors determining the
directions of x,y and z respectively it isn't to difficult to create one yourself.
Example: Say you want to deform an object by pulling the dimension Right towards the dimension Up and move it up.
frame
matrix
1-time | 0 | 0 | 0 |
time | 1 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | time | 0 | 1 |
cube end_cube
end_frame
Mesh
A Mesh is a series of triangle faces used to approximate a complex surface. Each triangle is described by three vertices.
Each vertice consists of a position vector, normal vector and a texture coordinate. The normal vector is used when lighting and reflecting
off the surface. It is a vector with length equal to 1 perpendicular to the surface. The texture coordinate is used with
Materials that have a texture file specified. It describes how the texture is mapped to the triangle.
The texture coordinate 0,0 means the upper left hand pixel will be used.
Parent: Scene or Frame
- Name (unique token) a mesh can be reused by supplying the name of a previously specified mesh.
- Material specifies a material or "look" of the object.
- Vertex_List (vector3, vector3, vector2) the position, normal and texture coordinate.
- ... continue to list the vertices in groups of three for each face in the mesh.
- End_Vertex_List to signal the end of the list.
Paraboloid
The Paraboloid is a parabola rotated around y.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Plane
Plane specifies a flat horizontal surface with y=0. Use the Matrix manipulating fields to reorient
the default ground plane into a wall etc.
Parent: Scene or Frame
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Quadric
Quadric specifies a curved shape generated from an expression in the form:
ax^2+by^2+cz^2+dxy+exz+fyz+gx+hy+iz+j=0
Parent: Scene or Frame
- Coefficients (vector10) the a,b,c,d,e,f,g,h,i and j constants in the expression above.
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Example: Say you want to create a unit sphere that distorts diagonally through xy. The formula for a sphere is
x^2+y^2+z^2-r^2=0. To change the radius (r) we change the coefficient j. To position the sphere we change the
coefficients g,h and i. To distort it over a plane we change d,e and f. The coefficients a,b and c change the
direction of the curve.
quadric
cooefficients 1,1,1,time,0,0,0,0,0,-1
end_quadric
Scene
The Scene holds the camera, all the lights and geometry to be traced. It also holds a few key properties...
Parent:Root of Document
- Background_Color (vector3) If no objects are hits this is the color displayed.
- Ambience (float) If no lights hit an object this determines how much ambient light illuminates it.
- Fog_Depth (float) The depth into the scene where no light can reach and the background color is returned.
- Camera The scene must have a camera.
- Light(s) illuminate the scene.
- Frame(s) group objects together.
- Define(s) pre-define text for later use.
- Include(s) insert predefined text from this or another file.
- Loop(s) allow for programatically creating objects.
- Geometric Objects in any number.
Surface of Revolution
The SOR is a list of 2D vectors whose x,y coordinates draw the outline of a curve that will be rotated about y.
Parent: Scene, Frame
- Type (unquoted string "linear" or "catmull") specifies the type of curve to draw.
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Sphere
The Sphere is a circle rotated around y.
Parent: Scene, Frame or CSG
- Translate (vector3) specifies the position of the object.
- Scale (vector3) specifies shape distortion in size for each axis.
- Rotate (vector3) specifies the pitch, yaw and roll.
- Material specifies a material or "look" of the object.
Tracer
The Tracer holds commands for the trace engine about how to create the image(s).
Parent:Root of Document
- Width (integer) The width of the resultant image in pixels.
- Height (integer) The height of the image in pixels.
- Max_Depth (integer) The depth of recursion allowed when bouncing rays off or through objects.
- Antialiasing (integer) The number of extra pixels to average into the image to remove artifacts.
- No_Diffuse Indicates no diffuse coloring.
- No_Highlights Do not perform phong highlighting.
- No_Shadows Do not create shadows.
- No_Reflection Do not reflect light off objects.
- No_Refraction Do not refract light through objects.
Union
Union is a Constructive Solid Geometry object created from the logical OR of two objects.
Think of it as the addition of the second object to the first. Associative!
- Material specifies a material or "look" of the object.
- Parent Object (object) specifies the left hand argument.
- Child Object (object) specifies the right hand argument.
Note: The material definition must come before the parent and child to be useful. Otherwise if the parent or child do not
contain their own material definition they will inherit the last material defined.
Tutorial
Let's walk through the features of RoughRay by starting with a minimal Scene. Every
Script needs a Scene element to encompass all the geometry and we will need at least one object
if we want anything to be drawn.
scene
cone { translate 0,0,3 }
end_scene
Copy the text above into the text area of RoughRay and click Play. You should see a flat looking cone drawn. Not too impressive
yet. We need to add a light to get a 3-Dimensional feel.
scene
light { translate 10,0,10 color 1,1,1 strength 100 } ;the new line
cone { translate 0,0,3 }
end_scene
Before we go too far we should define our camera. There can only be one camera and so far we have just used the default.
If you declare multiple cameras only the last one will be used. We will move the camera away from the origin and place our
object at the origin.
scene
camera { translate 0,0,2 look_at 0,0,0 } ;the new line
light { translate 10,0,10 color 1,1,1 strength 100 }
cone { }
end_scene
Our scene is still not very interesting. We will put in a couple more objects to see shadows and reflections form.
scene
camera { translate 0,0,2 look_at 0,0,0 }
light { translate 10,10,10 color 1,1,1 strength 100 }
cone { }
plane { translate 0,-1,0 material { diffuse 0,1,0 } } ;a new line, some green grass
sphere { translate 1,0,-1 material { reflection 1 } } ;a new line, a chrome ball
end_scene
You will see in the shadows that some pixels appear rough. That is called aliasing. We can tell the ray tracer to add
antialiasing and change the size of the image by putting in a Tracer section.
tracer
antialiasing 8 ;how many times to recalculate each pixel (add jitter and average)
max_depth 10 ;how many reflections and refractions are allowed
width 512
height 512
end_tracer
scene ;... this would be the same as the text above
Now lets change some positions and try refraction (the way light bends as it passes through an object).
scene
camera { translate 0,0,3 look_at 0,0,0 } ;we moved the camera back
light { translate 10,10,10 color 1,1,1 strength 100 }
cone { }
plane { translate 0,-1,0 material { diffuse 0,1,0 } }
sphere { translate 0.5,0,1 material { transparency 1.0 refraction 0.6 } } ;we move the sphere in front and made it transparent
end_scene