1

I'm woking on a scientific visualisation using openGL where I try to basically create a "coloured fog" to illustrate a multidimensional field. I want the hue of the color to represent the direction of the field and the luminosity of the color to correspond to the intensity of the field.

I use GL_BLEND with glBlendFunc(GL_ONE, GL_ONE) to achieve additive blending of colors of the surfaces I create. The problem is: in some places the colors get saturated. For example:
(1, 0, 0) + (1, 0, 0) = (2, 0, 0), and when this is rendered it just becomes (1, 0, 0) (i.e. the "overflow" is just chopped off). And this is not the way I would like it to be handled. I would like to handle the overflow by preserving hue and luminocity, i.e.

(2, 0, 0) should be translated into (1, 0.5, 0.5) (i.e. a lighter red, red with twice the luminocity of "pure" red).

Is there any way to achieve this (or something similar) with OpenGL?

4

1 回答 1

1

如果目标缓冲区的图像格式具有标准化格式(例如 UNSIGNED_BYTE),片段着色器的输出将被限制为 [0, 1]。如果您使用浮点格式,则不会限制输出。请参阅混合图像格式

通过混合不支持的功能混合目标缓冲区和颜色是很棘手的。一个可能的解决方案可能是使用着色器程序并使用扩展EXT_shader_framebuffer_fetch

此外,扩展KHR_blend_equation_advanced添加了许多“高级”混合方程,如HSL_HUE_KHRHSL_SATURATION_KHR和。HSL_COLOR_KHRHSL_LUMINOSITY_KHR

于 2020-05-20T08:19:14.320 回答