Hi, I set the color by using a fragment shader and the 32 bits floating point blending seems to be working now.
I would like to use multisampling in my FBO. How can I configure that? Is it only by setting the method: Camera::attach(BufferComponent buffer, osg::Texture* texture, unsigned int level, unsigned int face, bool mipMapGeneration, unsigned int multisampleSamples, unsigned int multisampleColorSamples) ? What is the difference between the parameter multisampleSamples and multisampleColorSamples? I tried to set both at 4 but that did not work. Tanks Jonathan On Tue, May 26, 2009 at 11:09 AM, Jonathan Richard < [email protected]> wrote: > Ok thank you for the advice. I'm not very familiar with the shader > programming yet, but I'm suppose to get into it soon. The problem that I see > is how to get access to the facet from the shader. If I'm into a fragment > shader I'll probably have no idea from which facet come each fragment. Is it > right? Maybe I have to use a geometry shader? Or maybe I can perform the > blending by myself into a fragment shader? You can tell me if you have any > clue about that. > > > I'll give you a little more of precision about my problem. The blending > seems to be working when the alpha of the front facet is different from 1. > For exemple if I define > > Rd = (2e-3, 0.0, 0.0, 1.0) // RGBA > > Rs = (6e-9, 0.0, 0.0, 0.4) //RGBA > > > In theory: > > Rd = Rs + (1-As)Rd > > Rd = 6e-9 + (1-0.4)*2e-3 = 1.200006e-3 > > In practice I get: 0.0012000059 > > > For now, the problem seems to occur only when As =1. > > > Thanks, > Jonathan > > > > > > > > > > 2009/5/26 J.P. Delport <[email protected]> > > Hi, >> >> Jonathan Richard wrote: >> > >> > |// Tell to sort the mesh before displaying it >> > |AFAIK OSG does not sort at the triangle level, there is an option to >> > make the sorting happen at a primitive level, but I think the default is >> > sorting on bounding sphere. >> > >> > I take this line (and the comment) from the osgblendequation example. >> > You think that I should not do this call? >> >> No, the call is fine. What I'm saying is that blending and transparency >> is (depending on the blend equation) dependent on the order in which >> things are rendered, so one cannot assume (when making off-line >> calculations) that all the geometry is perfectly sorted (think e.g. >> intersecting objects). >> >> > >> > |offscreenTexture->setSourceType( GL_UNSIGNED_BYTE); >> > |Should this not also be GL_FLOAT? >> > >> > yes sorry it is a "copy paste" error. I call >> > offscreenTexture->setSourceType(GL_FLOAT) and >> > offscreenTexture->setInternalFormat(GL_FLOAT_RGBA32_NV). >> > >> > |I can also not see from the code if OpenGL lighting is enabled. Do you >> > disable lighting in your app? >> > >> > No I wasn't but I disable it now and I see no change in the result >> >> OK. >> >> I'm running out of ideas to try help. I cannot from just reading the >> code see any more problems. I'd suggest using the ARB modes and trying a >> few other machines. I'll also try find some of our test code for float >> blending. >> >> Another option is to use shaders to explicitly set the colours of two >> facets (to eliminate any fixed function interference) and see how they >> blend. >> >> jp >> >> >> > >> > >> > Here a update of the code with the correction in yellow: >> > >> > >> > The colors are attached by setting the ColorArray of the drawables of >> > each Geode like this: >> > >> > >> > >> > int geodesNb = m_entityVectorOfGeodeVector[0].size(); >> > >> > >> > >> > osg::Geode* aGeode; >> > >> > int drawablesNb; >> > >> > osg::Drawable* aDrawable; >> > >> > osg::Geometry* aDrawableGeometry; >> > >> > osg::Vec4Array* aDrawableColor; >> > >> > for (int geodesLoop = 0; geodesLoop < geodesNb; geodesLoop++) >> > >> > { >> > >> > aGeode = m_entityVectorOfGeodeVector[0][geodesLoop]; >> > >> > drawablesNb = aGeode->getNumDrawables(); >> > >> > >> > >> > // Update color for each facet (drawable) of a geode >> > >> > for (int i = 0; i < drawablesNb; i++) >> > >> > { >> > >> > aDrawable = aGeode->getDrawable(i); >> > >> > aDrawable->dirtyDisplayList(); // >> > Force color update on next draw >> > >> > >> > >> > aDrawableGeometry = >> > dynamic_cast<osg::Geometry*>(aDrawable); >> > >> > >> > >> > aDrawableColor = >> > dynamic_cast<osg::Vec4Array*>(aDrawableGeometry>getColorArray()); >> > >> > >> > >> > >> > std::string geodeName=aGeode->getName(); >> > >> > >> > >> > if(!geodeName.compare("p1")) >> > >> > { >> > >> > // Set the facet color >> > and transparency (0=invisible) >> > >> > (*aDrawableColor)[0] = >> > m_facet1Color; >> > >> > >> > >> > … >> > >> > } >> > >> > } >> > >> > } >> > >> > >> > >> > Where the /entityVectorOfGeodeVector/ is the list of visible geodes that >> > I maintain by using a cull callback. >> > >> > >> > >> > >> > >> > Here a snapshot of my code to setup the viewer and the camera. >> > >> > >> > >> > m_viewer = new osgViewer::Viewer; >> > >> > m_viewer->setUpViewOnSingleScreen(); >> > >> > osg::Camera *camera = m_viewer->getCamera(); >> > >> > >> > >> > osgViewer::Renderer * renderer = >> > static_cast<osgViewer::Renderer*>(camera->getRenderer()); >> > >> > // Reading back the FBO does not work when it is disabled after render >> > --> set this property of the >> > >> > // renderStage to false. >> > >> > >> renderer->getSceneView(0)->getRenderStage()->setDisableFboAfterRender(false); >> > >> > >> renderer->getSceneView(1)->getRenderStage()->setDisableFboAfterRender(false); >> > >> > >> > >> > m_scene=new osg::Group(); >> > >> > >> > >> > std::string modelName="C:\\_JO\\LTI\\SIS\\Models\\test_IR\\carre.flt"; >> > >> > >> > >> > LoadModel(modelName); // call m_viewer->SetSceneData >> > >> > >> > >> > osg::StateSet* state = m_scene->getOrCreateStateSet(); >> > >> > >> > >> > // Disable Lighting effects >> > >> > state->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | >> > osg::StateAttribute::OFF); >> > >> > >> > >> > // Enable transparency >> > >> > state->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | >> > osg::StateAttribute::ON); >> > >> > // Tell to sort the mesh before displaying it >> > >> > state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); >> > >> > >> > >> > // Set the blend function (related to the transparency) >> > >> > osg::BlendFunc* selectedBlendFunction = new osg::BlendFunc(); >> > >> > selectedBlendFunction->setDestination(GL_ONE_MINUS_SRC_ALPHA); >> > >> > selectedBlendFunction->setSource(GL_ONE); >> > >> > >> > >> > state->setAttribute(selectedBlendFunction, osg::StateAttribute::OVERRIDE >> > | osg::StateAttribute::ON); >> > >> > >> > >> > osg::Image* offscreenImage = new osg::Image; >> > >> > osg::ref_ptr<osg::TextureRectangle> offscreenTexture = new >> > osg::TextureRectangle; >> > >> > >> > >> > // Allocate the image >> > >> > offscreenImage->allocateImage(WIDTH, HEIGHT, 1, GL_RGBA, GL_FLOAT); >> > >> > >> > >> > // Set the 32 bits texture >> > >> > offscreenTexture->setImage(offscreenImage); >> > >> > offscreenTexture->setSourceFormat(GL_RGBA); >> > >> > offscreenTexture->setSourceType( GL_FLOAT); >> > >> > offscreenTexture->setTextureSize(WIDTH, HEIGHT); >> > >> > offscreenTexture->setInternalFormat(GL_FLOAT_RGBA32_NV); >> > >> > >> > >> > // Initialize the background >> > >> > camera->setClearColor(osg::Vec4f(0.0f,0.0f,0.0f,1.0f)); >> > >> > >> > >> > camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); >> > >> > camera->attach(osg::Camera::COLOR_BUFFER0,offscreenTexture.get()); >> > >> > camera->setFinalDrawCallback(new MyCameraDrawCallback(precision)); >> > >> > >> > >> > m_viewer->realize(); >> > >> > >> > >> > // Set the colors R G >> > B A >> > >> > m_facet1Color = osg::Vec4( 0.2, 0.0, 0.0, >> > 1.0 ); >> > >> > m_facet2Color = osg::Vec4( 0, 0.1, 0.0, >> > 1.0 ); >> > >> > m_facet3Color = osg::Vec4( 4e-6, 0.0, 0.1, >> > 1.0 ); >> > >> > m_facet4Color = osg::Vec4( 5e-5, 0.5, 0.5, >> > 1.0 ); >> > >> > m_facet5Color = osg::Vec4( 6e-9, 0.1, 0.0, 1); >> > >> > >> > >> > … >> > >> > >> > >> > // Code of my camera Drawcallback >> > >> > void MyCameraDrawCallback::operator() (osg::RenderInfo& renderInfo) >> const >> > >> > { >> > >> > glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); >> > >> > m_image->readPixels(0,0,WIDTH,HEIGHT, GL_RGBA,GL_FLOAT); >> > >> > } >> > >> > >> > >> > >> > >> > >> > ------------------------------------------------------------------------ >> > >> > _______________________________________________ >> > osg-users mailing list >> > [email protected] >> > >> 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 >> [email protected] >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> > >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

