Syntax of the .ray File Format
For this project we define a rudimentary scene graph language.
Each command begins with a "#"-sign and goes on until the next command or until the end of the file is reached.
Commands may extend across new-line characters.
All color values are floating point values between 0.0 and 1.0, and all other numeric expressions are assumed to be floating point, unless otherwise noted.
Angles are given in radians.
If "//" characters are read, the remainder of the line is ignored.
The ray file consists of three parts:
- Global data: specifies information shared across the scene (cameras, lights, shaders)
- Local data: specifies information specific to the current .ray file (textures, materials, included .ray files, key-frame files, vertices)
- Shapes: specifies the shapes to be rendered (triangle, box, cone, cylinder, sphere, torus, ray-file instance, list of shapes, list of triangles, affinely deformed shapes, the union of a set of shapes, the intersection of a set of shapes, the difference between two shapes).
Within each part, individual commands can appear in order.
In order to define triangles you must first define the vertices you will use and then index them in the triangle definition.
- Global Data:
-
#camera px py pz dx dy dz ux uy uz ha
-
This defines a perspective camera in the scene.
(px,py,pz) is the position of the camera in world coordinates.
(dx,dy,dz) is a vector describing the viewing direction of the camera.
(ux,uy,uz) is a vector describing the up direction of the camera.
ha is the height angle of the viewing frustum.
If multiple camera commands are specified, the last one will be used.
-
#shader vertexShaderName fragmentShaderName
-
Sets the vertex and fragment shaders used for rendering the scene.
vertexShaderName is the name of the vertex shader file, with extension .vs
or .vert
.
fragmentShaderName is the name of the fragment shader file, with extension .fs
or .frag
.
If multiple shader commands are specified, the last one will be used.
-
#light_point ar ag ab dr dg db sr sg sb px py pz ca la qa
-
This defines a point light in the scene.
(ar,ag,ab) is the ambient color of the light.
(dr,dg,db) is the diffuse color of the light.
(sr,sg,sb) is the specular color of the light.
(px,py,pz) is the position of the light in world coordinates.
ca, la, and qa give the constant, linear, and quadratic components of the attenuation factor.
If d is the distance from the light to the surface, then the light's color at the surface is given by (r,g,b)*1.0/ (ca + la*d + qa*d*d).
-
#light_spot ar ag ab dr dg db sr sg sb px py pz dx dy dz ca la qa sc sd
-
This defines a spot light in the scene.
(ar,ag,ab) is the ambient color of the light.
(dr,dg,db) is the diffuse color of the light.
(sr,sg,sb) is the specular color of the light.
(px,py,pz) is the position of the light in world coordinates.
ca, la, and qa are the constant, linear, and quadratic components of the attenuation factor.
If d is the distance from the light to the surface, then the light's color at the surface is given by (r,g,b)*1.0/ (ca + la*d + qa*d*d).
cs is the half angle of divergence of the light cone. It can be measured as the angle from the center axis to the edge of the spot cone.
It should be less than pi/2 radians.
sd is the spot drop-off factor. It can take values from 0.0 to 128.0, where 0.0 indicated constant intensity across the cone, and 128.0 yields a sharp fall-off.
The cosine of the angle between light direction and the direction of a ray from (px,py,pz) to the point being lit, raised to the power of sd will yield the correct result.
-
#light_dir ar ag ab dr dg db sr sg sb dx dy dz
-
This defines a directional light in the scene.
(ar,ag,ab) is the ambient color of the light.
(dr,dg,db) is the diffuse color of the light.
(sr,sg,sb) is the specular color of the light.
(dx,dy,dz) is athe direction of the light in the scene.
-
#light_sphere ar ag ab dr dg db sr sg sb px py pz r ca la qa
-
This defines a spherical point light in the scene.
(ar,ag,ab) is the ambient color of the light.
(dr,dg,db) is the diffuse color of the light.
(sr,sg,sb) is the specular color of the light.
(px,py,pz) is the position of the light in world coordinates.
r is the radius of the light.
ca, la, and qa give the constant, linear, and quadratic components of the attenuation factor.
If d is the distance from the light to the surface, then the light's color at the surface is given by (r,g,b)*1.0/ (ca + la*d + qa*d*d).
- Local Data:
-
#texture filename
-
This defines a texture in the current file.
filename is the name of the file containing the texture.
The first texture declared will take the interger identifier 0, and subsequent textures will follow in order (i.e. 1, 2, 3, ...).
This integer handle is used in material definitions to indicate that the material includes the respective texture.
-
#material er eg eb ar ag ab dr dg db sr sg sb sfo tr tg tb ir tn !string!
-
This defines a material in the current file.
(er,eg,eb) is the emissive color of the material.
(ar,ag,ab) is the ambient color of the material.
(dr,dg,db) is the diffuse color of the material.
(sr,sg,sb) is the specular color of the material.
sfo is the specular 'shininess' (or 'fall-off') of the material, taking values from 0.0 to 128.0.
(tr,tg,tb) is the transparent color of the material.
ir is the index of refraction.
tn is the texture index (or -1 if no texture is associated with the material).
!string! is an exclamation mark delimited string allowing for specification of other functionality. string must be a single word (i.e. contain no white-spaces) and can be empty.
The first material declared will take the interger identifier 0, and subsequent materials will follow in order (i.e. 1, 2, 3, ...).
This integer handle is used in Shape definitions to indicate that the rendering should occur with the appropriate material.
-
#ray_file fileName
-
This defines a .ray file to be included within the scene.
fileName is the name of the .ray file.
The first ray_file declared will take the identifier 0, and subsequent ray_files will follow in order (i.e. 1,2,3, ...)
If the .ray file contains global data (e.g. cameras, shaders, or lights) those will be ignored.
-
#vertex px py pz nx ny nz ts tt
-
This defines a verex in the scene
(px,py,pz) is the position of the vertex.
(nx,ny,nz) is the normal of the vertex.
(ts,tt) is the texture coordinate of the vertex
The first vertex declared will take the interger identifier 0, and subsequent vertices will follow in order (i.e. 1, 2, 3, ...).
-
#key_file fileName
-
This defines a key-frame file to be used to define animations within the scene.
fileName is the name of the key-frame file.
If multiple key_file commands are specified, the last one will be used.
- Shapes:
-
#shape_triangle i1 i2 i3
-
This defines a triangle.
(i1,i2,i3) are the vertex indices defining the triangle.
This can only be declared within a shape_list associated to a shape_triangles.
-
#shape_box m cx cy cz lx ly lz
-
This defines an axis aligned box.
m is the index of the material associated with the shape_box
(cx,cy,cz) is the center of the box.
(lx,ly,lz) are the lengths of the box.
-
#shape_cone m cx cy cz r h
-
This defines a cone, with a central axis parallel to the y-axis, opening at the bottom and closing at the top.
m is the index of the material associated with the shape_cone
(cx,cy,cz) is the center of the cone.
r and h are the radius and height of the cone, respectively.
The cone is a closed surface (i.e. it's base is capped).
-
#shape_cylinder m cx cy cz r h
-
This defines a cylinder, with a central axis parallel to the y-axis.
m is the index of the material associated with the shape_cylinder
(cx,cy,cz) is the center of the cylinder.
r and h are the radius and height of the cylinder, respectively.
The cylinder is a closed surface (i.e. it has end caps.)
-
#shape_sphere m cx cy cz r
-
This defines a sphere.
m is the index of the material associated with the shape_sphere
(cx,cy,cz) is the center of the sphere.
r is the radius of the sphere.
-
#shape_torus m cx cy cz ir or
-
This defines a torus which is axially symmetric about the y-axis.
m is the index of the material associated with the shape_torus
(cx,cy,cz) is the center of the torus.
ir is the inner radius of the torus.
or is the outer radius of the torus.
-
#ray_file_instance n
-
This specifies an instance of a ray_file to be included in the scene.
n is the index of the ray_file.
-
#shape_list_begin
shape1 ...shapeN
#shape_list_end
-
These pair of commands enclose a list of shapes.
shape1...shapeN are the shapes in the list.
-
#shape_triangles m
shapeList
-
This specifies a list of triangles.
m is the index of the material associated with the shape_triangles
shapeList is the shape_list of triangles.
-
#static_affine m11 m21 m31 m41 m12 m22 m32 m42 m13 m23 m33 m43 m14 m24 m34 m44
shape
-
This specifies a shape to which a static affine transformation is applied
(m11,m21,m31,m41) is the first column of the transformation matrix.
(m12,m22,m32,m42) is the second column of the transformation matrix.
(m13,m23,m33,m43) is the third column of the transformation matrix.
(m14,m24,m34,m44) is the fourth column of the transformation matrix.
shape is the shape that is transformed.
-
#dynamic_affine parameterName
shape
-
This specifies a shape to which a dynamic affine transformation is applied
parameterName is the name of the dynamic parameter associated with the transformation.
shape is the shape that is transformed.
-
#shape_union
shapeList
-
This specifies the union of a set of shapes.
shapeList is the shape_list of shapes in the union.
-
#shape_intersection
shapeList
-
This specifies the intersection of a set of shapes.
shapeList is the shape_list of shapes in the intersection.
-
#shape_differences
shape1 shape2
-
This specifies the difference between two shapes (i.e. the set of points contained in the first shape but not in the second).
shape1 the first shape.
shape2 the second shape.