[osg-users] How to Preserve FBX baked in textures when running running hardware skinning
I run skinning.vert on my fbx model which has rigging. Ive attached the shader program as in the osg hardware animation example. I have a texture that accompanies the hand model in the FBX file that I export from 3Ds max. If I don't attach the shader program the hand models show up with the texture fine. I assume that when I run the shader on the hands it overrides the texture information. So my question is, is there a way to tell the shader not to override existing texture information or can I get the embedded texture on the fbx hand model and then pass it to the shader, and if so how? Or is there another approach I should be taking? Cheers! /Chris -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62458#62458 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Hi Chris, I don't now how the scene graph is set up so can't answer specifics, but in general if you want texturing to appear then the fragment shader will need to apply the texture. I'd guess that the current fragment shader doesn't have texturing in it, so just add this. Robert. On 23 January 2015 at 16:26, Chris Hidden wrote: > I run skinning.vert on my fbx model which has rigging. Ive attached the > shader program as in the osg hardware animation example. > > I have a texture that accompanies the hand model in the FBX file that I > export from 3Ds max. If I don't attach the shader program the hand models > show up with the texture fine. > > I assume that when I run the shader on the hands it overrides the texture > information. So my question is, is there a way to tell the shader not to > override existing texture information or can I get the embedded texture on > the fbx hand model and then pass it to the shader, and if so how? > > Or is there another approach I should be taking? > > Cheers! > /Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62458#62458 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Hey Robert, thanks for answer, hope you had a great weekend! I've been trying to read up on vertex shaders and fragment shaders and maybe I am not quite understanding. Im trying to attach a very basic fragment shader, but I can't seem to get it to work and I am not sure why. I keep getting the error "Duplicate function definitions for "main"; prototype: "main()" found. I've looked at 2 or 3 of the examples and it seems perfectly fine to attach two shader files, one .vert and one .frag to a single program. Specifically the program in osghardwareanimation example. I only added these lines of code to the existing example to get the duplicate main error: Code: osg::ref_ptr fragshader; osg::ref_ptr image = osgDB::readImageFile("Images/PNG/Erghis_Hands_Texture.png"); osg::ref_ptr texture = new osg::Texture2D(); texture->setImage(image); osg::ref_ptr ss = new osg::StateSet; ss->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); osg::ref_ptr unifo = new osg::Uniform("Hand_Texture", texture.get()); fragshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, "C:/OpenSceneGraph/files/shaders/rain.frag"); if (!fragshader.valid()) osg::notify(osg::WARN) << "RigTransformHardware can't load FragmentShader" << std::endl; program->addShader(fragshader.get()); ss->addUniform(unifo); I added this block right before the state change applications at the end of the init() function. I must be missing something stupid because I've googled the error and looked at the other examples and no one seems to be having this problem. What am I doing wrong? This happens with any .frag shader I load. Not just the one I wrote which for the sake of showing you is simply: uniform sampler2D myTexture; void main(void) { vec4 color = texture2D(myTexture, gl_TexCoord[0].st); gl_FragColor = color; } -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62482#62482 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Hi Chris, It's not possible to determine what error you have made from the snippets included. The snippet of code you did include didn't show how or whether you added the osg::Program to the StateSet, or whether you attached a vertex shader. I would recommend starting from one of the examples like osgshaders and the shaders in the OpenSceneGraph-Data/shaders set. Robert. On 26 January 2015 at 14:51, Chris Hidden wrote: > Hey Robert, thanks for answer, hope you had a great weekend! > > I've been trying to read up on vertex shaders and fragment shaders and > maybe I am not quite understanding. > > Im trying to attach a very basic fragment shader, but I can't seem to get > it to work and I am not sure why. > > I keep getting the error "Duplicate function definitions for "main"; > prototype: "main()" found. > > I've looked at 2 or 3 of the examples and it seems perfectly fine to > attach two shader files, one .vert and one .frag to a single program. > > Specifically the program in osghardwareanimation example. I only added > these lines of code to the existing example to get the duplicate main error: > > > Code: > > osg::ref_ptr fragshader; > osg::ref_ptr image = > osgDB::readImageFile("Images/PNG/Erghis_Hands_Texture.png"); > osg::ref_ptr texture = new osg::Texture2D(); > texture->setImage(image); > > osg::ref_ptr ss = new osg::StateSet; > ss->setTextureAttributeAndModes(0, texture, > osg::StateAttribute::ON); > > osg::ref_ptr unifo = new > osg::Uniform("Hand_Texture", texture.get()); > fragshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, > "C:/OpenSceneGraph/files/shaders/rain.frag"); > > if (!fragshader.valid()) > osg::notify(osg::WARN) << "RigTransformHardware can't load > FragmentShader" << std::endl; > program->addShader(fragshader.get()); > > ss->addUniform(unifo); > > > > > I added this block right before the state change applications at the end > of the init() function. I must be missing something stupid because I've > googled the error and looked at the other examples and no one seems to be > having this problem. What am I doing wrong? > > This happens with any .frag shader I load. Not just the one I wrote which > for the sake of showing you is simply: > > uniform sampler2D myTexture; > > void main(void) > { > vec4 color = texture2D(myTexture, gl_TexCoord[0].st); > gl_FragColor = color; > } > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62482#62482 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Aha, ok, I wasn't clear enough. I literally injected that code snippet into the osganimationhardware.cpp example. I just thougt it would be redundant to repost the entire example. If you shove my code right at in around line 122, thats where I have made the edits. Otherwise my entire init() method looks like this as in osganimationhardware but with my edits: Code: bool Erghis::HardwareController::init(osgAnimation::RigGeometry& geom) { osg::Vec3Array* pos = dynamic_cast(geom.getVertexArray()); if (!pos) { osg::notify(osg::WARN) << "RigTransformHardware no vertex array in the geometry " << geom.getName() << std::endl; return false; } if (!geom.getSkeleton()) { osg::notify(osg::WARN) << "RigTransformHardware no skeleton set in geometry " << geom.getName() << std::endl; return false; } osgAnimation::BoneMapVisitor mapVisitor; geom.getSkeleton()->accept(mapVisitor); osgAnimation::BoneMap bm = mapVisitor.getBoneMap(); if (!createPalette(pos->size(), bm, geom.getVertexInfluenceSet().getVertexToBoneList())) return false; int nbAttribs = getNumVertexAttrib(); // use a global program for all avatar if (!program.valid()) { program = new osg::Program; program->setName("HardwareSkinning"); if (!_shader.valid()) _shader = osg::Shader::readShaderFile(osg::Shader::VERTEX, "C:/OpenSceneGraph/files/shaders/skinning.vert"); if (!_shader.valid()) { osg::notify(osg::WARN) << "RigTransformHardware can't load VertexShader" << std::endl; return false; } // replace max matrix by the value from uniform { std::string str = _shader->getShaderSource(); std::string toreplace = std::string("MAX_MATRIX"); std::size_t start = str.find(toreplace); std::stringstream ss; ss << getMatrixPaletteUniform()->getNumElements(); str.replace(start, toreplace.size(), ss.str()); _shader->setShaderSource(str); osg::notify(osg::INFO) << "Shader " << str << std::endl; } program->addShader(_shader.get()); for (int i = 0; i < nbAttribs; i++) { std::stringstream ss; ss << "boneWeight" << i; program->addBindAttribLocation(ss.str(), attribIndex + i); osg::notify(osg::INFO) << "set vertex attrib " << ss.str() << std::endl; } for (int i = 0; i < nbAttribs; i++) { std::stringstream ss; ss << "boneWeight" << i; geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i)); } osg::ref_ptr ss = new osg::StateSet; ### # MY EDITS ### osg::ref_ptr image = osgDB::readImageFile("Images/PNG/Erghis_Hands_Texture.png"); osg::ref_ptr texture = new osg::Texture2D(); texture->setImage(image); ss->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); osg::ref_ptr unifo = new osg::Uniform("Hand_Texture", texture.get()); fragshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, "C:/OpenSceneGraph/files/shaders/rain.frag"); if (!fragshader.valid()) osg::notify(osg::WARN) << "RigTransformHardware can't load FragmentShader" << std::endl; program->addShader(fragshader.get()); ss->addUniform(unifo); ### # END MY EDITS ss->addUniform(getMatrixPaletteUniform()); ss->addUniform(new osg::Uniform(UNIFORM, getNumBonesPerVertex())); ss->setAttributeAndModes(program.get()); geom.setStateSet(ss.get()); _needInit = false; return true; } -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62484#62484 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Hi Chris, Still can't spot what might be wrong. Try running the application with the OSG_NOTIFY_LEVEL env var set to DEBUG and then capture the output to the console. The shader strings passed to OpenGL should be printed out. This might give some clues. Robert. On 26 January 2015 at 15:18, Chris Hidden wrote: > Aha, ok, I wasn't clear enough. > > I literally injected that code snippet into the osganimationhardware.cpp > example. I just thougt it would be redundant to repost the entire example. > > If you shove my code right at in around line 122, thats where I have made > the edits. > > Otherwise my entire init() method looks like this as in > osganimationhardware but with my edits: > > > Code: > > bool Erghis::HardwareController::init(osgAnimation::RigGeometry& geom) > { > osg::Vec3Array* pos = > dynamic_cast(geom.getVertexArray()); > > if (!pos) { > osg::notify(osg::WARN) << "RigTransformHardware no vertex > array in the geometry " << geom.getName() << std::endl; > return false; > } > > if (!geom.getSkeleton()) { > osg::notify(osg::WARN) << "RigTransformHardware no > skeleton set in geometry " << geom.getName() << std::endl; > return false; > } > > osgAnimation::BoneMapVisitor mapVisitor; > geom.getSkeleton()->accept(mapVisitor); > osgAnimation::BoneMap bm = mapVisitor.getBoneMap(); > > if (!createPalette(pos->size(), bm, > geom.getVertexInfluenceSet().getVertexToBoneList())) > return false; > > int nbAttribs = getNumVertexAttrib(); > > // use a global program for all avatar > if (!program.valid()) > { > program = new osg::Program; > program->setName("HardwareSkinning"); > if (!_shader.valid()) > _shader = > osg::Shader::readShaderFile(osg::Shader::VERTEX, > "C:/OpenSceneGraph/files/shaders/skinning.vert"); > > if (!_shader.valid()) { > osg::notify(osg::WARN) << "RigTransformHardware > can't load VertexShader" << std::endl; > return false; > } > > > // replace max matrix by the value from uniform > { > std::string str = _shader->getShaderSource(); > std::string toreplace = std::string("MAX_MATRIX"); > std::size_t start = str.find(toreplace); > std::stringstream ss; > ss << getMatrixPaletteUniform()->getNumElements(); > str.replace(start, toreplace.size(), ss.str()); > _shader->setShaderSource(str); > osg::notify(osg::INFO) << "Shader " << str << > std::endl; > } > > program->addShader(_shader.get()); > > for (int i = 0; i < nbAttribs; i++) > { > std::stringstream ss; > ss << "boneWeight" << i; > program->addBindAttribLocation(ss.str(), > attribIndex + i); > > osg::notify(osg::INFO) << "set vertex attrib " << > ss.str() << std::endl; > } > > for (int i = 0; i < nbAttribs; i++) > { > std::stringstream ss; > ss << "boneWeight" << i; > geom.setVertexAttribArray(attribIndex + i, > getVertexAttrib(i)); > } > > osg::ref_ptr ss = new osg::StateSet; > > ### > # MY EDITS ### > > osg::ref_ptr image = > osgDB::readImageFile("Images/PNG/Erghis_Hands_Texture.png"); > osg::ref_ptr texture = new osg::Texture2D(); > texture->setImage(image); > > > ss->setTextureAttributeAndModes(0, texture, > osg::StateAttribute::ON); > > osg::ref_ptr unifo = new > osg::Uniform("Hand_Texture", texture.get()); > fragshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, > "C:/OpenSceneGraph/files/shaders/rain.frag"); > > if (!fragshader.valid()) > osg::notify(osg::WARN) << "RigTransformHardware can't load > FragmentShader" << std::endl; > program->addShader(fragshader.get()); > > ss->addUniform(unifo); > > ### > # END MY EDITS > > > ss->addUniform(getMatrixPaletteUniform()); > ss->addUniform(new osg::Uniform(UNIFORM, getNumBonesPerVertex())); > ss->setAttributeAndModes(program.get()); > geom.setStateSet(ss.get()); > _needInit = false; > return true; > } > > > > > > > > > > > > ---
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Ok I solved my problem with the fragment shader. Stupid but I realized that if I didn't instanciate the fragment shader within the if conditional where it checks to make sure the program is valid or not it will add the same fragment shader twice to the program, hence the duplicate main error. I guess it was a bit of a dumb error. Yay mondays! Now I just need to figure out why the texture is still not showing up on my hand models... in fact the model doesn't show up at all :) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62486#62486 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Ok so now back to the original intent with this question. So I can now attach a texture to my hand model with a vertex and fragment shader, which is great! I load the texture via its file path and send it along to the shaders. However I was hoping to find a way to do this in a different workflow. I have been and would like to continue to do a fair amount of the texture work in 3D Studio Max. So when I export an FBX model and load it into the scene graph it under "normal" circumstances retains its embedded texture and displays accordingly. Is there a way I can access these textures for the FBX model, so that I could in some way load the texture directly from the model. So if I have osg::ref_ptr model = osgDB::readNodeFile("myModel.fbx); Then I would like to acheive this somehow (Pseudo Code): osg::ref_ptr texture = model->GetEmbeddeFBXTexture(); That way we could have a nice system that will take whatever our designers or modelers texture the model with directly through the code instead of having to manually switch in the code later on. Im sure this can be done one way or another. Is there a somewhat simple approach to this? Thank you! Cheers, Chris -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62492#62492 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Hi Chris, > osg::ref_ptr texture = model->GetEmbeddeFBXTexture(); I think you have to write NodeVisitor that will traverse your model and extract the Texture from the StateSet. But you can also work with the texture that is mapped in your FBX model. I didn't followed your conversation with Robert on this topic, but maybe you just put in your shader the texture unit to which the texture is assigned? On Tue, Jan 27, 2015 at 1:50 PM, Chris Hidden wrote: > Ok so now back to the original intent with this question. > > So I can now attach a texture to my hand model with a vertex and fragment > shader, which is great! I load the texture via its file path and send it > along to the shaders. > > However I was hoping to find a way to do this in a different workflow. I > have been and would like to continue to do a fair amount of the texture > work in 3D Studio Max. So when I export an FBX model and load it into the > scene graph it under "normal" circumstances retains its embedded texture > and displays accordingly. > > Is there a way I can access these textures for the FBX model, so that I > could in some way load the texture directly from the model. > > So if I have > osg::ref_ptr model = osgDB::readNodeFile("myModel.fbx); > > Then I would like to acheive this somehow (Pseudo Code): > > osg::ref_ptr texture = model->GetEmbeddeFBXTexture(); > > That way we could have a nice system that will take whatever our designers > or modelers texture the model with directly through the code instead of > having to manually switch in the code later on. > > Im sure this can be done one way or another. Is there a somewhat simple > approach to this? > Thank you! > > Cheers, > Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62492#62492 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- trajce nikolov nick ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
The shader needs to receive a sampler uniform containing the integer value of a texture unit to use. The right way to do this would be to scan the subgraph of the model for state sets containing enabled texture units. Use a node visitor here. For each of these texture units, create a uniform value containing the texture unit and attach it to the model's state. It might be a bit of a pain to write a shader for all kinds of different textures and multitexturing modes though. There is a tool that might be able to assist you here. So far this isn't integrated into OSG. ShaderGen https://github.com/mojocorp/ShaderGen Christian 2015-01-27 13:50 GMT+01:00 Chris Hidden : > Ok so now back to the original intent with this question. > > So I can now attach a texture to my hand model with a vertex and fragment > shader, which is great! I load the texture via its file path and send it > along to the shaders. > > However I was hoping to find a way to do this in a different workflow. I > have been and would like to continue to do a fair amount of the texture > work in 3D Studio Max. So when I export an FBX model and load it into the > scene graph it under "normal" circumstances retains its embedded texture > and displays accordingly. > > Is there a way I can access these textures for the FBX model, so that I > could in some way load the texture directly from the model. > > So if I have > osg::ref_ptr model = osgDB::readNodeFile("myModel.fbx); > > Then I would like to acheive this somehow (Pseudo Code): > > osg::ref_ptr texture = model->GetEmbeddeFBXTexture(); > > That way we could have a nice system that will take whatever our designers > or modelers texture the model with directly through the code instead of > having to manually switch in the code later on. > > Im sure this can be done one way or another. Is there a somewhat simple > approach to this? > Thank you! > > Cheers, > Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62492#62492 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
Great thanks guys! This is the kind of lead I was looking for. Ill take a look at the shaderGen and I also have been poking around the fbxsdk which might help as well. Cheers! If I find a good solution and the time Ill try and post how I managed to get it working here later on. Thank you! Cheers, Chris -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62495#62495 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to Preserve FBX baked in textures when running running hardware skinning
hmm just googled osg ShaderGen and found this: http://trac.openscenegraph.org/projects/osg//browser/OpenSceneGraph/branches/OpenSceneGraph-3.2/src/osgUtil/ShaderGen.cpp This seems to create shader code based on some OSG states, but I have no idea how complete this implementation is. Also I have never used this ;) Christian 2015-01-27 14:26 GMT+01:00 Chris Hidden : > Great thanks guys! > > This is the kind of lead I was looking for. Ill take a look at the > shaderGen and I also have been poking around the fbxsdk which might help as > well. Cheers! If I find a good solution and the time Ill try and post how > I managed to get it working here later on. > > Thank you! > > Cheers, > Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62495#62495 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org