vsg-dev / osg2vsg

Adapter library for converting OpenSceneGraph Images and 3D models to VulkanSceneGraph
MIT License
43 stars 15 forks source link

3d scene show lighting differences compared with osg #60

Open rhabacker opened 2 years ago

rhabacker commented 2 years ago

Describe the error Loading the file attached to vsg-dev/VulkanSceneGraph#308 or the files robot.osg or spaceship.osgt with vsgviewer, you can see drawing problems on the right side in the attached screenshot. The illuminations looks different.

Reproduce Steps to reproduce the behavior:

  1. checkout git repo from vsg-dev/vsgFramework unter ~/src
  2. run
    cmake -B ~/src/vsgFramework-build -S ~/src/vsgFramework -DBUILD_OpenSceneGraph=1 -DBUILD_assimp=0 -DBUILD_SHARED_LIBS=1
    cmake --build ~/src/vsgFramework-build
  3. unpack the zip file attached to vsg-dev/VulkanSceneGraph#308 in ~/src
  4. run LD_LIBRARY_PATH=~/src/vsgFramework-build/lib64 VSG_FILE_PATH=~/src/vsgFramework-build/src/vsgExamples/data ~/src/vsgFramework-build/bin/vsgviewer ~/src/demo.osgt.
  5. see error

Expected behavior The viewer should display similar illuminations as the reference image created with osgviewer on the left.

Screenshots grafik

Desktop (please fill in the following information):

Additional context Vulkan 1.2.189 has been installed

robertosfield commented 2 years ago

I've transferred this Issue to vsgXchange as it's an OSG->VSG converter issue.

The lack of lighting is down to the OSG scene graph not enabling lighting so the vsgXchange/OSG converter just honours that and creates shader that doesn't light the scene. If you enable lighting on an osg::StateSet decorating the scene it should light, albeit with a headlight.

You don't see this lack of lighting in the OSG as by default the global StateSet that the Viewer uses enables GL_LIGHTING by default. If you set the global StateSet to not enable GL_LIGHTING then you'd also see a flat shaded scene.

The vsgXchange/OSG ReaderWriter has support for setting the defaults that the OSG->VSG converter should use, and this provides a mechanism for forcing on lighting via a .vsgt asiii file hold the osg2vsg::BuildOptions structure. An example that defaults to lighting:

#vsga 0.2.0
Root id=1 osg2vsg::BuildOptions
{
  insertCullGroups 1
  insertCullNodes 1
  useBindDescriptorSet 1
  billboardTransform 0
  geometryTarget 1
  supportedGeometryAttributes 4095
  supportedShaderModeMask 1023
  overrideGeomAttributes 0
  overrideShaderModeMask 1
  useDepthSorted 1
  mapRGBtoRGBAHint 1
  copyNames 1
  vertexShaderPath ""
  fragmentShaderPath ""
  extension "vsgb"
}
r

You can pass this file to the loader using:

vsgviewer myfile.osgb --read_build_options settings.vsgt

You can also write out the settings that is used by the loader via:

vsgviewer myfile.osgb --write_build_options settings.vsgt

You can list this options (you can also pass them in via vsg::Options) by running vsgconv --features, in the OSG section you'll see:

    vsg::Options::Value  type
    -------------------  ----
    original_converter   bool
    read_build_options   string
    write_build_options  string

Perhaps it might make sense to add a enable_lighting option to this list so you don't have to create and edit a BuildOptions .vsgt as above.

rhabacker commented 2 years ago

With this setting I get grafik