### 3.4.4 Isosurface Object

Details about many of the things that can be done with the isosurface object are discussed in the isosurface tutorial section. Below you will only find the syntax basics:

    isosurface {
      function { FUNCTION_ITEMS }
      [contained_by { SPHERE | BOX }]
      [threshold FLOAT_VALUE]
      [accuracy FLOAT_VALUE]
      [max_gradient FLOAT_VALUE]
      [evaluate P0, P1, P2]
      [open]
      [max_trace INTEGER] | [all_intersections]
      [OBJECT_MODIFIERS...]
    }

Isosurface default values:

    contained_by : box{-1,1}
    threshold    : 0.0
    accuracy     : 0.001
    max_gradient : 1.1

`function { ... }` This must be specified and be the first item of the `isosurface` statement. Here you place all the mathematical functions that will describe the surface.

`contained_by { ... }` The `contained_by` 'object' limits the area where POV-Ray samples for the surface of the function. This container can either be a sphere or a box, both of which use the standard POV-Ray syntax. If not specified a `box {<-1,-1,-1>, <1,1,1>}` will be used as default.

    contained_by { sphere { CENTER, RADIUS } }
    contained_by { box { CORNER1, CORNER2 } }

`threshold` This specifies how much strength, or substance to give the `isosurface`. The surface appears where the `function` value equals the `threshold` value. The default threshold is 0.

    function = threshold

`accuracy` The isosurface finding method is a recursive subdivision method. This subdivision goes on until the length of the interval where POV-Ray finds a surface point is less than the specified `accuracy`. The default value is 0.001.
Smaller values produces more accurate surfaces, but it takes longer to render.

`max_gradient` POV-Ray can find the first intersecting point between a ray and the `isosurface` of any continuous function if the maximum gradient of the function is known. Therefore you can specify a `max_gradient` for the function. The default value is 1.1. When the `max_gradient` used to find the intersecting point is too high, the render slows down considerably. When it is too low, artefacts or holes may appear on the isosurface. When it is way too low, the surface does not show at all. While rendering the isosurface POV-Ray records the found gradient values and prints a warning if these values are higher or much lower than the specified `max_gradient`:

    Warning: The maximum gradient found was 5.257, but max_gradient of
    the isosurface was set to 5.000. The isosurface may contain holes!
    Adjust max_gradient to get a proper rendering of the isosurface.

    Warning: The maximum gradient found was 5.257, but max_gradient of
    the isosurface was set to 7.000. Adjust max_gradient to
    get a faster rendering of the isosurface.

For best performance you should specify a value close to the real maximum gradient.

`evaluate` POV-Ray can also dynamically adapt the used max_gradient. To activate this technique you have to specify the `evaluate` keyword followed by three parameters:

- P0: the minimum max_gradient in the estimation process,
- P1: an over-estimating factor. This means that the max_gradient is multiplied by the P1 parameter.
- P2: an attenuation parameter (1 or less)

In this case POV-Ray starts with the `max_gradient` value `P0` and dynamically changes it during the render using `P1` and `P2`. In the evaluation process, the P1 and P2 parameters are used in quadratic functions. This means that over-estimation increases more rapidly with higher values and attenuation more rapidly with lower values. Also with dynamic `max_gradient`, there can be artefacts and holes.

If you are unsure what values to use, start a render without `evaluate` to get a value for `max_gradient`. Now you can use it with `evaluate` like this:

- P0 : found max_gradient * min_factor
  'min_factor' being a float between 0 and 1 to reduce the `max_gradient` to a 'minimum max_gradient'. The ideal value for P0 would be the average of the found max_gradients, but we do not have access to that information.
  A good starting point is 0.6 for the min_factor
- P1 : sqrt(found max_gradient/(found max_gradient * min_factor))
  'min_factor' being the same as used in P0 this will give an over-estimation factor of more than 1, based on your minimum max_gradient and the found max_gradient.
- P2 : 1 or less
  0.7 is a good starting point.

When there are artifacts / holes in the isosurface, increase the min_factor and / or P2 a bit. Example: when the first run gives a found max_gradient of 356, start with

      #declare Min_factor= 0.6;
      isosurface {
         ...
         evaluate 356*Min_factor,  sqrt(356/(356*Min_factor)),  0.7
         //evaluate 213.6, 1.29, 0.7
         ...
       }

This method is only an approximation of what happens internally, but it gives faster rendering speeds with the majority of isosurfaces.

`open` When the isosurface is not fully contained within the contained_by object, there will be a cross section. Where this happens, you will see the surface of the container. With the `open` keyword, these cross section surfaces are removed. The inside of the isosurface becomes visible.

Note: that `open` slows down the render speed. Also, it is not recommended to use it with CSG operations.

`max_trace` Isosurfaces can be used in CSG shapes since they are solid finite objects - if not finite by themselves, they are through the cross section with the container.
By default POV-Ray searches only for the first surface which the ray intersects. But when using an `isosurface` in CSG operations, the other surfaces must also be found. Therefore, the keyword `max_trace` must be added to the `isosurface` statement. It must be followed by an integer value. To check for all surfaces, use the keyword `all_intersections` instead.
With `all_intersections` POV-Ray keeps looking until all surfaces are found. With a `max_trace` it only checks until that number is reached.