Author Topic: blend framebuffers  (Read 4719 times)

Offline madmadmax

  • byte
  • *
  • Posts: 4
    • View Profile
blend framebuffers
« on: July 24, 2007, 06:57:07 pm »
Hello,

I want to do the following:
1. draw a scene into a framebuffer f1
2. draw the scene a second time into another framebuffer f2 with a different glColorMask, so that only the red color parts are drawn
3. blend f2 over f1, so that f1 shines through f2
Is this possible? Point 1. and 2. are easy, however I'm not sure how to do 3  ???

Thanks in advance,
mmm

PS: Happy Birthday  ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blend framebuffers
« Reply #1 on: July 24, 2007, 07:26:03 pm »
You can copy the first FrameBuffer's content into a texture if the hardware supports GL_TEXTURE_RECTANGLE_EXT and draw that copy over the second buffer in another run. But you can't do this with the means jPCT offers, you have to use native OpenGL for it. I can post the sources for the BloomGLProcessor, which does some of these steps, if you are interested.

Offline madmadmax

  • byte
  • *
  • Posts: 4
    • View Profile
Re: blend framebuffers
« Reply #2 on: July 24, 2007, 08:46:58 pm »
Egon, thanks for your quick reply!
I just thought of a better way to achieve the same effect as described in my previous post. If the world is rendered twice into same framebuffer, whereby the depth buffer is cleared in between, it should be the same (If the world is set transparent the second time). In a first step I tried without transparency. The below code snippet shows this, the world is drawn the second time a bit rotated to see the effect. I would assume that the world drawn in red (because of glColorMask) would win in the Z-Buffer, because it is drawn after the world drawn in white, however it gets blended over the white rectangle (As can be seen in the image).

Code: [Select]
      buffer.clear();     

      GL11.glColorMask(true,true,true,false);
     
      world.renderScene(buffer);
      world.draw(buffer);
      buffer.update();
           
      buffer.clearZBufferOnly();
 
      camera.rotateY(-rot);
     
      GL11.glColorMask(true,false,false,false);
     
      world.renderScene(buffer);
      world.draw(buffer);
      buffer.update();
           
      camera.rotateY(rot);
     
      GL11.glColorMask(true,true,true,false);
      buffer.displayGLOnly();

The image:
[img=http://img523.imageshack.us/img523/7402/effectmr2.th.jpg]

Thanks for any suggestions!


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blend framebuffers
« Reply #3 on: July 24, 2007, 09:19:39 pm »
The problem with this approach is, that you can disable a color channel so that it's not going to be written. But what is already in there remains. When writing a (100,120,180)-pixel with only red enabled to a (190,60,80)-pixel in the framebuffer the resulting pixel is (100,60,80), i.e. the new value for red, the old ones for all other components. That's what causes the "blending", because you are actually mixing the colors.
However, i'm not really sure how you want your rendering to look like. Maybe you can fake a screen shot that shows the final result so that one can imagine what's your goal.

Offline madmadmax

  • byte
  • *
  • Posts: 4
    • View Profile
Re: blend framebuffers
« Reply #4 on: July 24, 2007, 10:35:08 pm »
Of course! Thanks for pointing out my stupidity  :P

Here's an image of what I want:
[img=http://img464.imageshack.us/img464/2789/unbenannt1jh5.gif]

This could be achieved by drawing the red object transparent over the white object. However I'm not really sure how to draw a transparent Object3D. If I use setTransparent with a value of 0, the object gets transparent, but not as much as I desire. Transparency also is only possible in about 5 steps (from 0-5) Is it because my 3ds object is created in the wrong way? Is there a thread that describes how such transparent objects are made for the jpct 3ds loader?
Thanks for the awesome support of yours, Egon!

Offline madmadmax

  • byte
  • *
  • Posts: 4
    • View Profile
Re: blend framebuffers
« Reply #5 on: July 24, 2007, 10:44:29 pm »
I found the answer how the opacity level for object3d can be controlled: One has to tweak Config.glTransparencyOffset and Config.glTransparencyMul (for opengl renderer).
Once again, thanks for the great support!