I've got a particle system being rendered on top of a background texture. Each particle is a square and has no texture applied to it and they are all the same color. The background is a grayscale texture. What I'm trying to achieve is the same type of blending, known in applications such as Gimp, as color blend mode.
Basically, the area of the background covered by a particle should maintain it's luminance, but adopt the color of the particle. I've tried several combinations of parameter of glBlendFunc() and tried messing around with glTexEnv, but I'm having a lot of trouble understanding it. Currently, if two particles overlap, they either become brighter or darker (depending on the glBlendFunc parameters).
I'm using OpenGL ES 1.1 on android. Is there any way of achieving this effect without having to use OpenGL ES 2.0? If so, what is it?
glBlendFunc only supports separable blend modes. Hue-only blending is non-separable, so it cannot be expressed in standard OpenGL. See this presentation by Nvidia's Mark Kilgard, slide 41.
Nvidia provides an extension on its newer GPUs (incl. Tegra), called NV_blend_equation_advanced which adds the GL_HSL_HUE_NV
and GL_HSL_COLOR_NV
tokens to perform the operation you are describing. Given that you wish to maintain support for OpenGL ES 1.1, this is not actually an option for you.
However, there may be a way to achieve the effect you are describing, given that your background is grayscale:
glBlendFunc(GL_DST_COLOR, GL_ZERO)
This should maintain luminance while painting the background with the color of the particle.
Edit: glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR)
would give 2 * source * destination color which might help.
Edit 2: try glTexEnvf as follows
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
It has been more than a decade since I last used glTexEnv, but there might be a combination of parameters that can achieve what you are trying to do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.