# Adding two fogs

When calculating fog along the ray we have two main part- transmittance and scattering.

What happens when we have two different fogs? With different extinction and color? Both extinction and color constant along the ray.

Transmittance seems easy to merge, probably something like this: $$T = e^{(\sigma_a+\sigma_b)d}$$ Where d is ray length.

What about color?

General in-scattering equation looks like this: $$S=\sigma *Fog_{color}\int_0^dT(x,\omega x)dx$$

What will happen with this equation when there are two fogs?

Will it become: $$Fog_{color}=lerp(Fog_a,Fog_b,\sigma_b/(\sigma_a+\sigma_b))$$ $$\sigma_t=\sigma_a+\sigma_b$$ $$S=\sigma_t*Fog_{color}*\int_0^de^{-\sigma_tx}dx$$ Or $$S=\sum_0^n\sigma_i*Fog_i\int_0^dT_i(x,\omega x)dx$$ Where n is fogs count.

Or something else?

## 1 Answer

After some research i think i have final answer.

General fog equation looks something like this: $$L(t)=L_p\color{red}{T(t)} + \int_0^t\color{blue}{T(x)}\color{green}{\sigma(x)L(x)}dx$$ Transmittance defined as: $$T(x)=e^{-\int_0^x\sigma(x) dx}$$ With const $$\sigma$$ become $$T(x)=e^{-\sigma x}$$

So color that will be visible is:

Visible percent $$\color{red}{T(t)}$$ of pixel color $$L_p$$, plus scattering probability $$\color{green}{\sigma(x)L(x)}$$ multiplied by visible percent $$\color{blue}{T(x)}$$ at distance $$x$$ integrated on ray. With two or more fogs we get multiple scatterings so equations become: $$T(x)=e^{-\int_0^x\sum_0^n\sigma_i(x)dx} = e^{-x\sum_0^n\sigma_i}$$ $$L(t)=L_p\color{red}{T(t)} + \int_0^t\color{blue}{T(x)}\sum_0^n\color{green}{\sigma_i(x)L_i(x)}dx=L_p\color{red}{T(t)} + \sum_0^n\color{green}{\sigma_iL_i}\int_0^t\color{blue}{T(x)}dx$$

All assuming that $$\sigma_i$$ and fog color $$L(x)$$ are constant across ray.

The final equation for two fogs, after resolving $$\int_0^t\color{blue}{T(x)}dx$$ will become. $$L(x)=L_p\color{red}{T(t)} + (\color{green}{\sigma_0L_0 + \sigma_1L_1})\color{blue}{\frac{1-T(t)}{\sigma_0+\sigma_1}}$$

It's the same equation as in Deep Compositing. After combining it with Lie group/algebra it is possible to integrate only parts of fogs.

Of course this integration isn't 100% correct if you have more complicated fog with not constant density etc.