Piecewise Hyperbolic Tonemap

Hyperbolic tonemap function with linear section, solved for mid-grey and peak-white intersections.

It is based on a very simple shifted and scaled hyperbola.

We start with a hyperbola in the simple form

$$ h\left(x\right)=-\frac{a}{x} $$

$a$ is our input domain (x) scale. We'll need to offset the hyperbola in x and y though. We'll add $h_0$and $h_1$ parameters to achieve this.

$$ c(x)=h_1-\frac{a}{x-h_{0}} $$

The inverse of this equation is very simple. We just swap the positions of $h_0$ and $h_1$.

$$ i(x)=h_0-\frac{a}{x-h_{1}} $$

First we need to calculate the derivative so that we can find the x,y coordinate for a specific slope in the equation h(x). The derivative is $d\left(x\right)=\frac{a}{x^{2}}$

From this we can solve the derivative for a specific slope $b$: Solving for x in $b=\frac{a}{x^{2}} : x=\sqrt{\frac{a}{b}}$

Substituting our solve for x into the original equation h(x), we get $\left(\sqrt{\frac{a}{b}},-\sqrt{ab}\right)$

To have a piecewise linear section in our hyperbolic compression, we'll need to offset that start point of our hyperbola to some xy coordinate. $x=t_1, y=bt_1$, where $t_1$is the x threshold value.

This gives us a solve for our x y offsets:

$$ h_{0}=-\sqrt{\frac{a}{b}}+t_{1} ; h_{1}=\sqrt{ab}+bt_{1} $$

Here is a desmos plot with an interactive graph:

https://www.desmos.com/calculator/9ogmshyuwe

Tonemap Function

To make this a proper tonemap function we need to solve for intersection points, so that we can precisely map an input scene-referred grey value $g_0$ to an output display-referred grey value $g_1$, and an input scene-referred peak white value $r_0$ to an display-referred peak white value $r_1$.