Skip to content

Commit

Permalink
add a simple "baseColorFactor" support (#2415)
Browse files Browse the repository at this point in the history
fix "baseColorTexture" not exists
  • Loading branch information
remoe authored Jan 9, 2024
1 parent b17448a commit 3e2f84e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/osgEarthCesium/PrepareRenderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <osg/Texture2D>
#include <osg/Geometry>
#include <osgEarth/ImageUtils>
#include <osgEarth/Lighting>
#include <osgEarth/Notify>
#include <osgEarth/Registry>
#include <osg/MatrixTransform>
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 3e2f84e

Please sign in to comment.