Hi,

On 13/12/10 12:26, Sajjadul Islam wrote:
Hi Delport,

Reasons for rendering the scene to two textrues

With key press event i may want to show the texture using the HUD
that have not gone through any operation. If i do any post processing
on the texture the initial texture value is lost. I want to preserve
it. This is why i render the same scene to two texture.

One Texture that contains the main scene and other texture also
contains the main scene but will go through further operation.

yes, I understand this, it's OK.


All the rendering are in PRE_ORDER except the HUD camera. HUD camera
is using the NESTED_RENDER.

OK, I just wanted to make sure you are not creating a loop and expecting OSG to figure out the render order based on how you connect input and output textures. OSG just traverses your cameras in the order you attach them to the scene (in the simplest case).


When the HUD camera is viewing any texture it is accessing the
texture as follows:

***************************************************************************'


................................

..............................

//the scene is passed to the followng class bp = new
BlurPass(subgraph,clearColour);

distortionNode->addChild(bp->getRoot().get());


...............................

//the following function is accessing the texture by checking first
the active switch node stateset->setTextureAttributeAndModes(0,
bp->getOutputTexture().get(),osg::StateAttribute::ON);
...................................

osg::ref_ptr<osg::Texture2D>  BlurPass::getOutputTexture() const {
int out_tex = _ActiveBranch;

return _ProcessPass[out_tex]->getOutputTexture(); }



//inside the BlurPass class i call the following function that make
one switch enables while making the other disabled - in other words
flip fllop

void BlurPass::activateBranch() { //GET THE current activate branch
int onb = _ActiveBranch;

osg::notify(osg::NOTICE)<<  "on bit "<<  onb<<  std::endl;

//get teh current inactive branch int offb = (onb == 1) ? 0 : 1;

osg::notify(osg::NOTICE)<<  "off bit "<<  offb<<  std::endl;

//make the active switch on _BranchSwitch[onb]->setAllChildrenOn();

//make the inactive switch off
_BranchSwitch[offb]->setAllChildrenOff(); }


void BlurPass::flip() { _ActiveBranch = (_ActiveBranch == 1) ? 0 :
1;

osg::notify(osg::NOTICE)<<"active branch"<<  _ActiveBranch<<
std::endl;

activateBranch(); }


BlurPass::BlurPass(osg::Node *scene, const osg::Vec4&clearColor)
:_SubGraph(scene), _ClearColor(clearColor) { //pre-define the
texture //width and height, the very same size //we preserve all over
the scene _TextureWidth = 1280; _TextureHeight = 1280;

//initially the shader is inactive shaderFlag = false;

_RootGroup = new osg::Group;

//initialize the texture where we //shall render the initial scene
createInputTexture();

//initialize the 2 output textures //which will be flipped with
keypress //for multipass blurring createOutputTextures();

//camera renders the scene to the 0-indexed texture //that will be
goiing through the blur phase in the process pass setupCamera();

//create two switch to do the flip-flop _BranchSwitch[0] = new
osg::Switch; _BranchSwitch[1] = new osg::Switch;


//add the camera and the two switches

//camera that renders the scene to the texture
_RootGroup->addChild(_Camera.get());


_RootGroup->addChild(_BranchSwitch[0].get());

_RootGroup->addChild(_BranchSwitch[1].get());

//initialize the active switch _ActiveBranch = 0;


//activate the switch based on the //current active branch flag
activateBranch();

//we have both input and output textures initialized and //the
_InOutTextureBlur[0] get the scene rendering that will //going
through the blur operation _ProcessPass[0] = new
ProcessPass(_OutTextureBlur[0].get(),_OutTextureBlur[1].get(),
_TextureWidth,_TextureHeight);

_ProcessPass[1] = new
ProcessPass(_OutTextureBlur[1].get(),_OutTextureBlur[0].get(),
_TextureWidth,_TextureHeight);

_BranchSwitch[0]->addChild(_ProcessPass[0]->getRoot().get());
_BranchSwitch[1]->addChild(_ProcessPass[1]->getRoot().get());


}

//setup the render to texture camera //the following function renders
the initial scene to 2 textures void BlurPass::setupCamera() {
_Camera = new osg::Camera;

_Camera->setClearColor(_ClearColor);
_Camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


//just inherit the main cameras view
_Camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
_Camera->setProjectionMatrix(osg::Matrixd::identity());
_Camera->setViewMatrix(osg::Matrixd::identity());


//set the viewport according to the value texture width and texture
height _Camera->setViewport(0,0,_TextureWidth,_TextureHeight);

//RENDER to texture before the main camera
_Camera->setRenderOrder(osg::Camera::PRE_RENDER);


//USE THE frame buffer object where supported
_Camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

 //the camera with  the relative frame renders to the input texture -
index 0 //this texture will be input for the process pass
_Camera->attach(osg::Camera::COLOR_BUFFER0,_InputTexture.get());


_Camera->attach(osg::Camera::COLOR_BUFFER1,_OutTextureBlur[0].get());

 //the sent subgraph will be rendered to the texture
if(_SubGraph.valid()) _Camera->addChild(_SubGraph.get()); else
osg::notify(osg::FATAL)<<  "Scene was not even created, camera has
nothing to work on"<<std::endl; }


Inside the constructor i initialize the _ActiveBranch to 0 so the
first Switch is enabled initially, i get the first pass operational.
With key press event i am enabling the second switch enabled while
making the first one disabled. And then the screen freezes. Then
again if i press the key the switch 0 is enabled  , i can see the
single blur pass again.

when you do the switch, do you change the texture that the HUD is displaying? Do again:
stateset->setTextureAttributeAndModes(0,
bp->getOutputTexture().get(),osg::StateAttribute::ON);

with getOutputTexture() returning the correct texture.

jp





****************************************************************************



If there is any flaw in design logic, please provide some hint .

Thank you!

Regards Sajjadul

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





_______________________________________________ osg-users mailing
list osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to