Hacker News new | past | comments | ask | show | jobs | submit login

A very small piece of advice which I don't see mentioned here: OpenGL works in linear RGB (which is very convenient), while your monitor displays sRGB (which gives you better colour resolution due to how eyes work). This means that outputting the result of OpenGL directly on your screen is wrong (a lot dimmer than it should be). Use this little fragment in all your shaders to convert the final output to sRGB:

    vec3 srgb(vec3 rgb) {
        vec3 mask = vec3(greaterThan(rgb, vec3(0.0031308)));
        return mix(rgb * 12.92,
                   pow(rgb, vec3(1.0 / 2.4)) * 1.055 - 0.055,
                   mask);
    }
Edit: Here's a very good example of the difference https://imgur.com/a/g6qNI

Edit 2: And of course when you load textures you must tell OpenGL they're in sRGB colourspace (most probably they are, if you created them on a normal monitor), so it will do the reverse transformation when reading from the texture. All this trouble could have been avoided if monitors were 30bit linear RGB colourspace to begin with, but that's history now. C'est la vie.





So you're saying that in my shaders, as long as I have GL_FRAMEBUFFER_SRGB enabled, this conversion takes place automatically? Am I understanding the docs right?

I'm asking because I'm a mobile game developer using Unity3d, and we have a fair amount of custom shaders, and I've never heard about this sRGB vs RGB colorspace thing before so I want to investigate. There's not much on google for GL_FRAMEBUFFER_SRGB + Unity3d. Maybe it's handled automatically or it's not even possible with openGL ES 2.0.


The implicit conversion only happens when the internal format of the destination buffer is GL_SRGB8 or GL_SRGB8_ALPHA8


Here's a bunch of shader code and examples for different tone-mapping operators. I really like the Hejl/Burgess-Dawson one as a simple Linear -> sRGRB-ish output function.

http://filmicgames.com/archives/75




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: