openscenegraph / OpenSceneGraph

OpenSceneGraph git repository
http://www.openscenegraph.org
Other
3.21k stars 1.42k forks source link

fbx show grey #1258

Closed ggslayer closed 11 months ago

ggslayer commented 11 months ago

Hi, I'm new user for osg and opengl render, I occured a problem when learning osg, need some help.

I build osg with fbx plugin succeed, and load a fbx file from www.mixamo.com, model rendered succed, but render result is so grey, after some test, I can't resolve the grey problem,

The render result screenshot image: https://github.com/ggslayer/codebase/blob/master/2023-10-16%2018-38-58%20%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png?raw=true

The fbx file downloaded from mixamo link: https://github.com/ggslayer/codebase/releases/download/fbx/dance.fbx

my code like this:

I can see the color in the view, but very grey, so I think the textures in fbx is loaded and render succeed, I run the model in osgViewer, grey too.. but in some online 3d viewer and mixamo, the model show normal.

In the createLight function, I do a lot of tests by code from internet, I failed finally. can anyone give me some help? thank you verty much!

My test code:


  int main(){

    osgViewer::Viewer viewer;
    osg::Node *animationNode = osgDB::readNodeFile("./dance.fbx");

    osg::ref_ptr<osg::Group> group = new osg::Group;
    group->addChild(animationNode);

    createLight(group, animationNode);

    viewer.setSceneData(group);
    return viewer.run();
  }

  bool createLight(osg::ref_ptr<osg::Group> lightRoot, osg::ref_ptr<osg::Node> node)
  {
    //开启光照
    lightRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
    lightRoot->getOrCreateStateSet()->setMode(GL_LIGHT0, osg::StateAttribute::ON);

    //计算包围盒
    osg::BoundingSphere bs;
    node->computeBound();
    bs = node->getBound();

    //创建一个Light对象
    osg::ref_ptr<osg::Light> light = new osg::Light();
    light->setLightNum(0);
    //设置方向
    light->setDirection(osg::Vec3(0.0f, 0.0f, -1.0f));
    //设置位置
    light->setPosition(osg::Vec4(bs.center().x(), bs.center().y(), bs.center().z() + bs.radius(), 1.0f));
    //设置环境光的颜色
    light->setAmbient(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    //设置散射光颜色
    light->setDiffuse(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));

    //设置恒衰减指数
    light->setConstantAttenuation(1.0f);
    //设置线形衰减指数
    light->setLinearAttenuation(0.0f);
    //设置二次方衰减指数
    light->setQuadraticAttenuation(0.0f);

    //创建光源
    osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource();
    lightSource->setLight(light.get());

    lightRoot->addChild(lightSource.get());
    return true;
  }
robertosfield commented 11 months ago

I you are new to the OSG and OpenGL then might I recommend just moving to learning modern scene graph and low level like the OSG's successor VulkanSceneGraph and with it Vulkan.

I tried the dance.fbx model with osgviewer and just get black model, but it loads just fine with vsgivewer, even the lighting and shadows are easier to set up than OSG. The VSG even correctly orientates the FBX model.

vsgshadow dance.fbx --direction 1 1 -1 --sm 3 -n 2 --dc

Screenshot_20231016_121659

ggslayer commented 11 months ago

Thank you for your advice, In my business, I want to render fbx's animation by osg, so the fbx's skeleton animation support is importent for me; After some research in vsg's doc, I don't see the animation support, does it support skeleton animation now? @robertosfield thank you

robertosfield commented 11 months ago

You are correct, the VSG doesn't yet have skeleton animation support provided in the core VulkanSceneGraph/vsgXchange. The vsgopenmw will have it so it's technically possible, it's just not provided by the core VSG itself yet.

My intention is to add animation support into the default PBR and Phong shader sets and the vsgXchange::assimp loader this year, but other members of the community are welcome to tackle it before I do. When it is implemented it'll be fully supported by the shaders so users will get a more coherent and better performing experience than the OSG itself can provide.

ggslayer commented 11 months ago

ok, I saw the vsg's Tutorials doc, It's a great work. I'll use it to redo my work when the skel animation supported. thankyou very much!

xarray commented 11 months ago

For old liners :) have a look at osgverse: https://github.com/xarray/osgverse

It supports FBX and GLTF, and can load and handle character animations from GLTF format (and FBX soon).