1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestPBREdgeTint.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 // This test covers the PBR Edge Tint feature
16 // It renders spheres with different edge colors using a skybox as image based lighting
17
18 #include "vtkActor.h"
19 #include "vtkActorCollection.h"
20 #include "vtkGenericOpenGLRenderWindow.h"
21 #include "vtkHDRReader.h"
22 #include "vtkImageData.h"
23 #include "vtkImageFlip.h"
24 #include "vtkInteractorStyleTrackballCamera.h"
25 #include "vtkNew.h"
26 #include "vtkOpenGLPolyDataMapper.h"
27 #include "vtkOpenGLRenderer.h"
28 #include "vtkOpenGLSkybox.h"
29 #include "vtkOpenGLTexture.h"
30 #include "vtkPBRIrradianceTexture.h"
31 #include "vtkPBRLUTTexture.h"
32 #include "vtkPBRPrefilterTexture.h"
33 #include "vtkProperty.h"
34 #include "vtkRegressionTestImage.h"
35 #include "vtkRenderWindow.h"
36 #include "vtkRenderWindowInteractor.h"
37 #include "vtkRendererCollection.h"
38 #include "vtkSphereSource.h"
39 #include "vtkTestUtilities.h"
40 #include "vtkTexture.h"
41
42 //------------------------------------------------------------------------------
TestPBREdgeTint(int argc,char * argv[])43 int TestPBREdgeTint(int argc, char* argv[])
44 {
45 vtkNew<vtkOpenGLRenderer> renderer;
46
47 vtkNew<vtkRenderWindow> renWin;
48 renWin->SetSize(600, 600);
49 renWin->AddRenderer(renderer);
50
51 vtkNew<vtkRenderWindowInteractor> iren;
52 iren->SetRenderWindow(renWin);
53
54 vtkNew<vtkOpenGLSkybox> skybox;
55
56 vtkSmartPointer<vtkPBRIrradianceTexture> irradiance = renderer->GetEnvMapIrradiance();
57 irradiance->SetIrradianceStep(0.3);
58 vtkSmartPointer<vtkPBRPrefilterTexture> prefilter = renderer->GetEnvMapPrefiltered();
59
60 vtkNew<vtkHDRReader> reader;
61 char* fname =
62 vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/spiaggia_di_mondello_1k.hdr");
63 reader->SetFileName(fname);
64 delete[] fname;
65 vtkNew<vtkTexture> texture;
66 texture->SetColorModeToDirectScalars();
67 texture->MipmapOn();
68 texture->InterpolateOn();
69 texture->SetInputConnection(reader->GetOutputPort());
70
71 // HDRI OpenGL
72 renderer->UseImageBasedLightingOn();
73 renderer->SetEnvironmentTexture(texture);
74
75 // Skybox OpenGL
76 skybox->SetFloorRight(0.0, 0.0, 1.0);
77 skybox->SetProjection(vtkSkybox::Sphere);
78 skybox->SetTexture(texture);
79
80 renderer->AddActor(skybox);
81
82 vtkNew<vtkSphereSource> sphere;
83 sphere->SetThetaResolution(75);
84 sphere->SetPhiResolution(75);
85
86 vtkNew<vtkPolyDataMapper> pdSphere;
87 pdSphere->SetInputConnection(sphere->GetOutputPort());
88
89 for (int i = 0; i < 6; i++)
90 {
91 vtkNew<vtkActor> actorSphere;
92 actorSphere->SetPosition(i, 0.0, 0.0);
93 actorSphere->SetMapper(pdSphere);
94 actorSphere->GetProperty()->SetInterpolationToPBR();
95 actorSphere->GetProperty()->SetMetallic(1.0);
96 actorSphere->GetProperty()->SetEdgeTint(0.0, 0.0, 0.0);
97 actorSphere->GetProperty()->SetRoughness(i / 5.0);
98 renderer->AddActor(actorSphere);
99 }
100
101 for (int i = 0; i < 6; i++)
102 {
103 vtkNew<vtkActor> actorSphere;
104 actorSphere->SetPosition(i, 1.0, 0.0);
105 actorSphere->SetMapper(pdSphere);
106 actorSphere->GetProperty()->SetInterpolationToPBR();
107 actorSphere->GetProperty()->SetMetallic(1.0);
108 actorSphere->GetProperty()->SetColor(0.0, 0.0, 0.0);
109 actorSphere->GetProperty()->SetEdgeTint(1.0, 1.0, 1.0);
110 actorSphere->GetProperty()->SetRoughness(i / 5.0);
111 renderer->AddActor(actorSphere);
112 }
113
114 for (int i = 0; i < 6; i++)
115 {
116 vtkNew<vtkActor> actorSphere;
117 actorSphere->SetPosition(i, 2.0, 0.0);
118 actorSphere->SetMapper(pdSphere);
119 actorSphere->GetProperty()->SetInterpolationToPBR();
120 actorSphere->GetProperty()->SetMetallic(1.0);
121 actorSphere->GetProperty()->SetColor(0.0, 0.0, 1.0);
122 actorSphere->GetProperty()->SetEdgeTint(1.0, 0.0, 0.0);
123 actorSphere->GetProperty()->SetRoughness(i / 5.0);
124 renderer->AddActor(actorSphere);
125 }
126
127 for (int i = 0; i < 6; i++)
128 {
129 vtkNew<vtkActor> actorSphere;
130 actorSphere->SetPosition(i, 3.0, 0.0);
131 actorSphere->SetMapper(pdSphere);
132 actorSphere->GetProperty()->SetInterpolationToPBR();
133 actorSphere->GetProperty()->SetMetallic(1.0);
134 actorSphere->GetProperty()->SetColor(1.0, 0.0, 0.0);
135 actorSphere->GetProperty()->SetEdgeTint(0.0, 0.0, 1.0);
136 actorSphere->GetProperty()->SetRoughness(i / 5.0);
137 renderer->AddActor(actorSphere);
138 }
139
140 for (int i = 0; i < 6; i++)
141 {
142 vtkNew<vtkActor> actorSphere;
143 actorSphere->SetPosition(i, 4.0, 0.0);
144 actorSphere->SetMapper(pdSphere);
145 actorSphere->GetProperty()->SetInterpolationToPBR();
146 actorSphere->GetProperty()->SetMetallic(1.0);
147 actorSphere->GetProperty()->SetColor(0.0, 0.0, 0.0);
148 actorSphere->GetProperty()->SetEdgeTint(1.0, 1.0, 0.0);
149 actorSphere->GetProperty()->SetRoughness(i / 5.0);
150 renderer->AddActor(actorSphere);
151 }
152
153 renWin->Render();
154
155 int retVal = vtkRegressionTestImage(renWin);
156 if (retVal == vtkRegressionTester::DO_INTERACTOR)
157 {
158 iren->Start();
159 }
160
161 return !retVal;
162 }
163