### Section 7.5.5Constructive Solid Geometry

POV-Ray supports Constructive Solid Geometry (CSG) with five different operations: difference, intersection, merge, union and negation (inversion). While the first four operations represent binary operators, i. e. they need two arguments, the negation is a unary operator, it takes only one argument.

### Section 7.5.5.1About CSG

Constructive Solid Geometry is a technique for combining two or more objects to create a new object using the three boolean set operators union, intersection, and negation. It only works with solid objects, i. e. objects that have a well-defined interior. This is the case for all objects described in the sections "Finite Solid Primitives" and "Infinite Solid Primitives".

CSG shapes may be used anywhere a standard shape can be used, even inside other CSG shapes. They can be translated, rotated or scaled in the same way as any other shape. The shapes making up the CSG shape may be individually translated, rotated and scaled as well.

### Section 7.5.5.2Inside and Outside

Most shape primitives, like spheres, boxes and blobs divide the world into two regions. One region is inside the object and one is outside.

Given any point in space you can say it's either inside or outside any particular primitive object. Well, it could be exactly on the surface but this case is rather hard to determine due to numerical problems.

Even planes have an inside and an outside. By definition, the surface normal of the plane points towards the outside of the plane. You should note that triangles and triangle-based shapes cannot be used as solid objects in CSG since they have no well defined inside and outside.

CSG uses the concepts of inside and outside to combine shapes together as explained in the following sections.

Imagine you have to objects that partially overlap like shown in the figure below. Four different areas of points can be distinguished: points that are neither in object A nor in object B, points that are in object A but not in object B, points that are not in object A but in object B and last not least points that are in object A and object B.

Two overlapping objects.

Keeping this in mind it will be quite easy to understand how the CSG operations work.

### Section 7.5.5.3Inverse

When using CSG it is often useful to invert an object so that it'll be inside-out. The appearance of the object is not changed, just the way that POV-Ray perceives it. When the inverse keyword is used the inside of the shape is flipped to become the outside and vice versa.

Note that the difference operation is performed by intersecting the first object with the negation of the second object.

### Section 7.5.5.4Union

The union of two objects.

You should be aware that the surfaces inside the union will not be removed. As you can see from the figure this may be a problem for transparent unions. If you want those surfaces to be removed you'll have to use the merge operations explained in a later section.

The following union will contain a box and a sphere.

union { box { <-1.5, -1, -1>, <0.5, 1, 1> } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 } }

### Section 7.5.5.5Intersection

A point is inside an intersection if it is inside both objects, A and B, as show in the figure below.

The intersection of two objects.

For example:

intersection { box { <-1.5, -1, -1>, <0.5, 1, 1> } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 } }

### Section 7.5.5.6Difference

The CSG difference operation takes the intersection between the first object and the negation of the second object. Thus only points inside object A and outside object B belong to the difference of both objects.

The results is a subtraction of the 2nd shape from the first shape as shown in the figure below.

The difference between two objects.

For example:

difference { box { <-1.5, -1, -1>, <0.5, 1, 1> } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 } }

### Section 7.5.5.7Merge

The union operation just glues objects together, it does not remove the objects' surfaces inside the union. If a transparent union is used those surface will get visible.

The merge operations can be used to avoid this problem. It works just like union but it eliminates the inner surfaces like shown in the figure below.

Merge removes inner surfaces.

### Section 7.5.6Light Sources

The last object covered is the light source. Light sources have no visible shape of their own. They are just points or areas which emit light. Their full syntax is:

light_source { <LOCATION> color <COLOUR> [ spotlight ] [ point_at <POINT_AT> ] [ radius RADIUS ] [ falloff FALLOFF ] [ tightness TIGHTNESS ] [ area_light <AXIS1>, <AXIS2>, SIZE1, SIZE2 ] [ adaptive ADAPTIVE ] [ jitter JITTER ] [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

The different types of light sources and the optional modifiers are described in the following sections.

### Section 7.5.6.1Point Lights

A point light source sends light of the specified color uniformly in all directions. Its location is described by the location keyword and its color is given by the color keyword. The complete syntax is:

light_source { <LOCATION> color <COLOUR> [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

The other keywords will be explained later.

### Section 7.5.6.2Spotlights

A spotlight is a point light source where the rays of light are constrained by a cone. The light is bright in the center of this cone and falls off or darkens at the edges of the cone. The syntax is:

light_source { <LOCATION> color <COLOUR> spotlight point_at <POINT_AT> radius RADIUS falloff FALLOFF tightness TIGHTNESS [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

The geometry of a spotlight.

Think of a spotlight as two nested cones as shown in the figure. The inner cone is specified by the radius parameter and is fully lit. The outer cone is the falloff cone beyond which there is no light. The values for these two parameters are half the opening angles of the corresponding cones, both angles have to be smaller than 90 degrees. The light smoothly falls off between the radius and the falloff angle like shown in the figures below (as long as the radius angle is not negative).

Intensity multiplier curve with a fixed falloff angle of 45 degrees.

Intensity multiplier curve with a fixed radius angle of 45 degrees.

Intensity multiplier curve with fixed angle and falloff angles of 30 and 60 degrees respectively and different tightness values.

You should note from the figures that the radius and falloff angles interact with the tightness parameter. Only negative radius angles will give the tightness value full control over the spotlight's appearance as you can see from the figure below. In that case the falloff angle has no effect and the lit area is only determined by the tightness parameter.

Intensity multiplier curve with a negative radius angle and different tightness values.

Spotlights may be used anyplace that a normal light source is used. Like any light sources, they are invisible. They are treated as shapes and may be included in CSG shapes. They may also be used in conjunction with area lights.

Next Section
Table Of Contents