Original Post
These days, "gamma correct rendering" (or, doing your shading math in linear space) is standard. It's also easy to implement due to the fact that modern GPUs support [font=courier new,courier,monospace]linear->sRGB[/font] and [font=courier new,courier,monospace]sRGB->linear[/font] transformations in hardware.
...however, I'm supporting some old GPU's that don't provide this hardware. The standard solution here is to pretend that [font=courier new,courier,monospace]sRGB[/font] is the same as [font=courier new,courier,monospace]gamma[sup]2.2[/sup][/font] colour space, and use [font=courier new,courier,monospace]pow(y, 1/2.2)[/font] and [font=courier new,courier,monospace]pow(x,2.2)[/font] to perform [font=courier new,courier,monospace]linear->gamma[sup]2.2[/sup][/font] and [font=courier new,courier,monospace]gamma[sup]2.2[/sup]->linear[/font] conversions.
..however, these old GPU's are also pretty slow at implementing [font=courier new,courier,monospace]pow[/font], so I'm looking for other sRGB approximations. The best I've come up with is the quadratic below, but I'd appreciate any other links/hints on the subject!
From gamma-space to linear-space:
[eqn]y = x^{2.2}[/eqn]
[eqn]y \approx x^2 \cdot 1.08933 - x \cdot 0.0893293[/eqn]
Correct for 0.0 and 1.0
Maximum error of 0.0149833 (~4/255) at x=0.706.
Cost: 2x mul, 1x madd
Reverse transform (linear-space to gamma-space):
[eqn]x = y^{1/2.2}[/eqn]
[eqn]x \approx 0.0410019+4.58998 \cdot 10^{-8} \cdot \sqrt{7.97972 \cdot 10^{11}+4.35732 \cdot 10^{14} y}[/eqn]
Cost: 2x madd, 1x sqrt
...however, I'm supporting some old GPU's that don't provide this hardware. The standard solution here is to pretend that [font=courier new,courier,monospace]sRGB[/font] is the same as [font=courier new,courier,monospace]gamma[sup]2.2[/sup][/font] colour space, and use [font=courier new,courier,monospace]pow(y, 1/2.2)[/font] and [font=courier new,courier,monospace]pow(x,2.2)[/font] to perform [font=courier new,courier,monospace]linear->gamma[sup]2.2[/sup][/font] and [font=courier new,courier,monospace]gamma[sup]2.2[/sup]->linear[/font] conversions.
..however, these old GPU's are also pretty slow at implementing [font=courier new,courier,monospace]pow[/font], so I'm looking for other sRGB approximations. The best I've come up with is the quadratic below, but I'd appreciate any other links/hints on the subject!
From gamma-space to linear-space:
[eqn]y = x^{2.2}[/eqn]
[eqn]y \approx x^2 \cdot 1.08933 - x \cdot 0.0893293[/eqn]
Correct for 0.0 and 1.0
Maximum error of 0.0149833 (~4/255) at x=0.706.
Cost: 2x mul, 1x madd
Reverse transform (linear-space to gamma-space):
[eqn]x = y^{1/2.2}[/eqn]
[eqn]x \approx 0.0410019+4.58998 \cdot 10^{-8} \cdot \sqrt{7.97972 \cdot 10^{11}+4.35732 \cdot 10^{14} y}[/eqn]
Cost: 2x madd, 1x sqrt
