2.4. Objects

2.4.1. Common features Bounding used in inside tests

Micha Riser

With MegaPOV, in every test using Inside of objects the bounding object has now priority. It first tests if the point is inside the bounding. If it is not then it knows that it can already decide that the point is outside (if the object is not inversed) or that the point is inside (if the object is inversed).

This should increase rendering speed of complicated CSG objects, since it could eliminate a lot of computing steps. The inside test is firstly done for the bounding object. Only when this test is inside the bounding, the tests against each of the objects composing the CSG object will be done.

2.4.2. Text Text enhancements

Yvo & René Smellenbergh

Based on the text enhancement idea of Jamis Buck and Noel Bundy, but modified and extended.

Syntax is:

text {
  the usual text stuff
  [ h_align_left | h_align_center | h_align_right ]
  [ v_align_top | v_align_center | v_align_bottom ]

h_align_left By adding this keyword to the text block, the text string (including horizontal offset) is aligned horizontally so that its most left point touches the y-axis. This is identical to the default alignment.

h_align_center By adding this keyword to the text block, the text string (including horizontal offset) is aligned horizontally so that it extends equally on both sides of the y-axis.

h_align_right By adding this keyword to the text block, the text string (including horizontal offset) is aligned horizontally so that its most right point touches the y-axis.

v_align_top By adding this keyword to the text block, the text string (including vertical offset) is aligned vertically so that its highest point touches the x-axis.

v_align_center By adding this keyword to the text block, the text string (including vertical offset) is aligned vertically so that its middle height sits on the x-axis.

v_align_bottom By adding this keyword to the text block, the text string (including vertical offset) is aligned vertically so that its lowest point sits on the x-axis.


When no alignment is specified, the POV-Ray™ defaults are used. Horizontally to the left and vertically on the base line.

The old keyword "position" of previous MegaPOV versions is no longer supported.

2.4.3. Cloth simulation

Christophe Bouffartigue

simcloth allows to simulate cloth in MegaPOV. The cloth patch is rectangular, and interacts with its environment (gravity, some obstructing objects, wind, ...).

Syntax is:

  simcloth {
    [ environment OBJECT-IDENTIFIER ]
    [ friction FLOAT ]
    [ gravity VECTOR ]
    [ wind { PIGMENT } ]
    [ viscosity FLOAT ]
    [ neighbors 0 | 1 ]
    [ internal_collision on | off ]
    [ damping FLOAT ]
    [ intervals FLOAT ]
    [ iterations INTEGER ]
    input STRING
    [ output STRING ]
    [ mesh_output STRING ]
    [ smooth_mesh on | off ]
    [ uv_mesh on | off ]

environment is followed by an object identifier. The object should be declared before simcloth {}. This object defines the environment that will interact with the cloth. Although any object can be used, it is recommended to use objects which have well-defined interiors.

friction is a coefficient specifying energy loss when the cloth touches the environment. A low value (<= 0) means a lot of friction and strongly slows the movement of the cloth. A high value (>= 1) will allow the cloth to slide over the objects (but not to bounce off ...). Default value is 1.0

gravity Specifies the direction and the strength of gravity. The default value is <0, 0, 0>.

wind A pigment is used to define the direction and strength of the wind in every space location. At a given point, the wind is defined by the red, green and blue components of the pigment at this point. You can explicitly declare the pigment, or use an already declared identifier. Don't forget that the color components can take any value you want (negative ones, greater than one, ...)

viscosity Specifies the influence of the wind and air friction on the cloth. The default value is 0 (no influence).

neighbors Specifies the number of neighbors that are joined by springs at each point. neighbors 0 is for 8 neighbors (faster but rougher calculation), and neighbors 1 (default value) is for 24 neighbors (slower calculation, but better results).

internal_collision Activates or deactivates internal collision management (cloth against itself). This problem is handled by added springs between points that are too close together. System instability probability is increased, and you must, most often, decrease the intervals parameter (see below). Deactivated by default (warning: much longer parsing when activated).

damping General energy loss parameter, it limits the accumulation of the model approximations and errors. A value lower than 0.95 (default value) is strongly recommended.

intervals specifies the time interval between each iteration. Keep it low. Default value is 0.05.

iterations It's the number of iterations to calculate.

input Filename of the starting *.cth file. The only required parameter, since you need a cloth to start with. For a complete description of the *.cth file format, see below.

output Filename of the ending *.cth file. If this parameter is specified, the result of the simulation is saved. Useful for animations, or for a multi-stage calculation.

mesh_output Allow the program to output a file (with specified name), containing tons of triangles, corresponding to the cloth points after the simulation. It allows you to save the result of a simulation, in a format usable by other POV-Ray™ versions (official or unofficial).

smooth_mesh Activate or deactivate the creation of smooth_triangle's if the mesh_output option is activated. Deactivated by default.

uv_mesh Activates or deactivates uv coordinates within the triangle (or smooth_triangle) if the mesh_output option is activated. UV coordinates go from <0, 0> to <1, 1>. Deactivated by default. Description of the .cth file format:

The file format is simple: the first line describes the cloth dimensions (number of points n1 and n2, normalized length between 2 neighbors nlng), and the springs strength ks. The other lines describe the location in space and velocity of each point. All values (3 for location, 3 for speed) are separated by commas, and each line is terminated by a comma as well.

Then, there are the constraints definitions. Constraints are 3 coefficients (1 for each axis) that will control the velocity vector of a given point of the cloth. It will be possible, for instance, to slow down a corner of the cloth along one axis, to completely stop it along another axis, and let it free along the last one. A constraint is defined by an integer (index), and 3 floating point coefficients, representing the constraint (respectively on x, y, z axis), all this on the same line and separated by commas. The index is the rank of the point (beginning at 0) in order of declaration of the cloth points. Constraints can be declared in any order.

You could see the cloth as 2 arrays of vectors Points[n1][n2], and Velocity[n1][n2], and its constraints Indexn, coefn. The *.cth file will look like this:

n1, n2, nlng, ks,
Points[0][0], Velocity[0][0],
Points[0][1], Velocity[0][1],
Points[0][n2-1], Velocity[0][n2-1],
Points[1][0], Velocity[1][0],
Points[1][1], Velocity[1][1],
Points[1][n2-1], Velocity[1][n2-1],
Points[2][0], Velocity[2][0],
Points[n1-1][n2-1], Velocity[n1-1][n2-1],
Index1, coef1[x], coef1[y], coef1[z],
Index2, coef2[x], coef2[y], coef2[z],
Index3, coef3[x], coef3[y], coef3[z],

For an example of a macro writing such a file (see Section, “Writing a *.cth file”).

2.4.4. Isosurface Control of max gradient message

Yvo & René Smellenbergh

In POV-Ray™ 3.5 the messages concerning the max_gradient follow a heuristic method to be displayed. This means that the message only appears when the difference with the set max_gradient is more than a certain percentage. Also when using a loop with hundreds of isosurfaces which have different max_gradient's, you need to wait after the render for all those messages to be displayed: this can take several minutes. Basically, you cannot control these messages.

In MegaPOV 1.0 you can use the keyword message to control the message flow:

  • message on will always show all max_gradient messages
  • message off will never show a max_gradient message
  • without a message keyword the default heuristic method will be used

This keyword is used in the isosurface{} block and should be used after the function{} block and before any material.

By using conditional expressions, you can now control messages in a loop.

2.4.5. Light Sources Area Light max_trace_level

Christoph Hormann

Normally area lights are handled as area lights in all situations. This means that every shadow ray test against an area light source is sampled across the area of the light source. This patch allows to specify a max_trace_level for the area light which turns off the soft shadows above the specified trace level.

Syntax is:

light_source {
  max_trace_level INTEGER

If you for example specify:

light_source {
  color rgb 1.0
  area_light 0.5*x 0.5*y 9,9 jitter adaptive 1 circular orient
  max_trace_level 1

this will only result in soft shadows on directly visible surfaces. In reflections, refractions and radiosity the light source will be treated as a point light.