I am encountering some problems with full-scene blending using render to 
texture. It appears that the blend operation is reading the main scene data as 
being completely blank (ie. matching the clear colour). I have already spent a 
fair few hours trying to solve this on my own, and I was wondering if anyone 
has any tips that may help me track down the cause. Frustratingly, I seem to be 
stuck on the easy part of the problem (the blending), but not on the more 
difficult part (the render to texture).

What I am doing is as follows:

I have created an osgViewer::Viewer (viewer), and a main camera (mcam), and an 
empty owg::Group (root), and attached the latter two to the first 
("viewer.setCamera(mcam)", "viewer.setSceneData(root)"). I have created a 
second camera (ovcam) which manages CEGUI, and attached it to the root 
("root.addChild ovcam"). I mention CEGUI only in case it is interfering with 
the rest somehow.

I set up a scene, which is basically an osg::Group with a bunch of children. 
This is added to the "root" group. Later on, after some updates, I create a new 
scene, add that to "root", remove the first from "root", and set up a 
render-to-texture camera. The means of doing this is roughly based upon the 
code here:

http://sourceforge.net/apps/mediawiki/delta3d/index.php?title=Tutorial_Render_To_Texture

Both cameras are added to "root". I am uncertain if the resultant structure is 
correct and would welcome suggestions. I have tried experimenting with the 
structure but have either been met with crashes or it does not solve the 
problem. I suspect it may be related though.

The RTT texture camera has the render order set to PRE_RENDER, the blending 
camera is set to POST_RENDER. The main scene uses the default render order, 
which should lie between the two (is this right?).

The problem occurs when I try to blend the result into the main scene.

The plan is to render the RTT quad with a variable alpha value to manage the 
fade. For now, I'm just rendering the RTT quad over a section of the main view 
(I'll call that the "box"), and using a BlendFunc of 
CONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHA. Setting the alpha value with 
BlendColor affects the result roughly as you'd expect. I'm just using a fixed 
value for now (until I get it working, of course). The colours in the source 
image (the image rendered to the texture) seem to come through fine, but the 
target colour always seems set to the clear colour of the main camera. To 
explain further:

- Using CONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHA, if you drop the constant alpha 
down lower, the prerendered image in the box becomes fainter, eventually fading 
to the main camera solid clear colour. This is only correct behaviour if the 
main scene was completely blank (ie. solid clear colour). It should be fading 
out to the main scene.
- If you blend with ONE/ZERO, you get the RTT image untouched (but not blended) 
in the box. This is expected, and confirms the RTT step is working correctly 
(ie. the scene rendered to texture is entirely correct). The result is the same 
with CONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHA and alpha 1.0.
- If you blend with ZERO/ONE, you get a solid box matching the clear colour. It 
should get the image from the main scene (ie. you should not be able to see the 
box at all). The result is the same with 
CONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHA and alpha 0.0.
- If you change the clear colour for the main camera, the colour of the box for 
ZERO/ONE matches, which is the basis behind my theory that the destination 
colour is always being read by the blend function, rather than the scene data.

If I had to guess as to what the problem may be, I would guess:

- I am setting up the scene graph containing the cameras incorrectly to ensure 
they are rendering in the correct order. It is almost as if the blending camera 
(set to POST_RENDER) is rendering *before* the main scene camera, but after the 
clear for that camera.
- I am missing something that is causing the blend function to use the wrong 
destination data as the destination input to the blend function. Perhaps I am 
not enabling something that needs enabling, or have not correctly specified 
where the destination input data should come from.

I have been experimenting on these fronts (and others), trying to guess the 
correct way to do things. I have been unsuccessful so far. I think I have 
correctly isolated the problem as the destination input for the blend function 
as being incorrect. I am just not sure what to change to correct it.

Any advice or pointers appreciated. I'm sure it's something simple that I have 
overlooked. Please feel free to ask any questions to clarify what I am doing.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44081#44081





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to