黎明的剔透里伸出了你沁清的暧昧

Graphics|EngineDev|GameDev|2D&3D Art

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  60 随笔 :: 1 文章 :: 18 评论 :: 0 Trackbacks


image

在计算机图形学领域时常听到gamma correction ,gamma correction 控制了图像整体的亮度,reproduce colors也需要gamma correction的一些理论知识,gamma correction不仅仅是控制了图像的亮度,而且还控制了RGB各个分量的比例,我们知道渲染器是线性的,而显示器并非线性,其实电子打在屏幕上从而产生亮点,电子的运动受电压控制,这两者是指数关系的,所以产生的亮度也跟电压成指数关系,而发送给显示器的voltages范围是0~1:

image

image

对于我们输入的图像,如果直接显示,那么就会篇暗,根据已知电压与显示亮度的关系,进行gamma correction ,其实就是对gamma曲线的修正。一般生产厂家不加说明,他们的伽码值大约等于2.5.

image

image

代码:

   gammaCorrection = 1 / gamma
   colour = GetPixelColour(x, y)
   newRed   = 255 * (Red(colour)   / 255) ^ gammaCorrection
   newGreen = 255 * (Green(colour) / 255) ^ gammaCorrection
   newBlue  = 255 * (Blue(colour)  / 255) ^ gammaCorrection
   PutPixelColour(x, y) = RGB(newRed, newGreen, newBlue)

知道monitor不是一个线性的,那么我们在进行颜色加法时,我们得到的颜色并不是真正的颜色值的相加,比如gamma factor是2.2

red = add (r1, r2);

red= add (0.235,0.156);

对于一个线性设备,red = 0.391,对于未经修正的montior red=0.126;

因为有一个幂函数的运算:C_out = C_in2.2

现在使用gamma correction :C_corrected= C_out1.0/2.2

0.3912.2 = 0.126

0.1261.0/2.2 = 0.39

我们看到使用伽码校正以后我们能得到我们预想的颜色值0.39.

 

imageimage

 

imageimage

 

imageimage

 

 

There are two ways to do gamma correction:

  • Using the renderer. The renderer (the graphics card or GPU) is a linear device. Modern renderers have the support of gamma correction via sRGB textures and framebuffer formats. See the following OpenGL extensions for more details: GL_ARB_framebuffer_sRGB and GL_EXT_texture_sRGB. With these extensions you can get gamma corrected values for free but gamma correction factor is set to 2.2. You can’t change it.
  • Using a software gamma correction. The gamma correction is applied to the final scene buffer thanks to apixel shader and you can set the gamma correction you want.

In OpenGL, using GL_ARB_framebuffer_sRGB is really simple: once your FBO is bound, just enable the sRGB space with

glEnable(GL_FRAMEBUFFER_SRGB);
 
gamma-correction
posted on 2012-11-15 23:05 情绝格调(fresmaster) 阅读(1597) 评论(1)  编辑 收藏 引用 所属分类: GraphicsDocuments

评论

# re: Gamma Correction 2014-07-09 11:35 tzzhwj
谢谢你的劳动  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理