Common PBR material package summary General insurance the following material types:
Concrete042C_2K_Color.jpg
Concrete042C_2K_AmbientOcclusion.jpg
Concrete042C_2K_Roughness.jpg
Concrete042C_2K_Metalness.jpg
Concrete042C_2K_NormalGL.jpg
Detailed data can be obtained from this address:
In the ORMTexture description, Occlusion value, Roughness value and Metallic value are stored in the RGB component of the Texture. How to merge three 8-bit grayscale images into the required material of ORMTexture? The rendered effect after merging is quite different from the actual effect, is this the VTK rendering accuracy is not enough or I did something wrong?
Here is some code for my rendering:
actor->GetProperty()->SetInterpolationToPBR();
vtkSmartPointer<vtkImageData> redImage = vtkSmartPointer<vtkImageData>::New();
ReadImageToTexture(m_material.ambientOcclusionPath, redImage.Get());
vtkSmartPointer<vtkImageData> greenImage = vtkSmartPointer<vtkImageData>::New();
ReadImageToTexture(m_material.roughnessPath, greenImage.Get());
vtkSmartPointer<vtkImageData> blueImage = vtkSmartPointer<vtkImageData>::New();
ReadImageToTexture(m_material.metalnessPath, blueImage.Get());
int Dimensions[3];
redImage->GetDimensions(Dimensions);
vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
imageData->SetDimensions(Dimensions);
imageData->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
int size = imageData->GetNumberOfPoints();
unsigned char *pixels = static_cast<unsigned char *>(imageData->GetScalarPointer());
unsigned char *pixels_r = static_cast<unsigned char *>(redImage->GetScalarPointer());
unsigned char *pixels_g = static_cast<unsigned char *>(greenImage->GetScalarPointer());
unsigned char *pixels_b = static_cast<unsigned char *>(blueImage->GetScalarPointer());
for (int i = 0; i < Dimensions[0]; i++)
{
for (int j = 0; j < Dimensions[1]; j++)
{
pixels[(i * Dimensions[0] + j) * 3] = static_cast<unsigned char>(pixels_r[i * Dimensions[0] + j]); // R
pixels[(i * Dimensions[0] + j) * 3 + 1] = static_cast<unsigned char>(pixels_g[i * Dimensions[0] + j]); // G
pixels[(i * Dimensions[0] + j) * 3 + 2] = static_cast<unsigned char>(pixels_b[i * Dimensions[0] + j]); // B
}
}
vtkSmartPointer<vtkTexture> material = vtkSmartPointer<vtkTexture>::New();
material->InterpolateOn();
material->MipmapOn();
material->SetInputData(imageData);
material->Update();
vtkSmartPointer<vtkTexture> albedo = vtkSmartPointer<vtkTexture>::New();
albedo->UseSRGBColorSpaceOn();
albedo->InterpolateOn();
ReadImageToTexture(m_material.baseColorPath, albedo);
vtkSmartPointer<vtkTexture> normal = vtkSmartPointer<vtkTexture>::New();
normal->InterpolateOn();
ReadImageToTexture(m_material.normalPath, normal);
vtkSmartPointer<vtkImageFlip> flip = vtkSmartPointer<vtkImageFlip>::New();
ReadImageToImageFlip(m_material.normalPath, flip);
flip->SetFilteredAxes(0);
vtkSmartPointer<vtkTexture> coatNormal = vtkSmartPointer<vtkTexture>::New();
coatNormal->InterpolateOn();
coatNormal->SetInputConnection(flip->GetOutputPort());
actor->GetProperty()->SetMetallic(1.0);
actor->GetProperty()->SetRoughness(1.0);
actor->GetProperty()->SetCoatColor(0.75,0.75,0.75);
actor->GetProperty()->SetBaseColorTexture(albedo);
actor->GetProperty()->SetORMTexture(material);
actor->GetProperty()->SetNormalTexture(normal);
actor->GetProperty()->SetCoatNormalTexture(coatNormal);
vtkDataSet *dataSet = actor->GetMapper()->GetInput();
vtkDataSetMapper *mapper = static_cast<vtkDataSetMapper *>(actor->GetMapper());
vtkSmartPointer<vtkTextureMapToSphere> textureMap = vtkSmartPointer<vtkTextureMapToSphere>::New();
textureMap->SetInputData(dataSet);
textureMap->SetPreventSeam(false);
textureMap->SetAutomaticSphereGeneration(true);
textureMap->Update();
vtkSmartPointer<vtkFloatArray> newTCoords = vtkSmartPointer<vtkFloatArray>::New();
newTCoords->DeepCopy(textureMap->GetOutput()->GetPointData()->GetTCoords());
dataSet->GetPointData()->SetTCoords(newTCoords);
mapper->SetInputData(dataSet);
mapper->SetScalarVisibility(false);
mapper->Modified();
actor->Modified();
I refer to the relevant example on vtk.org:
https://examples.vtk.org/site/Cxx/Rendering/PBR_Clear_Coat/