[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Gamma correction and texImage2D/texSubImage2D



 On 07/09/2010 16:58, Thatcher Ulrich wrote:
> On Tue, Sep 7, 2010 at 4:21 AM, Mark Callow <callow_mark@hicorp.co.jp> wrote:
>> On 06/09/2010 18:54, Thatcher Ulrich wrote:
>>> Actually, an app author can do this directly in their fragment shader.
>>>  Just do "gl_FragColor = pow(linear_rgb, 1.0 / 2.2);" at the end of
>>> the shader.  When/if WebGL exposes EXT_framebuffer_sRGB, the hardware
>>> can do this more cheaply (and perhaps more exactly) using a lookup
>>> table.
>> Subsequent blending and anti-aliasing will then be mathematically and
>> visually incorrect. Blending and especially anti-aliasing must be done
>> in a physically linear space.
> You say they "must" be done in a physically linear space, and yet in
> practice no system works this way unless EXT_*_sRGB are enabled, or
> unless the shaders are written to work around this.
I repeat. All the math. in the OpenGL spec. including blending is
predicated on using a physically linear space. If you do it in a
perceptually linear space the results are wrong. Doing the conversion in
the fragment shader means the renderbuffer contents are converted before
blending and anti-aliasing, ergo the results are incorrect.

You are incorrect in stating that in practice no system works this way
(in linear space). All SGI systems had gamma correctors so computations
could be done in linear space and the results converted on output to the
display. This is because as authors of IRIS GL and later OpenGL, we
understood that the math is only correct in a linear space. A good
number of desktop video cards in modern PCs have gamma correctors,
although it is not immediately clear how many GL or D3D drivers turn
them on.
>> Doing what you suggest is only correct if
>> blending is disabled or is blend equation and func are set such that the
>> destination is replaced by the source color.
> Yes -- sorry to be the bearer of bad news.  EXT_*_sRGB are designed to
> correct this.
If you are using an SRGB8_ALPHA8 renderbuffer then there is no need to
do conversion in the fragment shader and my comment becomes irrelevant.
That is hardly bad news.

Regards

    -Mark

begin:vcard
fn:Mark Callow
n:Callow;Mark
org:HI Corporation;Graphics Lab, Research & Development
adr:Higashiyama 1-4-4, Meguro-ku;;Meguro Higashiyama Bldg 5F;Tokyo;;153-0043;Japan
email;internet:callow_mark@hicorp.co.jp
title:Chief Architect
tel;work:+81 3 3710 9367 x228
tel;fax:+81 3 5773 8660
x-mozilla-html:TRUE
url:http://www.hicorp.co.jp,  http://www.mascotcapsule.com
version:2.1
end:vcard