• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hodgman

sRGB approximations

5 posts in this topic

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 ([i]~4/255[/i]) 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
0

Share this post


Link to post
Share on other sites
How much fidelity do you need? You could simply go with the old school technique of a sample from a 1D texture lookup table.
1

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
Thanks for the replies.
[quote name='Promit' timestamp='1332480381' post='4924527']How much fidelity do you need? You could simply go with the old school technique of a sample from a 1D texture lookup table.[/quote]Just enough for the game to look ok on a TV, and for the artist to not complain.
The tone-mapping pass ([i]linear->gamma[/i]) is ALU bound, not texture bound, so a LUT could be a good idea there. However, the forward passes ([i]gamma textures->linear[/i]) are very sensitive to extra texture fetches at the moment.
[quote name='Chris_F' timestamp='1332490015' post='4924549']
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.[/quote]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.
[quote name='mikiex' timestamp='1332625995' post='4924980']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.[/quote]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 [img]http://public.gamedev.net//public/style_emoticons/default/unsure.png[/img]
Left is my quadratic, right is gamma 2.2:
[img]http://img3.imageshack.us/img3/2682/gammatest.png[/img]
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0