Skip to content

Commit

Permalink
ENH: Add support for PBR material properties in material property wid…
Browse files Browse the repository at this point in the history
…gets

ctkMaterialPropertyWidget can now edit material properties for both non-PBR (Phong, Gouraud) and PBR interpolation.
PBR material properties are `diffuse` (shared with non-PBR modes) and `metallic` and `roughness` (matching names used in VTK and glTF).
An interpolation mode selector is added (hidden by default for backward compatibility) to allow easy switching between interpolation modes.

ctkVTKSurfaceMaterialPropertyWidget is updated to get/set associated properties in VTK.

ctkMaterialPropertyPreviewLabel is updated so that it can display both PBR and non-PBR material settings. Preview of PBR settings is a rough approximation.
  • Loading branch information
lassoan committed Feb 1, 2022
1 parent 4a743e2 commit 7b48c48
Show file tree
Hide file tree
Showing 7 changed files with 529 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ class ctkVTKSurfaceMaterialPropertyWidgetPrivate
ctkVTKSurfaceMaterialPropertyWidgetPrivate(ctkVTKSurfaceMaterialPropertyWidget& object);
vtkSmartPointer<vtkProperty> Property;
double SettingColor;

// Flag that indicates that the GUI is being updated from the VTK property,
// therefore GUI changes should not trigger VTK property update.
bool IsUpdatingGUI;
};

//-----------------------------------------------------------------------------
ctkVTKSurfaceMaterialPropertyWidgetPrivate::ctkVTKSurfaceMaterialPropertyWidgetPrivate(ctkVTKSurfaceMaterialPropertyWidget& object)
:q_ptr(&object)
{
this->SettingColor = false;
this->IsUpdatingGUI = false;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -98,13 +103,32 @@ void ctkVTKSurfaceMaterialPropertyWidget::updateFromProperty()
{
return;
}
if (d->IsUpdatingGUI)
{
// Update is already in progress
return;
}
d->IsUpdatingGUI = true;
double* c = d->Property->GetColor();
this->setColor(QColor::fromRgbF(qMin(c[0],1.), qMin(c[1], 1.), qMin(c[2],1.)));
this->setOpacity(d->Property->GetOpacity());

switch (d->Property->GetInterpolation())
{
case VTK_FLAT: this->setInterpolationMode(InterpolationFlat); break;
case VTK_GOURAUD: this->setInterpolationMode(InterpolationGouraud); break;
case VTK_PHONG: this->setInterpolationMode(InterpolationPhong); break;
case VTK_PBR: this->setInterpolationMode(InterpolationPBR); break;
}

this->setAmbient(d->Property->GetAmbient());
this->setDiffuse(d->Property->GetDiffuse());
this->setSpecular(d->Property->GetSpecular());
this->setSpecularPower(d->Property->GetSpecularPower());

this->setMetallic(d->Property->GetMetallic());
this->setRoughness(d->Property->GetRoughness());
d->IsUpdatingGUI = false;
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -144,6 +168,26 @@ void ctkVTKSurfaceMaterialPropertyWidget::onOpacityChanged(double newOpacity)
}
}

// --------------------------------------------------------------------------
void ctkVTKSurfaceMaterialPropertyWidget::onInterpolationModeChanged(
ctkMaterialPropertyWidget::InterpolationMode newInterpolationMode)
{
Q_D(ctkVTKSurfaceMaterialPropertyWidget);
this->Superclass::onInterpolationModeChanged(newInterpolationMode);
if (d->Property.GetPointer() != 0)
{
// the value might have changed since we fired the signal, use the current
// up-to-date value then.
switch (this->interpolationMode())
{
case InterpolationFlat: d->Property->SetInterpolationToFlat(); break;
case InterpolationGouraud: d->Property->SetInterpolationToGouraud(); break;
case InterpolationPhong: d->Property->SetInterpolationToPhong(); break;
case InterpolationPBR: d->Property->SetInterpolationToPBR(); break;
}
}
}

// --------------------------------------------------------------------------
void ctkVTKSurfaceMaterialPropertyWidget::onAmbientChanged(double newAmbient)
{
Expand Down Expand Up @@ -196,6 +240,32 @@ void ctkVTKSurfaceMaterialPropertyWidget::onSpecularPowerChanged(double newSpecu
}
}

// --------------------------------------------------------------------------
void ctkVTKSurfaceMaterialPropertyWidget::onMetallicChanged(double newMetallic)
{
Q_D(ctkVTKSurfaceMaterialPropertyWidget);
this->Superclass::onMetallicChanged(newMetallic);
if (d->Property.GetPointer() != 0)
{
// the value might have changed since we fired the signal, use the current
// up-to-date value then.
d->Property->SetMetallic(this->metallic());
}
}

// --------------------------------------------------------------------------
void ctkVTKSurfaceMaterialPropertyWidget::onRoughnessChanged(double newRoughness)
{
Q_D(ctkVTKSurfaceMaterialPropertyWidget);
this->Superclass::onRoughnessChanged(newRoughness);
if (d->Property.GetPointer() != 0)
{
// the value might have changed since we fired the signal, use the current
// up-to-date value then.
d->Property->SetRoughness(this->roughness());
}
}

// --------------------------------------------------------------------------
void ctkVTKSurfaceMaterialPropertyWidget::onBackfaceCullingChanged(bool newBackfaceCulling)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ protected Q_SLOTS:

virtual void onColorChanged(const QColor& newColor);
virtual void onOpacityChanged(double newOpacity);
virtual void onInterpolationModeChanged(ctkMaterialPropertyWidget::InterpolationMode newMode);
virtual void onAmbientChanged(double newAmbient);
virtual void onDiffuseChanged(double newDiffuse);
virtual void onSpecularChanged(double newSpecular);
virtual void onSpecularPowerChanged(double newSpecularPower);
virtual void onMetallicChanged(double newMetallic);
virtual void onRoughnessChanged(double newRoughness);
virtual void onBackfaceCullingChanged(bool newBackfaceCulling);

private:
Expand Down
Loading

0 comments on commit 7b48c48

Please sign in to comment.