Assume that the participating media volume is finite. Besides of attenuation and emission, direct illumination of participating media accounts for the single scattering, while indirect illumination is for multiple scattering. This scratch only consider single scattering.

The color along a camera, reflect or refract ray:

(1) If the ray does not go through the participating media volume, and it hits:

(a) nothing: background color

(b) diffuse, specular, transparent surface: direct illumination of the surface. Consider the light ray being affected by participating media. For reflect and refract rays, consider the radiance attenuation if they go through the media.

(2) Otherwise, if the ray intersects with the volume, compute the color with two steps:

Step 1: compute the color as described in (1).

Step 2: apply attenuation, emission and scattering to the color computed from step 1.

If the ray hits a surface, attenuate the color from the hit point in the surface to the first intersect point with the volume, or to the origin of the ray if the origin is inside the volume.

If the ray hits nothing, attenuate the background color from the second intersect point with the volume to the first intersect point, or to the origin of the ray if the origin is inside the volume.

 The color of a point X being illuminated by the light ray:

If the light ray hits a surface closer than X, it’s not illuminated, i.e the color is zero. Otherwise, apply attenuation and emission for the light ray.