Can somebody explain how to implement volume rendering and scattering? I've been told that this is the easiest and most effective method to render things like smoke, milk and fog.

Scratchapixel has a great article about it here but the lesson on implementation is unavailable.

I understand what Ray Marching is because of this answer from a while back but similiar to my previous problem I have no idea how to implement it.

To make it clear and narrow this question down so it is easier to answer here are my main problems:

  1. Can someone provide some pseudo code or code of a basic Volume Rendering and Ray Marching loop with Absorption & Scattering coefficients, Phase Function and a Density function?
  2. How is Ray Marching used alongside Path Tracing?
  3. Is this the best way to render sub surface scattering?
  • $\begingroup$ Subsurface scattering won't necessarily require ray marching if it is in a homogeneous medium. Are you specifically looking to model inhomogeneous media (fire and smoke) rather than homogeneous media (milk or glass)? $\endgroup$ Jun 11, 2017 at 0:25
  • $\begingroup$ Are you trying to do real time or offline rendering? SSS is a surface based algorithm that uses what's called a BSSRDF. Usually the implementation only accepts the data of a few layers past the surface. Usually just a few extra texture maps. Volume rendering can do the job of SSS but it models the entire inside of a volume. Often it does this with a 3d texture (uniform grid). But sometimes it's done with other datasets like tetrahedral grids. TLDR: Volume rendering isn't used for SSS although the concepts of emission, absorption, in/out scattering are the same. $\endgroup$ Jun 16, 2017 at 23:47

1 Answer 1


If this is still of interest to some readers in the future), I would recommend that you look at the lesson on ray-marching / volume rendering for developers on scratchapixel.


It explains how ray-marching works and also gives info on how to render volumetric objects with varying volume density (including voxel grids). Hope it helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.