Re: [osg-users] Proper way for setting uniforms in drawable cullcallback
Hi Robert, Unfortunately I can't do that way because I have one uniform for multiple positions. And I fill this uniform with positions of objects not culled. So it changes according to the camera. Thank you again. Cheers, Olivier -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=61470#61470 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Proper way for setting uniforms in drawable cullcallback
Hi Robert, Thanks for answering. In a single osg::geometry, I have several instances of a same object. In a cull callback I fill several uniforms corresponding to the positions of my object's instances if they are not culled, and set the right number of instances not culled to each PrimitiveSet of the geometry. And then the rendering is done thanks to a vertex shader that also takes care of the possible skinning. However this is not thread safe. Is there a good way to do it thread safe with callback? Or without callback? I am pretty sure that I can use geometry shader but if possible I would like to do it without geometry shader too. I hope this is a bit more clear. I don't know if it helps but I am using version 3.0.1. Thanks again. Cheers, Olivier -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=61468#61468 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Proper way for setting uniforms in drawable cullcallback
Hi everyone, I have read about how to set uniforms in a node cullcallback. Code: class LightingCullCallback : public osg::NodeCallback { std::unordered_map> mCullVisitorStateSetMap; public: LightingCullCallback (int maxLightNb){} virtual void operator() (osg::Node* node, osg::NodeVisitor* nv) { osgUtil::CullVisitor* pCullVisitor = dynamic_cast(nv); if (pCullVisitor) { std::unordered_map>::iterator itStateSet = mCullVisitorStateSetMap.find(pCullVisitor); osg::ref_ptr pStateSet = NULL; if (itStateSet != mCullVisitorStateSetMap.end()) { pStateSet = itStateSet->second; } else { pStateSet = new osg::StateSet; InitUniform(pStateSet); mCullVisitorStateSetMap.insert(std::make_pair(pCullVisitor, pStateSet)); } UpdateUniform(pStateSet); pCullVisitor->pushStateSet(pStateSet); traverse(node, nv); pCullVisitor->popStateSet(); } } }; I am looking for a similar way to do this with Drawable::CullCallback. But as far as I understand traversal and stateset mechanisms, I can not find a way to use pushStateSet and popStateSet in the Drawable::CullCallback. I have tried to do this instead Code: struct SCameraStateSetMap { std::unordered_map> mCameraStateSetMap; } class LightingGeometryCullCallback : public osg::Drawable::CullCallback { SCameraStateSetMap* mpCameraStateSetMap; public: LightingGeometryCullCallback( SCameraStateSetMap* pCameraStateSetMap) : mpCameraStateSetMap(pCameraStateSetMap) {} virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const { osgUtil::CullVisitor* pCullVisitor = dynamic_cast(nv); if (pCullVisitor != NULL) { osg::Camera* pCamera = pCullVisitor->getCurrentCamera(); if (pCamera != NULL) { std::unordered_map>::iterator itStateSet = mpCameraStateSetMap->mCameraStateSetMap.find(pCamera); osg::ref_ptr pStateSet = NULL; if (itStateSet != mpCameraStateSetMap->mCameraStateSetMap.end()) { pStateSet = itStateSet->second; } else { pStateSet = new osg::StateSet; InitUniform(pStateSet); mpCameraStateSetMap->mCameraStateSetMap.insert(std::make_pair(pCamera, pStateSet)); } UpdateUniform(pStateSet); return IsCulled(drawable); } } return true; } }; class LightingGeometryDrawCallback : public osg::Drawable::DrawCallback { SCameraStateSetMap* mpCameraStateSetMap; public: LightingGeometryDrawCallback( SCameraStateSetMap* pCameraStateSetMap) : mpCameraStateSetMap(pCameraStateSetMap) {} virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable* drawable) const { osg::Camera* pCamera = renderInfo.getCurrentCamera(); if (pCamera != NULL) { std::unordered_map>::iterator itStateSet = mpCameraStateSetMap->mCameraStateSetMap.find(pCamera); if (itStateSet != mpCameraStateSetMap->mCameraStateSetMap.end()) { renderInfo.getState()->pushStateSet(pStateSet); renderInfo.getState()->apply(); drawable->drawImplementation(renderInfo); renderInfo.getState()->popStateSet(); renderInfo.getState()->apply(); } else { drawable->drawImplementation(renderInfo); } } } }; But not successful. Do I have a chance to get this work this way? Or another? Thanks for taking the time to read. Cheers, Olivier[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=61463#61463 ___ osg-users mailing
Re: [osg-users] [SOLVED] Texturing a node according to its viewport
Hi, I've looked for a similar problem on the forum and haven't found but if there is one, then you can hit me :). I will to be as clear as possible, but ask me if there is something that is not. So let us say that I have an application like this : CompositeViewer |--| Camera1 Camera2 |--| ( Scene Root ) I have two cameras part of the same osgViewer, a composite viewer, rendering the same scene on different points of view. There is a drawable in the scenegraph that i want to be textured differently if it is rendered by the camera 1 or 2. As far as I understood, because of the viewer, the rendering of the two cameras are more or less at the same time. So I can not put a predrawcallback on my cameras to change the texture on the drawable because the predrawcallback of the second camera would change the texture before the first camera has rendered the scene. What I wanted to be was to but an osg::Drawable::DrawCallback on my drawable to change texture according to the camera but it seems that it is not possible. Code: virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable* drawable) const Because the drawable is const and so I can not modify its StateSet to simply change the texture. I obviously could load one scene by viewer, but I was looking for another way to achieve this. I can't see any options remaining so I'm desperately asking for your help :). A bit of context of my problem, I tried to simplify it to be clearer. The drawable I'm talking about is in fact a mirror, and i want that the texture of the mirror (pre-rendered by other cameras) change according to my point of view. Thanks for reading me and for any clue you can give me. Regards, Olivier[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=55986#55986 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texturing a node according to its viewport
I found a solution using cullMAsks on Camera and NodeMasks on Node. Thanks, Olivier -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=56095#56095 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org