To give your objects colour you use materials.
Material(MaterialComponent *comp1, [MaterialComponent *comp2,] ...);A Material is made up of any number of components: diffuse, specular, transmitted, phong and emissive. A MaterialComponent can be any of of the following
DiffuseComponent(double r, double g, double b, double a = 0); DiffuseComponent(double r, double g, double b, double er, double eg, double eb, double a = 0); SpecTransComponent(double n, double rs, double gs, double bs, double rt, double gt, double bt); SpecTransComponent(double n, double rs, double gs, double bs, double ers, double egs, double ebs, double as, double rt, double gt, double bt, double ert, double egt, double ebt, double a); PhongComponent(double power, double er, double eg, double eb); PhongComponent(double power, double r, double g, double b, double er, double eg, double eb, double a); EmissiveComponent(double er, double eg, double eb, double a = 0); EmissiveComponent(double r, double g, double b, double er, double eg, double eb, double a = 0);Key: r = red, g = green, b = blue, a = alpha, e = emissive, t = trasmitted, n = refractive index
When a ray hits the object, all four colours contribute to the returned colour of the object.
The colours stored by the MaterialComponent structure use the RGB colour model. Each colour is defined by three doubles which specify the amounts of red, green and blue with a number between 0 to 1.
The diffuse colour is multiplied by the colour of each light on the object. In white light this produces the diffuse colour but in red light, for example, magenta objects appear red as there is no blue component in the light to reflect.
The specular colour is multiplied by the colour returned from the ray cast in the direction of mirror reflection. If the object is not reflective then this should be set to black. If the object is a perfect mirror then this should be set to white.
The transmitted colour is multiplied by the colour returned from the ray transmitted through the object. If the object is opaque then this should be set to black.
The phong colour is used to model shiny surfaces. Shiny surfaces do not reflect light evenly in all directions. More light is reflected in the direction of mirror reflection. This produces a highlight on curved surfaces. An apple is a good example of an object with a strong phong highlight. The phong highlight colour should be a combination of the diffuse colour, the specular colour and white but just white gives a reasonable approximation. For dull surfaces with no highlight just set the phong colour to black and the phong power to 0.
The phong power determines the size of the highlight. The larger the number the smaller the highlight. A phong power of 3.0 gives a large, soft highlight and 30.0 gives a small, sharp highlight.
The refractive index determines how much light bends when it is transmitted through the object. The greater the refractive index the more light bends in the object. The refractive index for air is 1.0, water is 1.3 and glass is 1.5.
Example: Define a red material
Material *red = new Material(new DiffuseComponent(1.00, 0.00, 0.00));Example: Define a myown material and set make a pipe object that uses it.
Material *myMat = new Material(new DiffuseComponent(0.2, 0.2, 0.4), new SpecTransComponent(7.5, 0.7, 0.7, 0.7, 0, 0, 0), new PhongComponent(3, 1, 1, 1)); object pipe = make_pipe(); pipe->material = myMat;
In the above section of code, the 'myMat' material is given a diffuse colour of 0.2, 0.2, 0.4, dark bluey-grey.
A specular colour of 0.7, 0.7, 0.7, quite shiny.
And no transparency (0, 0, 0), i.e. can't see through it. A refractive index of 7.5 (although not used).
The phong highlight colour is white (1.0, 1.0, 1.0) and the Phong power is 3.0.
There are several predefined materials in Mirage:
black, dkgrey, grey, ltgrey, white, ltred, ltgreen, ltblue, red, green, blue, dkred, dkgreen, dkblue, magenta, cyan, yellow, lavender, purple, orange, ltbrown, brown, dkbrown, terracotta, transp, perspex, glass, clear, mirror, gold, silver, china.
These are used with the command
the_object->material = ltgreen;