blend framebuffers

Started by madmadmax, July 24, 2007, 06:57:07 PM

Previous topic - Next topic

madmadmax

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  ;)

EgonOlsen

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.

madmadmax

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).


      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!


EgonOlsen

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.

madmadmax

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!

madmadmax

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!