简体   繁体   中英

Opengl, Ruby, glBlendFunc: place transparent images on top of each others as if it was opaque

I'm not sure if glBlendFunc is the great function to resolve my problem, but I think that I'll need it! Here is my problem:

在此输入图像描述

You see the two pine trees' reflects on the right? I'd like to have something like that:

在此输入图像描述

Then, I need a method which is doing the same display than for an opaque image, but with transparent image. Is there a special combination in the glBlendFunc, or should I proceed by other means?

I don't think a pure blending approach will work. In the case where you have the two overlapping tree reflections, the first one is blended with the water after it was rendered. When you draw the second tree, you would want only the second tree blended with the water. But the color of the water in the framebuffer was already blended with the first tree, so the water color alone is not in the framebuffer anymore.

Three approaches come to mind:

  1. Draw all the tree reflections into an FBO, without blending. Then draw the result on top of the water, with blending enabled.

  2. Keep depth testing enabled (in case you currently have it disabled) while drawing the reflections. Draw the tree reflections front to back, with a slight offset relative to the water surface, and with the offset decreasing for each reflection drawn. So the reflections of the closer trees will hide the reflections of the trees that are farther away.

  3. Similar to option 2. But instead of an offset and depth test, use a stencil test to ensure that only one reflected tree is rendered at any pixel.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM