diff --git a/src/osgEarthCesium/PrepareRenderResources.cpp b/src/osgEarthCesium/PrepareRenderResources.cpp index 7b92f348d7..fbd6dbe410 100644 --- a/src/osgEarthCesium/PrepareRenderResources.cpp +++ b/src/osgEarthCesium/PrepareRenderResources.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -538,13 +539,21 @@ class NodeBuilder if (primitive.material >= 0 && primitive.material < _model->materials.size()) { + osg::StateSet* stateSet = geom->getOrCreateStateSet(); auto& material = _model->materials[primitive.material]; auto pbr = material.pbrMetallicRoughness; - unsigned int baseColorTexture = pbr->baseColorTexture->index; - if (baseColorTexture >= 0 && baseColorTexture < _textures.size()) - { - osg::StateSet* stateSet = geom->getOrCreateStateSet(); - stateSet->setTextureAttributeAndModes(0, _textures[baseColorTexture], osg::StateAttribute::ON); + if (pbr->baseColorFactor.size() > 0) { + osgEarth::MaterialGL3* material = new osgEarth::MaterialGL3(); + osg::Vec4d color(pbr->baseColorFactor[0], pbr->baseColorFactor[1], pbr->baseColorFactor[2], pbr->baseColorFactor[3]); + material->setDiffuse(osg::Material::FRONT_AND_BACK, color); + stateSet->setAttributeAndModes(material); + } + if (pbr->baseColorTexture.has_value()) { + unsigned int baseColorTexture = pbr->baseColorTexture->index; + if (baseColorTexture >= 0 && baseColorTexture < _textures.size()) + { + stateSet->setTextureAttributeAndModes(0, _textures[baseColorTexture], osg::StateAttribute::ON); + } } }