The full source code is found in PatchyFog.java. Here is the getMaterialSpec() method:
public void getMaterialSpec(MaterialSpec spec, double x, double y, double z, double xsize, double ysize, double zsize, double t) { double size = 1.0, scale = 1.0; float d = 0.0f; for (int i = 0; i < 3 && xsize < size && ysize < size && zsize < size; i++) { d += (float) (size*Noise.value(x*scale+123.456, y*scale+123.456, z*scale+123.456)); size *= 0.5; scale *= 2.0; } d = 0.5f*d + 1.0f - thickness; if (d > 1.0f) d = 1.0f; else if (d < 0.0f) d = 0.0f; spec.transparency.setRGB(d, d, d); spec.color.copy(color); if (scattering > 0.0f) { d = scattering*(1.0f-d); spec.scattering.setRGB(d, d, d); spec.eccentricity = 0.0; } }There are a number of important things to notice about this method:
d = 0.5f*d + 1.0f - thickness;is somewhat arbitrary. We want thickness values in the range [0, 1] to cover the range of useful materials, from very thin and wispy to almost totally opaque, and this function is empirically found to give good results.
public boolean isScattering() { return (scattering > 0.0f); }If scattering = 0, then isScattering returns false and the renderer ignores the scattering color.
Prev: The Material3D Class Next: Postscript: Isn't There a Better Way?