/*========================================================================= Program: Visualization Toolkit Module: TestPBRClearCoat.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // This test covers the PBR Clear coat feature // It renders a cube with custom texture mapping and a coat normal texture #include "vtkActor.h" #include "vtkActorCollection.h" #include "vtkCamera.h" #include "vtkCubeSource.h" #include "vtkDeflectNormals.h" #include "vtkGenericOpenGLRenderWindow.h" #include "vtkImageData.h" #include "vtkImageFlip.h" #include "vtkInteractorStyleTrackballCamera.h" #include "vtkJPEGReader.h" #include "vtkLight.h" #include "vtkNew.h" #include "vtkOpenGLPolyDataMapper.h" #include "vtkOpenGLRenderer.h" #include "vtkOpenGLSkybox.h" #include "vtkOpenGLTexture.h" #include "vtkPBRIrradianceTexture.h" #include "vtkPBRLUTTexture.h" #include "vtkPBRPrefilterTexture.h" #include "vtkPNGReader.h" #include "vtkPolyDataTangents.h" #include "vtkProperty.h" #include "vtkRegressionTestImage.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRendererCollection.h" #include "vtkTestUtilities.h" #include "vtkTexture.h" #include "vtkTriangleFilter.h" //---------------------------------------------------------------------------- int TestPBRClearCoat(int argc, char* argv[]) { vtkNew renderer; renderer->AutomaticLightCreationOff(); vtkNew light; light->SetPosition(2.0, 0.0, 2.0); light->SetFocalPoint(0.0, 0.0, 0.0); renderer->AddLight(light); vtkNew renWin; renWin->SetSize(600, 600); renWin->AddRenderer(renderer); vtkNew iren; iren->SetRenderWindow(renWin); vtkSmartPointer irradiance = renderer->GetEnvMapIrradiance(); irradiance->SetIrradianceStep(0.3); renderer->UseSphericalHarmonicsOff(); vtkNew textureCubemap; textureCubemap->CubeMapOn(); textureCubemap->UseSRGBColorSpaceOn(); std::string pathSkybox[6] = { "Data/skybox/posx.jpg", "Data/skybox/negx.jpg", "Data/skybox/posy.jpg", "Data/skybox/negy.jpg", "Data/skybox/posz.jpg", "Data/skybox/negz.jpg" }; for (int i = 0; i < 6; i++) { vtkNew jpg; char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, pathSkybox[i].c_str()); jpg->SetFileName(fname); delete[] fname; vtkNew flip; flip->SetInputConnection(jpg->GetOutputPort()); flip->SetFilteredAxis(1); // flip y axis textureCubemap->SetInputConnection(i, flip->GetOutputPort()); } renderer->SetEnvironmentTexture(textureCubemap); renderer->UseImageBasedLightingOn(); vtkNew cube; vtkNew triangulation; triangulation->SetInputConnection(cube->GetOutputPort()); vtkNew tangents; tangents->SetInputConnection(triangulation->GetOutputPort()); vtkNew mapper; mapper->SetInputConnection(tangents->GetOutputPort()); vtkNew materialReader; char* matname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Material.png"); materialReader->SetFileName(matname); delete[] matname; vtkNew material; material->InterpolateOn(); material->SetInputConnection(materialReader->GetOutputPort()); vtkNew albedoReader; char* colname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Base_Color.png"); albedoReader->SetFileName(colname); delete[] colname; vtkNew albedo; albedo->UseSRGBColorSpaceOn(); albedo->InterpolateOn(); albedo->SetInputConnection(albedoReader->GetOutputPort()); vtkNew normalReader; char* normname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Normal.png"); normalReader->SetFileName(normname); delete[] normname; vtkNew flip; flip->SetInputConnection(normalReader->GetOutputPort()); flip->SetFilteredAxes(0); vtkNew normal; normal->InterpolateOn(); normal->SetInputConnection(normalReader->GetOutputPort()); vtkNew coatNormal; coatNormal->InterpolateOn(); coatNormal->SetInputConnection(flip->GetOutputPort()); vtkNew actor; actor->SetOrientation(0.0, 25.0, 0.0); actor->SetMapper(mapper); actor->GetProperty()->SetInterpolationToPBR(); // set metallic and roughness to 1.0 as they act as multipliers with texture value actor->GetProperty()->SetMetallic(1.0); actor->GetProperty()->SetRoughness(1.0); actor->GetProperty()->SetCoatStrength(1.0); actor->GetProperty()->SetCoatColor(1.0, 0.0, 0.0); actor->GetProperty()->SetBaseColorTexture(albedo); actor->GetProperty()->SetORMTexture(material); actor->GetProperty()->SetNormalTexture(normal); actor->GetProperty()->SetCoatNormalTexture(coatNormal); renderer->AddActor(actor); renWin->Render(); renderer->GetActiveCamera()->Zoom(1.5); renWin->Render(); int retVal = vtkRegressionTestImage(renWin); if (retVal == vtkRegressionTester::DO_INTERACTOR) { iren->Start(); } return !retVal; }