
Here are two ways to get the same effect:
- Make Roughness lower
- Configure Coat layer and use it.
#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkSphereSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataNormals.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkLight.h>
#include <vtkSTLReader.h>
#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();
using namespace std;
int main()
{
vtkSPtrNew( reader, vtkSTLReader );
reader->SetFileName( "string.stl" );
reader->Update();
vtkSPtrNew(polyDataNormals, vtkPolyDataNormals);
polyDataNormals->SetInputData( reader->GetOutput() );
polyDataNormals->ComputePointNormalsOn();
polyDataNormals->ComputeCellNormalsOff();
polyDataNormals->SetSplitting(false);
polyDataNormals->Update();
vtkSPtrNew( mapper, vtkPolyDataMapper );
mapper->SetInputConnection( polyDataNormals->GetOutputPort() );
vtkSPtrNew( actor, vtkActor );
actor->SetMapper( mapper );
#if (VTK_MAJOR_VERSION >= 9)
// Ambient 环境; diffuse 扩散; specular 镜面; coefficient 系数
actor->GetProperty()->SetInterpolationToPBR(); // shading interpolation: PBR
actor->GetProperty()->SetRoughness(0.1); // A: set 0.1
// actor->GetProperty()->SetCoatStrength(1.0); // B: use Coat method if Roughness is big(such as 0.7)
// actor->GetProperty()->SetCoatRoughness(0.15);
// actor->GetProperty()->SetCoatIOR(1.3);
#endif
vtkSPtrNew( renderer, vtkRenderer );
renderer->AddActor(actor);
renderer->SetBackground( 0, 0, 0 );
vtkSPtrNew( renderWindow, vtkRenderWindow );
renderWindow->AddRenderer( renderer );
vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
renderWindowInteractor->SetRenderWindow( renderWindow );
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
The string.stl used in the project can be downloaded at: