• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# sRGB approximations

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Hodgman  Moderators

Posted 22 March 2012 - 11:21 PM

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 linear->sRGB and sRGB->linear 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 sRGB is the same as gamma2.2 colour space, and use pow(y, 1/2.2) and pow(x,2.2) to perform linear->gamma2.2 and gamma2.2->linear conversions.

..however, these old GPU's are also pretty slow at implementing pow, 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:

Correct for 0.0 and 1.0
Maximum error of 0.0149833 (~4/255) at x=0.706.

Reverse transform (linear-space to gamma-space):

### #2Promit  Senior Moderators

Posted 22 March 2012 - 11:26 PM

How much fidelity do you need? You could simply go with the old school technique of a sample from a 1D texture lookup table.
SlimDX | Shark Eaters for iOS | Ventspace Blog | Twitter | Proud supporter of diversity and inclusiveness in game development

### #3Chris_F  Members

Posted 23 March 2012 - 02:06 AM

Does it really have to be sRGB?

You could store your textures with a gamma of 2.0, which should be much easier to convert in shader (2x mul to encode, 1x sqrt to decode) and still offers a good distribution of values. It would only require you to alter you asset pipeline.

### #4mikiex  Members

Posted 24 March 2012 - 03:53 PM

I'd be interested to see some comparisons visually as you have to be careful with approximations in Gamma as the error can be low - yet have a big effect. Microsoft used a piecewise approximation in the 360 which is not good at all - as John Hable explains
http://filmicgames.com/archives/14

### #5Hodgman  Moderators

Posted 04 April 2012 - 12:33 AM

Thanks for the replies.

How much fidelity do you need? You could simply go with the old school technique of a sample from a 1D texture lookup table.

Just enough for the game to look ok on a TV, and for the artist to not complain.
The tone-mapping pass (linear->gamma) is ALU bound, not texture bound, so a LUT could be a good idea there. However, the forward passes (gamma textures->linear) are very sensitive to extra texture fetches at the moment.

Does it really have to be sRGB?
You could store your textures with a gamma of 2.0, which should be much easier to convert in shader (2x mul to encode, 1x sqrt to decode) and still offers a good distribution of values. It would only require you to alter you asset pipeline.

Our textures are currently authored in 8-bit sRGB, so transforming the data into a different 8-bit gammma space is only going to lose information.
On the next project I'm pushing a 16-bit texture authoring pipeline, which would allow us to do things like this.

I'd be interested to see some comparisons visually as you have to be careful with approximations in Gamma as the error can be low - yet have a big effect.

I checked my approximation into source control and deliberately didn't tell the artists just to see if they'd notice. Three hours later, I'd been sent two almost-identical screenshots of the game, one from the previous build and one from the current build, and was being asked why the gamma had changed!

Below is a cropped version on that screenshot showing the problematic area. The rest of the image is mostly perfect, but there's a range of dark values that have all been squished together in my approximation
Left is my quadratic, right is gamma 2.2:

I'm going to tweak my coefficients some more and see if I can't get some better results in the blacks without ruining everything else.

### #6Zoner  Members

Posted 08 April 2012 - 03:43 PM

It is worth noting that the real sRGB equation has a linear toe to transition from the pow curve to 0. If you skip this step the values come out quite a bit brighter (much like the X360's piecewise linear sRGB snafu). In addition, if you use pow you will notice you also cant use a base of 0 (NaNs are returned as the pow intrinsic is doing an exp2 & log2 behind the scenes to do the pow). The traditional technique of setting a very tiny minimum allowed non-zero value for the base also causes true black to not ever be output, which does horrible horrible things to the image quality in dark scenes.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.