Re: [osg-users] Tesselation on Model
Hi David, Thank you very much Sebastian! You are awesome! You really made my day. I can see the tesselation it's working now. : ) Thx, an , in comparison, most elaborate question like this needed some attention :-) If I'm allowed to add one question for personal advancing. What do i have to change in the shader so that the model is normal again? My Model is looking like it was pressed to 2D papper and then got wrapped arround a ball. Is this because of the geometryshader of the example? Most likely the example shader is fitted to apply the shift along a specific axis. Usually you would take the world-space normal for the displacement. As I don't have any code at hand right now I cannot tell with certainty, but I will try to check this anytime soon. To avoid polluting the forum simply drop me a personal message. Cheers Sebastian ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Tesselation on Model
Thank you very much Sebastian! You are awesome! You really made my day. I can see the tesselation it's working now. : ) If I'm allowed to add one question for personal advancing. What do i have to change in the shader so that the model is normal again? My Model is looking like it was pressed to 2D papper and then got wrapped arround a ball. Is this because of the geometryshader of the example? Cheers, David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66616#66616 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Tesselation on Model
Hi David, tesselation shaders usually work on the GL_PATCH primitive rather than usual triangles. So in order to get your program running you need to run a visitor on the scene and convert the primitive sets to this. This however won't magically solve every tesselation problem, but this a totally different domain. See the attached apply for a nodevisitor. It will "work" in some cases. Be sure you have triangles in the source models (so no quads) beforehand. virtual void apply( osg::Geode& node ) { for (size_t drawable_num =0; drawable_num < node.getNumDrawables();++drawable_num) { osg::Drawable* drawable = node.getDrawable(drawable_num); drawable->setUseDisplayList(false); drawable->setUseVertexBufferObjects(true); osg::Geometry* geom = drawable->asGeometry(); if (!geom) { continue; } for (size_t primset_num= 0; primset_num < geom->getNumPrimitiveSets(); ++primset_num) { geom->getPrimitiveSet(primset_num)->setMode(osg::PrimitiveSet::PATCHES); geom->getOrCreateStateSet()->setAttribute(new osg::PatchParameter(3)); } } traverse(node); } Cheers Sebastian Hi osg-Forum, I'm kind of stuck with a problem in how to combine a tesslation shader in osg with a normal model right now. I really searched over google a couple of times and over the osg forum. I can't find an answer to my problem. Normally i prefer to not ask and just resolve it myself because thats my problem and not yours. As you can see this is my first post and i just registered here to ask that. I'm really sry for that. The thing is that I'm currently working on is an application that will just display a model. The model i'm working on is a huge bunch of GroupNodes that resolve down in the tree to geode-group-nodes and then geometrynodes. I guess thats pretty normal. With default osg shaders everty thing works nice and smooth. Now comes the problem. I have to tesselate the Model. I admit that im not used to programm shaders and only did it with DirectX 11. But the easy things worked back then. For this project i used the "osgtesselateshaders" example of yours and did just copy the shaders there. I know that now all the texture, material and own lightning won't work with this shaders. I just want to see if the wireframe will get tesselated. For that i create the osg::Program variable in a ref_ptr and then set the pointer of it to all geometrynodes of the model. Every Geometrynode will get his own uniform with "innerTesselation", "outerTesselation" variables and so own. I also created hotkeys for "+" and "-" that will change the values of all Geoemtrynode as pleased. The default shader of osg works perfectly fine with my programm but of course no tesselation will hapen. Now if i start the programm with the osg tesselateion shaders of "osgtesselateshaders" it will just print this in Visual Studio: "Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)" This warning pretty much says nothing as far as i have googeld it. Just says "some Problem ist here". Of course the viewer will show nothing of my model. So now my question what do i have to change to make the shaders of the example work with a loaded model? Is it even possible to make this example work with a model? Isn't a model just a bunch of triangles (+ texture and materials) as the Icosahedron in the example? Whats the difference here? It would be cool if somebody allready has an example on how to use an tesselation shader with a simpel model that he can (is allowed) to post here. I'm sry for the post if the problem is just a simple coding error. Code: // init of the programm this->mShader = new osg::Program(); this->mShader->addShader(new osg::Shader(osg::Shader::VERTEX, shader::Shader::vertSource)); this->mShader->addShader(new osg::Shader(osg::Shader::TESSCONTROL, shader::Shader::tessControlSource)); this->mShader->addShader(new osg::Shader(osg::Shader::TESSEVALUATION, shader::Shader::tessEvalSource)); this->mShader->addShader(new osg::Shader(osg::Shader::GEOMETRY, shader::Shader::geomSource)); this->mShader->addShader(new osg::Shader(osg::Shader::FRAGMENT, shader::Shader::fragSource)); this->mShader->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3); this->mShader->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES); this->mShader->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP); n->setShader(this->mShader.get()); Code: void scene::GroupNode::setShader(osg::Program * p) { NodeIDMap::iterator itr; for (itr = this->mChildren.begin(); itr != this->mChildren.end(); ++itr) itr->second->setShader(p); } Code: void scene::GeometryNode::setShader(osg::Program * p) { auto *ss =
[osg-users] Tesselation on Model
Hi osg-Forum, I'm kind of stuck with a problem in how to combine a tesslation shader in osg with a normal model right now. I really searched over google a couple of times and over the osg forum. I can't find an answer to my problem. Normally i prefer to not ask and just resolve it myself because thats my problem and not yours. As you can see this is my first post and i just registered here to ask that. I'm really sry for that. The thing is that I'm currently working on is an application that will just display a model. The model i'm working on is a huge bunch of GroupNodes that resolve down in the tree to geode-group-nodes and then geometrynodes. I guess thats pretty normal. With default osg shaders everty thing works nice and smooth. Now comes the problem. I have to tesselate the Model. I admit that im not used to programm shaders and only did it with DirectX 11. But the easy things worked back then. For this project i used the "osgtesselateshaders" example of yours and did just copy the shaders there. I know that now all the texture, material and own lightning won't work with this shaders. I just want to see if the wireframe will get tesselated. For that i create the osg::Program variable in a ref_ptr and then set the pointer of it to all geometrynodes of the model. Every Geometrynode will get his own uniform with "innerTesselation", "outerTesselation" variables and so own. I also created hotkeys for "+" and "-" that will change the values of all Geoemtrynode as pleased. The default shader of osg works perfectly fine with my programm but of course no tesselation will hapen. Now if i start the programm with the osg tesselateion shaders of "osgtesselateshaders" it will just print this in Visual Studio: "Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)" This warning pretty much says nothing as far as i have googeld it. Just says "some Problem ist here". Of course the viewer will show nothing of my model. So now my question what do i have to change to make the shaders of the example work with a loaded model? Is it even possible to make this example work with a model? Isn't a model just a bunch of triangles (+ texture and materials) as the Icosahedron in the example? Whats the difference here? It would be cool if somebody allready has an example on how to use an tesselation shader with a simpel model that he can (is allowed) to post here. I'm sry for the post if the problem is just a simple coding error. Code: // init of the programm this->mShader = new osg::Program(); this->mShader->addShader(new osg::Shader(osg::Shader::VERTEX, shader::Shader::vertSource)); this->mShader->addShader(new osg::Shader(osg::Shader::TESSCONTROL, shader::Shader::tessControlSource)); this->mShader->addShader(new osg::Shader(osg::Shader::TESSEVALUATION, shader::Shader::tessEvalSource)); this->mShader->addShader(new osg::Shader(osg::Shader::GEOMETRY, shader::Shader::geomSource)); this->mShader->addShader(new osg::Shader(osg::Shader::FRAGMENT, shader::Shader::fragSource)); this->mShader->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3); this->mShader->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES); this->mShader->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP); n->setShader(this->mShader.get()); Code: void scene::GroupNode::setShader(osg::Program * p) { NodeIDMap::iterator itr; for (itr = this->mChildren.begin(); itr != this->mChildren.end(); ++itr) itr->second->setShader(p); } Code: void scene::GeometryNode::setShader(osg::Program * p) { auto *ss = this->mOSGNode->getOrCreateStateSet(); ss->setAttribute(p); } Code: scene::GeometryNode::GeometryNode(osg::Geometry * ptrOSGNode) { this->mTessInnerU = new osg::Uniform("TessLevelInner", 1.0f); this->mTessOuterU = new osg::Uniform("TessLevelOuter", 1.0f); osg::StateSet * state; state = ptrOSGNode->getOrCreateStateSet(); state->addUniform(new osg::Uniform("AmbientMaterial", osg::Vec3(0.04f, 0.04f, 0.04f))); state->addUniform(new osg::Uniform("DiffuseMaterial", osg::Vec3(0.0f, 0.75f, 0.75f))); state->addUniform(new osg::Uniform("LightPosition", osg::Vec3(0.25f, 0.25f, 1.0f))); state->addUniform(this->mTessInnerU.get()); state->addUniform(this->mTessOuterU.get()); state->setAttribute(new osg::PatchParameter(3)); } Thank you! Cheers, NoxxKn[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66608#66608 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org