0

Here's my problem.

I'm rendering an orthogonal quad (filling the viewport) before everything (with vertex coloring at each corner), right after I'm rendering a cube skybox with 6 transparent polygons (GL_BLEND, source GL_ONE, dest GL_ONE). That works perfectly, the skybox is half-colored by the underneath quad and half-colored by it's own UV mapped textures.

The problem comes when I add the height-map (GL_BLEND, GL_ONE, ...) The height map blends with the skybox under + with the quad.

What I want is the height map to be blended with the ortho quad but not with the skybox. I don't want to see the skybox through the height map.

I'm sure there's another way for doing this.

Is it possible to render the ortho quad first and the skybox (like it's now) THEN the height map with a special blending that substract the skybox but not the ortho quad with some kind of multipass blending ?

Thank you very much !

Dimitri

2 Answers2

2

Your glBlendFunc with GL_ONE, GL_ONE is called additive blending, and has the nice property (like any addition) to be commutative, that is to say A+B = B+A.

You could then draw your things in the other order, and your blending would give the same result.

In your case, you could draw your height map, and your skybox, without blending ; then your fullscreen quad with blending.

To prevent the height map and skybox to overlap, you could either :

  • draw your skybox first, and then your height map
  • draw the other way around, with GL_DEPTH_TEST enabled to let the Z buffer sort the pixels visibility for you

Hope this helps

rotoglup
  • 5,223
  • 25
  • 37
0

OpenGL is no a scene graph, so after each rendering step all further commands on all the existing contents. glBlendFunc(GL_ONE, GL_ONE); doesn't sound right anyway, unless you really want to add the values. I think you're looking for glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Do you have any idea how I could do this ? Is there some algorithm to clip the hidden parts of the skybox polygon into smaller one which I could prevent from rendering ? I'm probably not the first to encounter the case where multiple transparent thing conflict with others. – dimcaron144 Feb 26 '11 at 21:31
  • For blending to work properly you must sort the parts back to front. Next you surely don't want to use GL_ONE, GL_ONE blending function, as this will cause things to "shine through". I'm pretty sure you want some alpha channel controlled blending (so far you're not using the alpha channel). – datenwolf Feb 26 '11 at 22:22