Ok, I updated my code to just use 2 textures attached to the camera (COLOR_BUFFER and DEPTH_BUFFER), and a fragment shader to set gl_FragColor.xyz = texture(depth).aaa , and that seems to work when I set my implementation to FRAME_BUFFER_OBJECT.

However, I had to add another slave camera to the view to display the Color channel (same as above, but no fragment shader).  This works too, and is in fact what I wanted to do (later on, I'l be distorting these images so a simple screen-quad won't be the actual use).  However, I have a "random noise" window that's the default camera.  I set windowDecorations and such to false, but it's still there (hidden behind my other camera displays).  Is there any way to hide it? I tried setting pbuffer=true on that gc, but then the whole app dies (I get blank textures everywhere).

September 14, 2012 6:54 AM
Alright, I thought that might be the answer..

As for FBO vs PBuffer, I'm running right now on a LAte 2011 MAcbook Pro, with the ATI chipset..  I thought FBO's were supported but maybe not...

Sergey Polischuk wrote:
September 14, 2012 6:51 AM
followup:
just use rgba texture for your case.

multiple render targets work only if you render stuff with shaders and in fragment shader output values separately for each render target with gl_FragData[attachment_index] = value; (instead of gl_FragColor or whatever). As i've said, all render targets should have same size, format, and channels count for this setup, or you will get fbo setup errors.

Cheers.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
September 14, 2012 2:25 AM
Hi Randall

All color attachments must have same size, format, and channels count.

Cheers.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
September 13, 2012 11:29 PM
I'm trying to write a simple app to render a scene and drop out 3
buffers : Depth, Color (RGB), and Alpha. I've pasted the code below,
and there's an important DEFINE at the top: SHOW_ALPHA. If you set
SHOW_ALPHA to 0, that disables the COLOR_BUFFER1 (a GL_ALPHA texture
attachment to the main camera) and everything works perfectly. I set
that to 1, and then my visuals get all scrambled and I get the following
error messages:

RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x8cdd
Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
multiple color outputs.
Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
multiple color outputs.
RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x8cdd
Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
multiple color outputs.
Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
multiple color outputs.

Now, I think I can accomplish what I want using a single RGBA texture
and a fragment shader to pull out the A. Am I doing something wrong, or
is the fragment-shader route the "right" way to go?

Code below:


#include <osgViewer/Viewer>

#include <osg/BlendFunc>
#include <osg/Geode>
#include <osg/TexGen>
#include <osg/Texture2D>
#include <osg/MatrixTransform>
#include <osg/LightModel>
#include <osg/Material>
#include <osgGA/NodeTrackerManipulator>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

#define SHOW_ALPHA 0
#define SHOW_DEPTH 1
#define HEIGHT_OFFSET 24

int main(void) {

int width=512, height=256;
osg::ref_ptr<osg::Geode> screenQuad = new osg::Geode;

osg::ref_ptr<osg::Texture2D> __depthTexture = new osg::Texture2D();
osg::ref_ptr<osg::Texture2D> __maskTexture = new osg::Texture2D();
osg::ref_ptr<osg::Texture2D> __colorTexture = new osg::Texture2D();
osg::ref_ptr<osg::Node> model =
osgDB::readNodeFile("/Users/rhand/Documents/MagicLeap/data/MLOS-Logo.obj");
osgViewer::Viewer V;
osg::ref_ptr<osg::Group> group = new osg::Group();

//model->getOrCreateStateSet()->setMode(GL_,osg::StateAttribute::OFF);

model->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);

model->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);

V.getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
V.getCamera()->setClearDepth(1.0);
V.getCamera()->setClearColor(osg::Vec4(0,0,0,0));
group->addChild(model.get());
V.setSceneData(group.get());

// Establish the "base" Graphics Context
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = HEIGHT_OFFSET;
traits->width = width;
traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0; // Doesn't inherit from anything
traits->vsync = true; // Disable VSync (for now)
traits->supportsResize = false;
traits->windowName = "Color";
osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get());

{
__depthTexture->setTextureSize(width,height);
__depthTexture->setInternalFormat(GL_DEPTH_COMPONENT);

__depthTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);


__depthTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);

__depthTexture->setDataVariance( osg::Object::DYNAMIC );
__depthTexture->setResizeNonPowerOfTwoHint( false );

__maskTexture->setTextureSize(width,height);
__maskTexture->setInternalFormat(GL_ALPHA);

__maskTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);


__maskTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);

__maskTexture->setDataVariance( osg::Object::DYNAMIC );
__maskTexture->setResizeNonPowerOfTwoHint( false );

__colorTexture->setTextureSize(width,height);
__colorTexture->setInternalFormat(GL_RGB);

__colorTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);


__colorTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);

__colorTexture->setDataVariance( osg::Object::DYNAMIC );
__colorTexture->setResizeNonPowerOfTwoHint( false );

osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
__camera->setGraphicsContext(gc.get());
__camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
__camera->setViewport(new osg::Viewport(0,0, traits->width,
traits->height));

__camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
__camera->setProjectionMatrixAsPerspective(70,(height/width),
1,200);
__camera->setClearDepth(1.0);
__camera->setViewMatrixAsLookAt( osg::Vec3(0,0,0),
osg::Vec3(0,100,0), osg::Vec3(0,0,1) );
__camera->setRenderOrder(osg::Camera::PRE_RENDER);

__camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
__camera->attach(osg::Camera::COLOR_BUFFER0, __colorTexture);
#if SHOW_DEPTH
__camera->attach(osg::Camera::DEPTH_BUFFER, __depthTexture);
#endif
#if SHOW_ALPHA
__camera->attach(osg::Camera::COLOR_BUFFER1, __maskTexture);
#endif
V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd());
}
{ // Make the re-usable Quad for displaying the textures
// Make the quad with a little 10px border around the edges, for
debugging

osg::ref_ptr<osg::Drawable> quad = osg::createTexturedQuadGeometry(
osg::Vec3(10,10.0,0),
osg::Vec3(width-20,0,0),osg::Vec3(0,height-20,0),
0, 0, 1, 1);
quad->setDataVariance( osg::Object::STATIC ); // This is
_always_ a screen-aligned quad
quad->setUseDisplayList( true );
osg::StateSet* ss = quad->getOrCreateStateSet();
ss->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
ss->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
ss->setMode(GL_BLEND, osg::StateAttribute::ON);
ss->setAttribute(new osg::BlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA), osg::StateAttribute::ON);
// Put the quad in a Geometry Node (Geode) and configure it for
Texture coordinates
//osg::ref_ptr<osg::Geode> *geode = new osg::Geode;
screenQuad->addDrawable( quad.get() );
}

#if SHOW_DEPTH
{ // Display the Depth MAsk
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = height + (HEIGHT_OFFSET*3);
traits->width = width;
traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = gc.get();
traits->vsync = true; // Disable VSync (for now)
traits->supportsResize = false;
traits->windowName = "Depth";
osg::ref_ptr<osg::GraphicsContext> this_gc =
osg::GraphicsContext::createGraphicsContext(traits.get());

// now create a camera
// It's an orthographic 2D camera (sized to pixel match)
// Load an identity view matrix, and set the only geometry here
to be the quad
osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
__camera->setGraphicsContext(this_gc.get());
__camera->setViewport(new osg::Viewport(0,0, width, height));
__camera->setClearMask(GL_COLOR_BUFFER_BIT);
__camera->setClearDepth(1.0);
__camera->setClearColor(osg::Vec4(1,0,0,0)); // Red border
__camera->setRenderOrder(osg::Camera::POST_RENDER);

__camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
__camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
__camera->setViewMatrix(osg::Matrix::identity());
__camera->addChild(screenQuad.get());
osg::StateSet *ss = __camera->getOrCreateStateSet();
ss->setTextureAttributeAndModes(0, __depthTexture,
osg::StateAttribute::ON);

V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
}
#endif
#if SHOW_ALPHA
{ // display the Alpha mask
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 2*height+ 4*HEIGHT_OFFSET;
traits->width = width;
traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = gc.get();
traits->vsync = true; // Disable VSync (for now)
traits->supportsResize = false;
traits->windowName = "alpha";
osg::ref_ptr<osg::GraphicsContext> this_gc =
osg::GraphicsContext::createGraphicsContext(traits.get());

// now create a camera
// It's an orthographic 2D camera (sized to pixel match)
// Load an identity view matrix, and set the only geometry here
to be the quad
osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
__camera->setGraphicsContext(this_gc.get());
__camera->setViewport(new osg::Viewport(0,0, width, height));
__camera->setClearMask(GL_COLOR_BUFFER_BIT);
__camera->setClearDepth(1.0);
__camera->setClearColor(osg::Vec4(0,0,0,0));
__camera->setRenderOrder(osg::Camera::POST_RENDER);

__camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
__camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
__camera->setViewMatrix(osg::Matrix::identity());
__camera->addChild(screenQuad.get());
osg::StateSet *ss = __camera->getOrCreateStateSet();
ss->setTextureAttributeAndModes(0, __maskTexture,
osg::StateAttribute::ON);

V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
}
#endif
{ // display the Color mask
// now create a camera
// It's an orthographic 2D camera (sized to pixel match)
// Load an identity view matrix, and set the only geometry here
to be the quad
osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
__camera->setGraphicsContext(gc.get());
__camera->setViewport(new osg::Viewport(0,0, width, height));
__camera->setClearMask(GL_COLOR_BUFFER_BIT);
__camera->setClearDepth(1.0);
__camera->setClearColor(osg::Vec4(0,0,0,0));
__camera->setRenderOrder(osg::Camera::POST_RENDER);

__camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
__camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
__camera->setViewMatrix(osg::Matrix::identity());
__camera->addChild(screenQuad.get());
osg::StateSet *ss = __camera->getOrCreateStateSet();
ss->setTextureAttributeAndModes(0, __colorTexture,
osg::StateAttribute::ON);

V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
}


V.run();
}


--
Randall Hand
http://www.yeraze.com

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

Reply via email to