A texture describes the surface of an object. Everything that happens inside an object or in the space around it is described by other statements. The interior statement holds the properties of the matter inside an object: its index of refraction, dispersion, caustics, light attenuation, and the particles (media) it contains. The media statement describes particles that absorb, emit and scatter light; it is used inside an interior, or at the top of the scene, where it fills the whole atmosphere. fog, rainbow, sky_sphere and background are cheaper scene-level effects that do not sample the space. There is no atmosphere keyword in this version of the language: atmospheric media is a media statement that is not attached to an object.
A scene with no #version directive runs as language version 3.62. The media defaults depend on the language version (before 3.5 the default method is 1 with 10 intervals); this page lists the values for language version 3.5 and later.
The interior statement
interior {
[interior identifier]
[ior n] [dispersion d] [dispersion_samples n] [caustics c]
[fade_distance d] [fade_power p] [fade_color | fade_colour colour]
[media { … }] …
}
The statement is an object modifier (sphere { … interior { ior 1.5 } }) and can be part of a material. An identifier first supplies the starting values (#declare Water = interior { … }). The interior matters only for solid objects with a well-defined inside, and only if the surface texture is transparent, so that one can look inside. Scaling an object does not change its interior: a lens made of glass with ior 1.5 has the same ior at any size, light fades by the same amount per unit of distance (so a bigger object looks darker), and media has the same density per cubic unit (so there are more particles in a bigger object).
| Keyword | Value | Default | Meaning |
|---|---|---|---|
ior | number | 1.0 (0 internally, which is replaced by the ior of the atmosphere, 1.0) | index of refraction. A non-zero ior turns refraction on (an ior of 1 is legal and bends nothing). Air is 1.0, water 1.33, glass 1.5, diamond 2.4. It does not make the object transparent: that needs a filter or transmit value in the pigment. The same ior is used by the Fresnel reflection of the finish and by subsurface light transport |
dispersion | number | 1.0 (none) | the ratio of the indices of refraction for violet and red light. Good values are 1.01 to 1.1. Without an ior there is no dispersion. The ior does not change the strength, only the angle of refraction. Dispersion has no effect on simulated caustics; it shows in photon caustics |
dispersion_samples | integer ≥ 2 | 7 | number of colour steps of the simulated spectrum. Up to 100 or more for a very smooth result. A smaller value is a parse error |
caustics | number | 0 (none) | simulated caustics: shaded areas behind a transparent object get brighter where the light ray is nearly parallel to the surface normal, and the effect falls off with the angle. The value is multiplied by 45 internally. Typical 0 to 1: low values give broad bright areas, high values small focal points. It acts only in the shadow of the object and only for refraction, not reflection |
fade_distance | number | 0 (no attenuation) | distance in the interior at which the light has fallen to half |
fade_power | number | 0 | how fast the light falls off; use 1 to 2 for realism. 1000 or more selects an exponential falloff. Attenuation is only on if both fade_distance and fade_power are non-zero |
fade_color, fade_colour | colour | <0, 0, 0> | colour of the attenuation. <1,1,1> means no attenuation; <1,0,0> gives a red tint (not cyan as in media) |
media | media statement | none | particles inside the object, see below. More than one media may be written; their effects add up |
refraction | number | 1.0 | old keyword (warning “Refraction value unnecessary to turn on refraction…”). The number darkens the refracted light; use the pigment’s filter and transmit or fade_power instead |
The keywords ior, caustics and refraction are also accepted inside finish (with a warning), and are then moved to the interior of the object when its texture is a plain texture. The statement hollow (an object keyword, on Object modifiers) is a flag of the interior as well: an object must be hollow for media to work inside it.
The attenuation of a ray that has travelled the distance d in the interior is the colour
fade_colour + (1 − fade_colour) / (1 + (d / fade_distance) ^ fade_power)
fade_power >= 1000: exp(−(1 − fade_colour) × d / fade_distance)
So with the default fade_colour 0 the light is at half strength at d = fade_distance. The result multiplies the refracted light and the light of shadow rays that pass through the object.
sphere { 0, 1
pigment { rgbf <1, 1, 1, 0.95> }
finish { reflection { 0.05, 1 fresnel on } conserve_energy }
interior {
ior 1.5
dispersion 1.03
dispersion_samples 12
caustics 0.5
fade_distance 2
fade_power 2
fade_color rgb <0.3, 0.6, 1>
}
}
#declare Water = interior { ior 1.33 fade_distance 5 fade_power 1001 fade_colour <0.2, 0.5, 1> }
box { <2, -1, -1>, <4, 0, 1>
pigment { rgbf <0.9, 1, 1, 0.9> }
interior { Water }
}
The media statement
media {
[media identifier]
[method 1|2|3] [intervals n] [samples min [, max]]
[confidence c] [variance v] [ratio r] [jitter j]
[aa_level n] [aa_threshold t]
[absorption colour] [emission colour]
[scattering { type, colour [eccentricity e] [extinction x] }]
[density { … }] …
[collect [bool]]
[translate | rotate | scale | transform | matrix …]
}
Media is sampled at a number of points along a ray. A medium is made of three kinds of interaction with light: absorption, emission and scattering. Each is given by a colour (only red, green and blue are used; filter and transmit are ignored, and a single number is a grey). The colour also sets the density of the particles: 100 particles per unit means a colour value that is 100 times as large. Inside an interior the sampling happens only inside the object, from the entry to the exit point of the ray. At the top level of the scene the media is atmospheric (see below). The object must be hollow, and a transparent container object (a pigment with filter or transmit 1) casts a shadow for absorbing and scattering media unless it has no_shadow; emission media never casts a shadow.
| Keyword | Value | Default | Meaning |
|---|---|---|---|
method | 1, 2 or 3 | 3 (language version 3.5 and later; 1 before) | sampling method, see below. Another number: “Sample method choices are 1, 2, or 3.” |
intervals | integer ≥ 1 | 1 (10 before 3.5) | number of intervals the ray path is divided into. Zero or less is an error. Method 3 works best with one interval; the program makes more if needed |
samples | min [, max] | 10, 10 (1, 1 before 3.5) | minimum and maximum number of samples per interval. max defaults to min. Both at least 1, max not below min. (The manual lists the default as 1, 1; the parser sets 10, 10 for a new media in language version 3.5 and later.) |
confidence | number, 0 ≤ c < 1 | 0.9 | probability that the estimate is within the variance; more samples are taken until it is reached (but never more than max). A value outside 0 to 1 is “Illegal confidence value in media.” |
variance | number | 1/128 | permitted variance of the samples in an interval. Smaller values and larger confidence give slower and more accurate results |
ratio | number | 0.9 | how the intervals are spread between lit and unlit areas (spotlight and cylinder light cones). 0.9 gives lit intervals more samples. The number of intervals must exceed the number of lit intervals, or there is an error |
jitter | number | 0 | random displacement of the sample points. For method 2 a value of 1 staggers the samples over the full range between samples and makes it look like method 1. Also works with method 3 |
aa_level | integer ≥ 1 | 3 | recursion depth of the adaptive sampling of method 3 (the manual’s text says 4 in one place; 3 is the value in its default list and in the source) |
aa_threshold | number > 0 | 0.1 | threshold of the adaptive sampling of method 3 |
absorption | colour | <0, 0, 0> (none) | light of this colour is absorbed: absorption rgb <0,1,0> removes green, so a white object behind looks magenta |
emission | colour | <0, 0, 0> (none) | light given out by the particles; visible without lights, like a high ambient. It lights other objects only with radiosity and media on there |
scattering | { type, colour … } | none | scattering of light from light sources, like diffuse reflection; see below. It also absorbs |
density | { … } | constant 1 | a pattern that varies the density; see below |
collect | [bool] | on | when off, the media is ignored by photons |
| transformations | apply to the density statements written before them (later ones are not changed); with no density they do nothing |
Scattering
scattering { type, colour [eccentricity e] [extinction x] }
| Item | Value | Default | Meaning |
|---|---|---|---|
| type | 1 to 5 | 1 | 1 isotropic (independent of direction). 2 Mie haze and 3 Mie murky (for fine droplets and pollution: very much forward scattering, murky more than haze). 4 Rayleigh (small particles such as air; no dependence on the wavelength is modelled). 5 Henyey-Greenstein (a function with an eccentricity). A number outside 1 to 5 gives the warning “Unknown atmospheric scattering type.” |
| colour | colour | <0, 0, 0> | colour of the scattered light (and so the amount) |
eccentricity | number | 0 | only for type 5 (the error “Eccentricity cannot be used with this scattering type.”). 0 is isotropic; positive values scatter toward the direction of the light, negative against it; larger magnitudes are more directional |
extinction | number | 1.0 | the balance between scattering and absorption. 1 matches the physical model, 0.25 gives a quarter of the usual absorption, 0 turns it off. Other values are not physical, but give artistic freedom |
Sampling methods
| Method | How it samples |
|---|---|
| 1 | The path is divided into intervals; each interval gets samples random sample points (between the minimum and the maximum, stopping early when confidence and variance are met). With spotlight or cylinder light cones the lit intervals are weighted by ratio |
| 2 | Samples are spread evenly along the ray (or light ray); extra samples above the minimum are random, so set max equal to min. jitter randomises them |
| 3 | Adaptive sampling like adaptive antialiasing: another sample is taken between two samples if their variance is large. Adaptive only if the minimum number of samples is 3 or more. aa_level and aa_threshold control it |
Density
density {
[density identifier]
[pattern type | colour]
[pattern modifiers] [color_map { … } | density_map { … }]
}
A density statement uses any pattern (spherical, planar, cylindrical and boxed are the most useful) and its modifiers (see Patterns and maps). The pattern value, 0 to 1, is the density at the point. With a color_map the value is turned into a colour that multiplies the absorption, emission and scattering colour (so a flame can be white in the middle and orange to blue at the edge; one map for all three kinds). With density_map each entry is a density body ([0.3 spherical scale 2]), blended like a pigment map. For block patterns (checker, hexagon, brick, object) the items are written density { … } each. A plain colour is allowed but is mostly used inside a density map. The three colour components are the density; a single number is a grey.
Several densities in one media are multiplied at each sample point: where one is zero it removes the other, so only the overlap is seen (like an intersection). Several media in one interior are computed independently and added (like a union). Transformations written in a media after a density move that density; scaling the container scales the density pattern as well. To keep the look when scaling an object evenly by s, divide the media colour by s; for uneven scaling use Density × sqrt(3) / vlength(Scale).
sphere { 0, 1
pigment { rgbt 1 }
hollow
interior {
media {
method 3
intervals 1
samples 8, 16
confidence 0.95
variance 1/200
aa_level 3
aa_threshold 0.1
jitter 0.5
emission 0.1
absorption rgb <0.2, 0.2, 0>
scattering { 5, rgb 0.4 eccentricity 0.3 extinction 0.5 }
density {
spherical
color_map {
[0.0 rgb <0, 0, 0.5>]
[0.5 rgb <0.8, 0.8, 0.4>]
[1.0 rgb <1, 1, 1>]
}
turbulence 0.3
}
scale 1.2
}
}
}
box { <2, -1, -1>, <4, 1, 1>
pigment { rgbt 1 }
hollow
interior {
media {
method 2
samples 12
jitter 1
emission 0.5
}
media {
method 1
intervals 6
samples 1, 3
ratio 0.8
absorption 0.05
density { gradient x }
}
}
}
Atmosphere and scene-level effects
The following statements are written at the top level of the scene, outside any object. The camera must not be inside a non-hollow object, or fog, atmospheric media and rainbows are not computed (make large objects such as planes hollow).
Atmospheric media
A media { … } statement outside an object fills the whole scene. More than one can be written; they add up. The sampling runs from the camera to the first object that the ray hits, so the media shows up only in front of objects, not against the background or the sky sphere. Spotlight cones are finite and give the best results; point lights can make street lights in fog. Which lights take part is set by media_interaction (default on) and media_attenuation (default off) of each light source, see Light sources. If the effect is wanted only in one area, use an object interior with media instead: it is faster and more accurate because it is computed only inside the container.
fog
fog {
[fog identifier]
[colour] [distance d] [fog_type 1|2]
[fog_offset h] [fog_alt a] [up <v>]
[turbulence <t>] [turb_depth d] [octaves n] [omega o] [lambda l]
[rotate | scale | matrix | transform …]
}
Fog adds colour to every pixel according to the distance the ray travelled, without looking at light sources. It is faster than media but shows no light beams and no shadows in the fog. Several fog statements may be written; they are layers (usually ground fogs of different colour, height and turbulence).
| Keyword | Value | Default | Meaning |
|---|---|---|---|
| colour | colour | black | the colour of the fog. The transmit value is a threshold: at least that share of the background always shows. The filter value makes a filtering fog: that share of the background light is multiplied by the fog colour |
distance | number | 0 (fog off) | the distance D at which an object has 64 per cent of its colour and the fog 36 per cent. Pixel = exp(−d/D) × object + (1 − exp(−d/D)) × fog. A distance of 0 means no fog; use 1e-6 for a very thick fog. An old form wrote the number alone after the colour (a version warning) |
fog_type | 1 or 2 | 1 | 1 constant fog, 2 ground fog. Another number is a warning (“Unknown fog type.”) |
fog_offset | number | 0 | ground fog: the height (along up) below which the fog has full density |
fog_alt | number | 0 | ground fog: the rate at which the fog fades above the offset. The density above the offset is 1 / (1 + (y − offset) / alt)² (25 per cent at offset + alt); the total is the integral along the ray. Both default to 0, so write them for a ground fog |
up | vector | <0, 1, 0> | the direction of “up” for ground fog, normalised. Rotation and scale of the fog change this vector (scaling is not advised); translate is accepted but gives the warning “A fog’s up vector can’t be translated.” |
turbulence | number or vector | <0, 0, 0> | noise that stirs the fog, see turbulence |
turb_depth | number | 0.5 | scales the turbulence along the direction of the ray. Typical 0 to 1 or more |
octaves, omega, lambda | number | 6, 0.5, 2.0 | turbulence parameters; octaves clamped to 1 to 10 |
rainbow
rainbow {
[rainbow identifier]
direction <v> angle a width w [distance d] [jitter j]
color_map { … } [up <v>] [arc_angle a] [falloff_angle a]
}
A rainbow is a fog-like circular arc. For each ray the angle between its direction and the direction of the (virtual, very distant) light is computed. If the angle is between angle − width/2 and angle + width/2 the ray hits the rainbow and the angle, mapped to 0 (inner ring) to 1 (outer ring), selects a colour from the map. The colour is blended with the background as for fog (filter and transmit as in fog). Any number of rainbows may be used.
| Keyword | Value | Default | Meaning |
|---|---|---|---|
direction | vector | <0, 0, 0> (an error: “Rainbow’s direction vector is zero.”) | the direction of the light that makes the rainbow; required |
angle | degrees | 0 | angle from the direction to the middle of the rainbow (42.5 for a real one). The manual calls it required; the parser accepts it missing and uses 0 |
width | degrees | 0 | width of the band; the same remark |
distance | number | very large | as for fog; the default makes sure that the rainbow is not seen on objects |
jitter | number | 0 | random noise on the colour map index |
color_map, colour_map | colour map | none | the colours (see colour maps) |
up | vector | <0, 1, 0> | where the zero angle of the arc is; rotating it turns the arc around the direction. Not parallel to direction: “Rainbow’s up and direction vector are co-linear.” |
arc_angle | 0 to 360 | 180 (the manual calls the default rainbow a full 360 degree circle) | size of the arc: it goes from −arc/2 to +arc/2. A smaller arc ends abruptly. Outside 0 to 360 is an error |
falloff_angle | 0 to 360, not above arc_angle | 180; equal to arc_angle if only that is written | the arc blends softly into the background between ±falloff/2 and ±arc/2. A falloff larger than the arc: “Arc angle is smaller than falloff angle in rainbow.” |
sky_sphere
sky_sphere {
[sky_sphere identifier]
pigment { … } [pigment { … } …]
[emission colour]
[rotate | translate | scale | matrix | transform …]
}
A sky sphere is a background at infinity. The direction of the ray (a unit vector, so the point is <-1,-1,-1> to <1,1,1>) is used as the point at which the pigment is evaluated, so the sky does not depend on the camera position. pigment may be written several times: the first is the bottom layer, the last the top; transparent parts of the upper layers (filter or transmit) show the layers below. A sky sphere without a pigment is the error “Empty sky_sphere statement.”. Only one sky sphere is used: a second gives the warning “Only one sky-sphere allowed (last one will be used).” emission (default rgb 1) multiplies the sky colour to adjust the brightness, mostly for light-probe images. Rotating the sky sphere is useful for animation; translating and scaling give hard to predict results. It does not work as expected with the orthographic and cylindrical cameras, because their rays are parallel.
background
background { colour }
The colour of any ray that hits nothing. The default is black. From language version 3.7 a background in the scene is opaque unless it has a transmit value (use rgbft for the old behaviour when alpha output is on).
background { rgb <0.1, 0.1, 0.2> }
sky_sphere {
pigment {
gradient y
color_map { [0.5 rgb <0.6, 0.7, 1>] [1.0 rgb <0.05, 0.1, 0.4>] }
scale 2
translate -1
}
pigment {
bozo
color_map { [0 rgbt <1, 1, 1, 1>] [0.5 rgbt <1, 1, 1, 0.6>] [1 rgbt <1, 1, 1, 0>] }
scale 0.3
}
emission rgb <0.9, 0.9, 1>
rotate y*20
}
fog {
fog_type 2
distance 40
color rgbt <0.8, 0.85, 0.9, 0.1>
fog_offset 0.5
fog_alt 2
up <0, 1, 0>
turbulence 0.4
turb_depth 0.5
octaves 4
omega 0.5
lambda 2
}
fog { distance 200 color rgb <0.7, 0.7, 0.8> }
rainbow {
direction <0, 0, 1>
angle 42.5
width 5
distance 1000
jitter 0.01
color_map {
[0.0 rgbf <1, 0.5, 1, 1>]
[0.5 rgbf <1, 0.8, 0.2, 0.5>]
[1.0 rgbf <0.5, 0.5, 1, 1>]
}
up <0, 1, 0>
arc_angle 120
falloff_angle 30
}
media {
intervals 1
samples 5, 10
scattering { 2, rgb 0.01 }
}
light_source { <0, 20, -20> rgb 1 media_interaction on media_attenuation on }
light_source {
<4, 6, -4> rgb 2
spotlight point_at 0 radius 10 falloff 20
media_interaction on
}
plane { y, -1 pigment { rgb 0.5 } hollow }
sphere { 0, 1 pigment { rgb 1 } hollow }
Not described
Known, not yet covered
- Reference: the exact scattering phase functions and the statistics of the sampling (the chi-squared confidence test) are only described in words; the media code (
source/core/render/media.cpp) was not followed through. - Reference: the parser has no
photonsblock ininterior; the photon keywords that exist for media (collect) and objects are listed, the global photon settings are on Global settings. - Reference: the internal units of the rainbow
arc_angleandfalloff_angledefaults (the parser stores 180 for both without converting) were not traced into the rainbow code.