-
Notifications
You must be signed in to change notification settings - Fork 0
Scenes
The parsing of the scene config files is done by the libconfig++ library.
This is an example of scene config file
# Configuration of the camera
camera :
{
# The resolution of the image
resolution = {
width = 1280;
height = 720;
};
# The number of ray per pixel
samples = 100;
# The position of the camera
look_from = {
x = 278.0;
y = 278.0;
z = -800.0;
};
# The point the camera is looking at
look_at = {
x = 278.0;
y = 278.0;
z = 0.0;
};
# The up vector of the camera
up = {
x = 0.0;
y = 1.0;
z = 0.0;
};
# The field of view of the camera
fieldOfView = 40.0; # In degree
# The aspect ratio of the camera
aspectRatio = {
width = 16.0;
height = 9.0;
};
# The aperture of the camera
aperture = 0.0;
# The distance to the focus point
diskToFocus = 10.0;
};
# Primitives in the scene
primitives :
{
# List of Primitives
# List of Rectangle
YZrectangle = (
{
y0 = 0.0;
y1 = 555.0;
z0 = 0.0;
z1 = 555.0;
k = 555.0;
material = {
name = "Lambertian";
color = {
r = 0.12;
g = 0.45;
b = 0.15;
};
};
},
{
y0 = 0.0;
y1 = 555.0;
z0 = 0.0;
z1 = 555.0;
k = 0.0;
material = {
name = "Lambertian";
texture = {
name = "solidColor";
color = {
r = 0.65;
g = 0.05;
b = 0.05;
};
};
};
}
);
XZrectangle = (
{
x0 = 213.0;
x1 = 343.0;
z0 = 227.0;
z1 = 332.0;
k = 554.0;
material = {
name = "diffuseLight";
color = {
r = 15.0;
g = 15.0;
b = 15.0;
};
};
transform = {
FlipFace = {};
};
},
{
x0 = 0.0;
x1 = 555.0;
z0 = 0.0;
z1 = 555.0;
k = 0.0;
material = {
name = "Lambertian";
texture = {
name = "solidColor";
color = {
r = 0.65;
g = 0.05;
b = 0.05;
};
};
};
},
{
x0 = 0.0;
x1 = 555.0;
z0 = 0.0;
z1 = 555.0;
k = 555.0;
material = {
name = "Lambertian";
color = {
r = 0.73;
g = 0.73;
b = 0.73;
};
};
}
);
XYrectangle = (
{
x0 = 0.0;
x1 = 555.0;
y0 = 0.0;
y1 = 555.0;
k = 555.0;
material = {
name = "Lambertian";
color = {
r = 0.73;
g = 0.73;
b = 0.73;
};
};
}
);
# List of cube
cube = (
{
p0 = {
x = 0.0;
y = 0.0;
z = 0.0;
};
p1 = {
x = 165.0;
y = 330.0;
z = 165.0;
};
material = {
name = "Metal";
color = {
r = 0.8;
g = 0.85;
b = 0.88;
};
fuzz = 0.0;
};
transform = {
rotate = {
degree = 15.0;
};
translate = {
x = 265.0;
y = 0.0;
z = 295.0;
};
};
}
);
spheres = (
{
x = 190;
y = 90;
z = 190;
r = 90;
material = {
name = "Dielectric";
refIdx = 1.5;
};
}
);
};
# List of Lights
lights :
{
ambient = 0.0; # Background color -> create a calcul
# List of PointLights
point = (
{
x = 190;
y = 90;
z = 190;
r = 90;
material = {
name = "none";
}
}, # Create a Sphere with a radius of 90 in default value and AMaterial() for material;
{
x = 213;
y = 343;
z = 227;
r = 90;
material = {
name = "none";
}
}
);
};
A line starting with # is a comment and will be ignored by the parser.
A section is defined by a name followed by a colon : and a block of data between curly braces {}. Example :
camera :
{
[...]
};{ width = 1920; height = 1080; } and not by a list of data [1920, 1080]. And width and height are integers, not floats.
If you do not respect the types, the parser will not be able to parse the file and will return an error.
The camera needs all of these parameters to be defined :
-
resolution: Resolution of the image to render (1920x1080 by default) -
look_from: Position of the camera -
look_at: Position where the camera is looking at -
up: Up vector of the camera -
fieldOfView: Field of view of the camera (72.0 by default) -
aspectRatio: Aspect ratio of the camera (16.0 / 9.0 by default) -
aperture: Aperture of the camera (0.0 by default) -
diskToFocus: Disk to focus of the camera (10.0 by default)
The primites section contains all the primitives of the scene.
This is the list of primitives that can be defined :
-
spheres: List of spheres -
planes: List of planes -
cylinders: List of cylinders -
cones: List of cones -
cubes: List of cubes -
limitedCylinders: List of limited cylinders -
limitedCones: List of limited cones -
XYrectangles: List of XY rectangles -
XZrectangles: List of XZ rectangles -
YZrectangles: List of YZ rectangles -
triangles: List of triangles
A sphere is defined by a position, a radius and a material.
spheres = (
{
x = 190;
y = 90;
z = 190;
r = 90;
material = {
name = Dielectric;
refIdx = 1.5;
};
}
);For the material part, refer to the materials section.
A plane is defined by an axis, a position, a color and a material.
planes = (
{
axis = "Z";
position = -20;
color = { r = 64; g = 64; b = 255; };
material = {
name = Lambertian;
albedo = { r = 0.5; g = 0.5; b = 0.5; };
};
}
);For the material part, refer to the materials section.
A cylinder is defined by a position, a radius, a color and a material.
cylinders = (
{
x = 190;
y = 90;
z = 190;
r = 90;
color = { r = 64; g = 64; b = 255; };
material = {
name = Lambertian;
albedo = { r = 0.5; g = 0.5; b = 0.5; };
};
}
);The Limited version is defined by the same parameters, plus a height.
limitedCylinders = (
{
x = 190;
y = 90;
z = 190;
r = 90;
height = 100;
color = { r = 64; g = 64; b = 255; };
material = {
name = Lambertian;
albedo = { r = 0.5; g = 0.5; b = 0.5; };
};
}
);For the material part, refer to the materials section.
A cone is defined by a position, a radius, a color and a material.
cones = (
{
x = 190;
y = 90;
z = 190;
r = 90;
color = { r = 64; g = 64; b = 255; };
material = {
name = Lambertian;
albedo = { r = 0.5; g = 0.5; b = 0.5; };
};
}
);The Limited version is defined by the same parameters, plus a height.
limitedCones = (
{
x = 190;
y = 90;
z = 190;
r = 90;
height = 100;
color = { r = 64; g = 64; b = 255; };
material = {
name = Lambertian;
albedo = { r = 0.5; g = 0.5; b = 0.5; };
};
}
);For the material part, refer to the materials section.
A cube is defined by a position, a size, a color and a material.
cube = (
{
p0 = {
x = 0.0;
y = 0.0;
z = 0.0;
};
p1 = {
x = 165.0;
y = 330.0;
z = 165.0;
};
material = {
name = "Metal";
color = {
r = 0.8;
g = 0.85;
b = 0.88;
};
fuzz = 0.0;
};
}
);We have 3 declinations of the cube :
-
cubes: A cube with all the faces -
XYrectangles: A rectangle in the XY plane -
XZrectangles: A rectangle in the XZ plane -
YZrectangles: A rectangle in the YZ plane
The YZ version is defined like this :
YZrectangle = (
{
y0 = 0.0;
y1 = 555.0;
z0 = 0.0;
z1 = 555.0;
k = 555.0;
material = {
name = "Lambertian";
color = {
r = 0.12;
g = 0.45;
b = 0.15;
};
};
}
);
The XZ version is defined like this :
```txt
XZrectangle = (
{
x0 = 213.0;
x1 = 343.0;
z0 = 227.0;
z1 = 332.0;
k = 554.0;
material = {
name = "diffuseLight";
color = {
r = 15.0;
g = 15.0;
b = 15.0;
};
};
}
);The XY version is defined like this :
XYrectangle = (
{
x0 = 0.0;
x1 = 555.0;
y0 = 0.0;
y1 = 555.0;
k = 555.0;
material = {
name = "Lambertian";
color = {
r = 0.73;
g = 0.73;
b = 0.73;
};
};
}
);For the material part, refer to the materials section.
A triangle is defined by 3 points and a material.
triangles = (
{
pa = {
x = 0.0;
y = 0.0;
z = 0.0;
};
pb = {
x = 165.0;
y = 330.0;
z = 165.0;
};
pc = {
x = 165.0;
y = 0.0;
z = 165.0;
};
material = {
name = "Metal";
color = {
r = 0.8;
g = 0.85;
b = 0.88;
};
fuzz = 0.0;
};
}
);The lights section contains all the lights of the scene.
This is the list of lights that can be defined :
-
ambient: Ambient light -
diffuse: Diffuse light -
point: Point light -
directional: Directional light
The ambient light is defined by a value between 0.0 and 1.0.
ambient = 0.4;The diffuse light is defined by a value between 0.0 and 1.0.
diffuse = 0.6;The point light is defined by a position, a radius and a material.
point = (
{ x = 400; y = 100; z = 500; r = 100; material = { name = "none"; }; }
);The directional light is defined by a direction and a material, a radius and a material.
directional = (
{ x = 400; y = 100; z = 500; r = 100; material = { name = "none"; }; }
);This is the list of materials that can be defined :
-
Lambertian: Lambertian material -
Metal: Metal material -
Dielectric: Dielectric material -
diffuseLight: Diffuse light material
The Lambertian material is defined by an color.
material = {
name = Lambertian;
color = { r = 0.5; g = 0.5; b = 0.5; };
};The Metal material is defined by an color and a fuzz.
material = {
name = Metal;
color = { r = 0.5; g = 0.5; b = 0.5; };
fuzz = 0.0;
};The Dielectric material is defined by a refraction index.
material = {
name = Dielectric;
refIdx = 1.5;
};The Diffuse light material is defined by a color.
material = {
name = diffuseLight;
color = { r = 0.5; g = 0.5; b = 0.5; };
};You can apply transformations to the primitives.
This is the list of transformations that can be applied :
-
translate: Translate the primitive -
rotate: Rotate the primitive -
scale: Scale the primitive
The translate transformation is defined by a vector.
translate = {
x = 0.0;
y = 0.0;
z = 0.0;
};The rotate transformation is defined by a vector.
rotate = {
x = 0.0;
y = 0.0;
z = 0.0;
};The scale transformation is defined by a vector.
scale = {
x = 0.0;
y = 0.0;
z = 0.0;
};