...
 
Commits (9)
......@@ -3076,7 +3076,7 @@ function (vtk_module_add_module name)
${_vtk_add_module_private_depends_link})
set(_vtk_add_module_private_depends_forward_link)
foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_private_depends)
foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_depends_link _vtk_add_module_private_depends)
_vtk_module_get_module_property("${_vtk_add_module_private_depend}"
PROPERTY "forward_link"
VARIABLE _vtk_add_module_forward_link)
......
......@@ -47,7 +47,8 @@ const char vtkDataSetAttributes
"Tensors",
"GlobalIds",
"PedigreeIds",
"EdgeFlag"
"EdgeFlag",
"Tangents"
};
const char vtkDataSetAttributes
......@@ -59,7 +60,8 @@ const char vtkDataSetAttributes
"vtkDataSetAttributes::TENSORS",
"vtkDataSetAttributes::GLOBALIDS",
"vtkDataSetAttributes::PEDIGREEIDS",
"vtkDataSetAttributes::EDGEFLAG"
"vtkDataSetAttributes::EDGEFLAG",
"vtkDataSetAttributes::TANGENTS"
};
//--------------------------------------------------------------------------
......@@ -110,6 +112,7 @@ void vtkDataSetAttributes::CopyAllOn(int ctype)
this->SetCopyTensors(1, ctype);
this->SetCopyGlobalIds(1, ctype);
this->SetCopyPedigreeIds(1, ctype);
this->SetCopyTangents(1, ctype);
}
//--------------------------------------------------------------------------
......@@ -124,6 +127,7 @@ void vtkDataSetAttributes::CopyAllOff(int ctype)
this->SetCopyTensors(0, ctype);
this->SetCopyGlobalIds(0, ctype);
this->SetCopyPedigreeIds(0, ctype);
this->SetCopyTangents(0, ctype);
}
//--------------------------------------------------------------------------
......@@ -1092,6 +1096,24 @@ vtkDataArray* vtkDataSetAttributes::GetNormals()
return this->GetAttribute(NORMALS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetTangents(vtkDataArray* da)
{
return this->SetAttribute(da, TANGENTS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveTangents(const char* name)
{
return this->SetActiveAttribute(name, TANGENTS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTangents()
{
return this->GetAttribute(TANGENTS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetTCoords(vtkDataArray* da)
{
......@@ -1193,6 +1215,16 @@ vtkDataArray* vtkDataSetAttributes::GetNormals(const char* name)
return this->GetArray(name);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTangents(const char* name)
{
if (name == nullptr || name[0] == '\0')
{
return this->GetTangents();
}
return this->GetArray(name);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTCoords(const char* name)
{
......@@ -1281,7 +1313,8 @@ const int vtkDataSetAttributes
9,
1,
1,
1};
1,
3};
//--------------------------------------------------------------------------
// Scalars set to NOLIMIT
......@@ -1294,6 +1327,7 @@ const int vtkDataSetAttributes
EXACT,
EXACT,
EXACT,
EXACT,
EXACT};
//--------------------------------------------------------------------------
......@@ -1569,12 +1603,25 @@ void vtkDataSetAttributes::SetCopyNormals(vtkTypeBool i, int ctype)
{
this->SetCopyAttribute(NORMALS, i, ctype);
}
//--------------------------------------------------------------------------
vtkTypeBool vtkDataSetAttributes::GetCopyNormals(int ctype)
{
return this->GetCopyAttribute(NORMALS, ctype);
}
//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyTangents(vtkTypeBool i, int ctype)
{
this->SetCopyAttribute(TANGENTS, i, ctype);
}
//--------------------------------------------------------------------------
vtkTypeBool vtkDataSetAttributes::GetCopyTangents(int ctype)
{
return this->GetCopyAttribute(TANGENTS, ctype);
}
//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyTCoords(vtkTypeBool i, int ctype)
{
......
......@@ -101,6 +101,7 @@ public:
GLOBALIDS=5,
PEDIGREEIDS=6,
EDGEFLAG=7,
TANGENTS=8,
NUM_ATTRIBUTES
};
......@@ -165,6 +166,15 @@ public:
vtkDataArray* GetNormals();
//@}
//@{
/**
* Set/get the tangent data.
*/
int SetTangents(vtkDataArray* da);
int SetActiveTangents(const char* name);
vtkDataArray* GetTangents();
//@}
//@{
/**
* Set/Get the texture coordinate data.
......@@ -210,6 +220,7 @@ public:
vtkDataArray* GetScalars(const char* name);
vtkDataArray* GetVectors(const char* name);
vtkDataArray* GetNormals(const char* name);
vtkDataArray* GetTangents(const char* name);
vtkDataArray* GetTCoords(const char* name);
vtkDataArray* GetTensors(const char* name);
vtkDataArray* GetGlobalIds(const char* name);
......@@ -227,6 +238,7 @@ public:
* vtkDataSetAttributes::GLOBALIDS = 5
* vtkDataSetAttributes::PEDIGREEIDS = 6
* vtkDataSetAttributes::EDGEFLAG = 7
* vtkDataSetAttributes::TANGENTS = 8
* Returns the index of the array if successful, -1 if the array
* is not in the list of arrays.
*/
......@@ -364,6 +376,11 @@ public:
vtkTypeBool GetCopyNormals(int ctype=ALLCOPY);
vtkBooleanMacro(CopyNormals, vtkTypeBool);
/// @copydoc vtkDataSetAttributes::SetCopyAttribute()
void SetCopyTangents(vtkTypeBool i, int ctype=ALLCOPY);
vtkTypeBool GetCopyTangents(int ctype=ALLCOPY);
vtkBooleanMacro(CopyTangents, vtkTypeBool);
/// @copydoc vtkDataSetAttributes::SetCopyAttribute()
void SetCopyTCoords(vtkTypeBool i, int ctype=ALLCOPY);
vtkTypeBool GetCopyTCoords(int ctype=ALLCOPY);
......
......@@ -63,6 +63,7 @@ set(classes
vtkPointDataToCellData
vtkPolyDataConnectivityFilter
vtkPolyDataNormals
vtkPolyDataTangents
vtkProbeFilter
vtkQuadricClustering
vtkQuadricDecimation
......
......@@ -7,6 +7,7 @@ vtk_module_test_data(
Data/delaunay3d.vtu
Data/disk_out_ref_surface.vtp
Data/explicitStructuredGrid.vtu
Data/tex_debug.jpg
Data/wavelet300Arrays.vti)
add_subdirectory(Cxx)
......
......@@ -37,6 +37,7 @@ vtk_add_test_cxx(vtkFiltersCoreCxxTests tests
TestNamedComponents.cxx,NO_VALID
TestPointDataToCellData.cxx,NO_VALID
TestPolyDataConnectivityFilter.cxx,NO_VALID
TestPolyDataTangents.cxx
TestProbeFilter.cxx,NO_VALID
TestProbeFilterImageInput.cxx
TestProbeFilterOutputAttributes.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestPolyDataTangents.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 vtkPolyDataTangents filter
#include "vtkActor.h"
#include "vtkActorCollection.h"
#include "vtkArrowSource.h"
#include "vtkCamera.h"
#include "vtkDataSetAttributes.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkGlyph3DMapper.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkJPEGReader.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyDataTangents.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
#include "vtkTextureMapToCylinder.h"
#include "vtkTriangleFilter.h"
#include "vtkXMLPolyDataReader.h"
//----------------------------------------------------------------------------
int TestPolyDataTangents(int argc, char* argv[])
{
vtkNew<vtkXMLPolyDataReader> reader;
reader->SetFileName(vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/cow.vtp"));
vtkNew<vtkPolyDataNormals> normals;
normals->SetInputConnection(reader->GetOutputPort());
normals->SplittingOff();
vtkNew<vtkTriangleFilter> triangle;
triangle->SetInputConnection(normals->GetOutputPort());
vtkNew<vtkTextureMapToCylinder> textureMap;
textureMap->SetInputConnection(triangle->GetOutputPort());
vtkNew<vtkPolyDataTangents> tangents;
tangents->SetInputConnection(textureMap->GetOutputPort());
vtkNew<vtkArrowSource> arrow;
arrow->SetTipResolution(20);
arrow->SetShaftResolution(20);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(tangents->GetOutputPort());
vtkNew<vtkGlyph3DMapper> tgtsMapper;
tgtsMapper->SetInputConnection(tangents->GetOutputPort());
tgtsMapper->SetOrientationArray(vtkDataSetAttributes::TANGENTS);
tgtsMapper->SetSourceConnection(arrow->GetOutputPort());
tgtsMapper->SetScaleFactor(0.5);
vtkNew<vtkJPEGReader> image;
image->SetFileName(vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/tex_debug.jpg"));
vtkNew<vtkTexture> texture;
texture->SetInputConnection(image->GetOutputPort());
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 600);
renWin->SetMultiSamples(0);
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->SetTexture(texture);
vtkNew<vtkActor> actorTangents;
actorTangents->SetMapper(tgtsMapper);
actorTangents->GetProperty()->SetColor(1.0, 0.0, 0.0);
renderer->AddActor(actor);
renderer->AddActor(actorTangents);
renWin->Render();
renderer->GetActiveCamera()->Zoom(3.0);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
5e6f5645886ad600419a5b44088d7fe569a7d9cfc6e8311842a75299662ac9411095d10a92a21288d4dfe314855fc88a36724a86bd9c8c1bcd7f994ae17e5656
......@@ -24,6 +24,7 @@ TEST_DEPENDS
VTK::FiltersGeneral
VTK::FiltersGeometry
VTK::FiltersSources
VTK::FiltersTexture
VTK::IOExodus
VTK::IOImage
VTK::IOLegacy
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyDataTangents.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.
=========================================================================*/
#include "vtkPolyDataTangents.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkPolygon.h"
#include "vtkPriorityQueue.h"
#include "vtkTriangleStrip.h"
#include "vtkSMPTools.h"
struct TangentComputation
{
TangentComputation(vtkIdType offset, vtkPoints* points, vtkCellArray* triangles,
vtkDataArray* tcoords, vtkDataArray* tangents)
{
this->Points = points;
this->Triangles = triangles;
this->TCoords = tcoords;
this->Tangents = tangents;
this->Offset = offset;
}
void operator()(vtkIdType beginId, vtkIdType endId)
{
for (vtkIdType cellId = beginId; cellId < endId; cellId++)
{
double tangent[3];
if (cellId >= this->Offset)
{
vtkIdType npts;
vtkIdType* pts;
this->Triangles->GetCell(4 * cellId, npts, pts);
// compute edges
double v1[3], v2[3], v3[3];
this->Points->GetPoint(pts[0], v1);
this->Points->GetPoint(pts[1], v2);
this->Points->GetPoint(pts[2], v3);
double ax, ay, az, bx, by, bz;
ax = v3[0] - v2[0];
ay = v3[1] - v2[1];
az = v3[2] - v2[2];
bx = v1[0] - v2[0];
by = v1[1] - v2[1];
bz = v1[2] - v2[2];
// compute uv direction
double uv1[2], uv2[2], uv3[2];
this->TCoords->GetTuple(pts[0], uv1);
this->TCoords->GetTuple(pts[1], uv2);
this->TCoords->GetTuple(pts[2], uv3);
double dUV1_x = uv3[0] - uv2[0];
double dUV1_y = uv3[1] - uv2[1];
double dUV2_x = uv1[0] - uv2[0];
double dUV2_y = uv1[1] - uv2[1];
double f = 1.0 / (dUV1_x * dUV2_y - dUV2_x * dUV1_y);
tangent[0] = f * (dUV2_y * ax - dUV1_y * bx);
tangent[1] = f * (dUV2_y * ay - dUV1_y * by);
tangent[2] = f * (dUV2_y * az - dUV1_y * bz);
}
else
{
tangent[0] = 1.0;
tangent[1] = 0.0;
tangent[2] = 0.0;
}
this->Tangents->SetTuple(cellId, tangent);
}
}
private:
vtkPoints* Points;
vtkCellArray* Triangles;
vtkDataArray* TCoords;
vtkDataArray* Tangents;
vtkIdType Offset;
};
vtkStandardNewMacro(vtkPolyDataTangents);
//------------------------------------------------------------------------------
int vtkPolyDataTangents::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkPolyData* input = vtkPolyData::GetData(inputVector[0]);
vtkPolyData* output = vtkPolyData::GetData(outputVector);
if (input->GetPointData()->GetTCoords() == nullptr)
{
vtkErrorMacro("Texture coordinates are requested to generate tangents.");
return 0;
}
vtkPoints* inPts = input->GetPoints();
vtkCellArray* inPolys = input->GetPolys();
vtkPointData* pd = input->GetPointData();
vtkPointData* outPD = output->GetPointData();
vtkDataArray* tcoords = pd->GetTCoords();
vtkIdType numPolys = input->GetNumberOfPolys();
if (4 * numPolys != inPolys->GetNumberOfConnectivityEntries() || input->GetNumberOfStrips() > 0)
{
vtkErrorMacro("This filter only supports triangles, triangulate first.");
return 0;
}
vtkIdType numVerts = input->GetNumberOfVerts();
vtkIdType numLines = input->GetNumberOfLines();
// Initial pass to compute polygon tangents without effects of neighbors
vtkNew<vtkFloatArray> cellTangents;
cellTangents->SetNumberOfComponents(3);
cellTangents->SetName("Tangents");
cellTangents->SetNumberOfTuples(numVerts + numLines + numPolys);
TangentComputation functor(numVerts + numLines, inPts, inPolys, tcoords, cellTangents);
vtkSMPTools::For(0, numVerts + numLines + numPolys, functor);
outPD->PassData(pd);
this->UpdateProgress(0.8);
vtkIdType numPts = input->GetNumberOfPoints();
vtkNew<vtkFloatArray> pointTangents;
pointTangents->SetNumberOfComponents(3);
pointTangents->SetNumberOfTuples(numPts);
pointTangents->SetName("Tangents");
float* fTangents = pointTangents->GetPointer(0);
std::fill_n(fTangents, 3 * numPts, 0);
float* fCellTangents = cellTangents->GetPointer(0);
if (this->ComputePointTangents)
{
vtkIdType cellId = 0;
vtkIdType npts;
vtkIdType* pts;
for (inPolys->InitTraversal(); inPolys->GetNextCell(npts, pts); ++cellId)
{
for (vtkIdType i = 0; i < npts; ++i)
{
fTangents[3 * pts[i]] += fCellTangents[3 * cellId];
fTangents[3 * pts[i] + 1] += fCellTangents[3 * cellId + 1];
fTangents[3 * pts[i] + 2] += fCellTangents[3 * cellId + 2];
}
}
for (vtkIdType i = 0; i < numPts; ++i)
{
vtkMath::Normalize(fTangents + 3 * i);
}
outPD->SetTangents(pointTangents);
}
output->SetPoints(inPts);
if (this->ComputeCellTangents)
{
output->GetCellData()->SetTangents(cellTangents);
}
output->SetPolys(inPolys);
// copy the original vertices and lines to the output
output->SetVerts(input->GetVerts());
output->SetLines(input->GetLines());
return 1;
}
//------------------------------------------------------------------------------
void vtkPolyDataTangents::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Compute Point Tangents: " << (this->ComputePointTangents ? "On\n" : "Off\n");
os << indent << "Compute Cell Tangents: " << (this->ComputeCellTangents ? "On\n" : "Off\n");
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyDataTangents.h
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.
=========================================================================*/
/**
* @class vtkPolyDataTangents
* @brief compute tangents for triangulated polydata
*
* vtkPolyDataTangents is a filter that computes point and/or cell tangents for a triangulated
* polydata.
* This filter requires an input with both normals and tcoords on points.
*/
#ifndef vtkPolyDataTangents_h
#define vtkPolyDataTangents_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
class vtkFloatArray;
class vtkIdList;
class vtkPolyData;
class VTKFILTERSCORE_EXPORT vtkPolyDataTangents : public vtkPolyDataAlgorithm
{
public:
vtkTypeMacro(vtkPolyDataTangents, vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkPolyDataTangents* New();
//@{
/**
* Turn on/off the computation of point tangents.
* Default is true.
*/
vtkSetMacro(ComputePointTangents, bool);
vtkGetMacro(ComputePointTangents, bool);
vtkBooleanMacro(ComputePointTangents, bool);
//@}
//@{
/**
* Turn on/off the computation of cell tangents.
* Default is false.
*/
vtkSetMacro(ComputeCellTangents, bool);
vtkGetMacro(ComputeCellTangents, bool);
vtkBooleanMacro(ComputeCellTangents, bool);
//@}
protected:
vtkPolyDataTangents() = default;
~vtkPolyDataTangents() override = default;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
bool ComputePointTangents = true;
bool ComputeCellTangents = false;
private:
vtkPolyDataTangents(const vtkPolyDataTangents&) = delete;
void operator=(const vtkPolyDataTangents&) = delete;
};
#endif
......@@ -64,6 +64,14 @@ vtkProperty::vtkProperty()
this->VertexColor[1] = 1.0;
this->VertexColor[2] = 0.5;
this->EmissiveFactor[0] = 1.0;
this->EmissiveFactor[1] = 1.0;
this->EmissiveFactor[2] = 1.0;
this->NormalScale = 1.0;
this->OcclusionStrength = 1.0;
this->Metallic = 0.0;
this->Roughness = 0.5;
this->Ambient = 0.0;
this->Diffuse = 1.0;
this->Specular = 0.0;
......
......@@ -40,6 +40,7 @@
#define VTK_FLAT 0
#define VTK_GOURAUD 1
#define VTK_PHONG 2
#define VTK_PBR 3
// representation models
#define VTK_POINTS 0
......@@ -139,7 +140,7 @@ public:
/**
* Set the shading interpolation method for an object.
*/
vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PHONG);
vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
vtkGetMacro(Interpolation,int);
void SetInterpolationToFlat()
{ this->SetInterpolation(VTK_FLAT); }
......@@ -147,6 +148,8 @@ public:
{ this->SetInterpolation(VTK_GOURAUD); }
void SetInterpolationToPhong()
{ this->SetInterpolation(VTK_PHONG); }
void SetInterpolationToPBR()
{ this->SetInterpolation(VTK_PBR); }
const char *GetInterpolationAsString();
//@}
......@@ -178,6 +181,61 @@ public:
void GetColor(double &r, double &g, double &b);
//@}
//@{
/**
* Set/Get the metallic coefficient.
* Usually this value is either 0 or 1 for real material but any value in between is valid.
* This parameter is only used by PBR Interpolation.
* Default value is 0.0
*/
vtkSetClampMacro(Metallic, double, 0.0, 1.0);
vtkGetMacro(Metallic, double);
//@}
//@{
/**
* Set/Get the roughness coefficient.
* This value have to be between 0 (glossy) and 1 (rough).
* A glossy material have reflections and a high specular part.
* This parameter is only used by PBR Interpolation.
* Default value is 0.5
*/
vtkSetClampMacro(Roughness, double, 0.0, 1.0);
vtkGetMacro(Roughness, double);
//@}
//@{
/**
* Set/Get the normal scale coefficient.
* This value affects the strength of the normal deviation from the texture.
* Default value is 1.0
*/
vtkSetMacro(NormalScale, double);
vtkGetMacro(NormalScale, double);
//@}
//@{
/**
* Set/Get the occlusion strength coefficient.
* This value affects the strength of the occlusion if a material texture is present.
* This parameter is only used by PBR Interpolation.
* Default value is 1.0
*/
vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
vtkGetMacro(OcclusionStrength, double);
//@}
//@{
/**
* Set/Get the emissive factor.
* This value is multiplied with the emissive color when an emissive texture is present.
* This parameter is only used by PBR Interpolation.
* Default value is [1.0, 1.0, 1.0]
*/
vtkSetVector3Macro(EmissiveFactor, double);
vtkGetVector3Macro(EmissiveFactor, double);
//@}
//@{
/**
* Set/Get the ambient lighting coefficient.
......@@ -233,6 +291,7 @@ public:
//@{
/**
* Set/Get the diffuse surface color.
* For PBR Interpolation, DiffuseColor is used as the base color
*/
vtkSetVector3Macro(DiffuseColor, double);
vtkGetVector3Macro(DiffuseColor, double);
......@@ -432,11 +491,49 @@ public:
* must be assigned unique names. Note that for texture blending the
* textures will be rendering is alphabetical order and after any texture
* defined in the actor.
* There exists 4 special textures with reserved names: "albedoTex", "materialTex", "normalTex"
* and "emissiveTex". While these textures can be added with the regular SetTexture method, it is
* prefered to use to method SetBaseColorTexture, SetORMTexture, SetNormalTexture and
* SetEmissiveTexture respectively.
*/
void SetTexture(const char* name, vtkTexture* texture);
vtkTexture* GetTexture(const char* name);
//@}
/**
* Set the base color texture. Also called albedo, this texture is only used while rendering
* with PBR interpolation. This is the color of the object.
* @sa SetInterpolationToPBR
*/
void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
/**
* Set the ORM texture. This texture contains three RGB independent components corresponding to
* the Occlusion value, Roughness value and Metallic value respectively.
* Each texture value is scaled by the Occlusion strength, roughness coefficient and metallic
* coefficient.
* This is only used by the PBR shading model.
* @sa SetInterpolationToPBR SetOcclusionStrength SetMetallic SetRoughness
*/
void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
/**
* Set the normal texture. This texture is required for normal mapping. It is valid for both PBR
* and Phong interpolation.
* The normal mapping is enabled if this texture is present and both normals and tangents are
* presents in the vtkPolyData.
* @sa vtkPolyDataTangents SetNormalScale
*/
void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
/**
* Set the emissive texture. When present, this RGB texture provides location and color to the
* shader where the vtkPolyData should emit light. Emited light is scaled by EmissiveFactor.
* This is only supported by PBR interpolation model.
* @sa SetInterpolationToPBR SetEmissiveFactor
*/
void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
/**
* Remove a texture from the collection.
*/
......@@ -493,6 +590,11 @@ protected:
double VertexColor[3];
double Ambient;
double Diffuse;
double Metallic;
double Roughness;
double NormalScale;
double OcclusionStrength;
double EmissiveFactor[3];
double Specular;
double SpecularPower;
double Opacity;
......@@ -539,10 +641,14 @@ inline const char *vtkProperty::GetInterpolationAsString(void)
{
return "Gouraud";
}
else
else if (this->Interpolation == VTK_PHONG)
{
return "Phong";
}
else // if (this->Interpolation == VTK_PBR)
{
return "Physically based rendering";
}
}
//@}
......
......@@ -52,6 +52,7 @@ vtkCxxSetObjectMacro(vtkRenderer, BackgroundTexture, vtkTexture);
vtkCxxSetObjectMacro(vtkRenderer, RightBackgroundTexture, vtkTexture);
vtkCxxSetObjectMacro(vtkRenderer, Pass, vtkRenderPass);
vtkCxxSetObjectMacro(vtkRenderer, FXAAOptions, vtkFXAAOptions);
vtkCxxSetObjectMacro(vtkRenderer, EnvironmentCubeMap, vtkTexture);
//----------------------------------------------------------------------------
// Return NULL if no override is supplied.
......@@ -147,6 +148,9 @@ vtkRenderer::vtkRenderer()
this->Information = vtkInformation::New();
this->Information->Register(this);
this->Information->Delete();
this->UseImageBasedLighting = false;
this->EnvironmentCubeMap = nullptr;
}
vtkRenderer::~vtkRenderer()
......@@ -198,6 +202,11 @@ vtkRenderer::~vtkRenderer()
}
this->SetInformation(nullptr);
if (this->EnvironmentCubeMap != nullptr)
{
this->EnvironmentCubeMap->Delete();
}
}
void vtkRenderer::SetLeftBackgroundTexture(vtkTexture* texture)
......
......@@ -745,6 +745,26 @@ public:
virtual void SetInformation(vtkInformation*);
//@}
//@{
/**
* If this flag is true and the rendering engine supports it, image based
* lighting is enabled and surface rendering displays environment reflections.
* The input cube map have to be set with SetEnvironmentCubeMap.
* If not cubemap is specified, this feature is disable.
*/
vtkSetMacro(UseImageBasedLighting, bool)
vtkGetMacro(UseImageBasedLighting, bool)
vtkBooleanMacro(UseImageBasedLighting, bool)
//@}
//@{
/**
* Set/Get the environment cubemap used for image based lighting.
*/
vtkGetObjectMacro(EnvironmentCubeMap, vtkTexture);
virtual void SetEnvironmentCubeMap(vtkTexture*);
//@}
protected:
vtkRenderer();
~vtkRenderer() override;
......@@ -976,6 +996,9 @@ protected:
// Arbitrary extra information associated with this renderer
vtkInformation* Information;
bool UseImageBasedLighting;
vtkTexture* EnvironmentCubeMap;
private:
vtkRenderer(const vtkRenderer&) = delete;
void operator=(const vtkRenderer&) = delete;
......
......@@ -74,6 +74,9 @@ set(classes
vtkPanoramicProjectionPass
vtkPixelBufferObject
vtkPointFillPass
vtkPBRIrradianceTexture
vtkPBRLUTTexture
vtkPBRPrefilterTexture
vtkRenderPassCollection
vtkRenderStepsPass
vtkRenderbuffer
......
......@@ -3,6 +3,7 @@ vtk_module_test_data(
Data/bunny.ply
Data/clouds.jpeg
Data/dragon.ply
Data/normalMapping.png
Data/skybox-nx.jpg
Data/skybox-ny.jpg
Data/skybox-nz.jpg
......@@ -10,6 +11,7 @@ vtk_module_test_data(
Data/skybox-py.jpg
Data/skybox-pz.jpg
Data/skybox/,REGEX:.*\.jpg
Data/,REGEX:vtk_.*\.png
Data/wintersun.jpg)
add_subdirectory(Cxx)
......
......@@ -26,8 +26,11 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests
TestLightingMapLuminancePass.cxx
TestLightingMapNormalsPass.cxx
TestMultiTexturing.cxx
TestNormalMapping.cxx
TestOffscreenRenderingResize.cxx
TestOrderIndependentTranslucentPass.cxx
TestPBRMapping.cxx
TestPBRMaterials.cxx
TestPanoramicProjectionPass.cxx,NO_DATA
TestPointFillPass.cxx
TestPointGaussianSelection.cxx,NO_DATA
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestNormalMapping.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 normal mapping feature
// Texture credits:
// Julian Herzog, CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
// The image has been cropped and resized
#include "vtkActor.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkLight.h"
#include "vtkNew.h"
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkPNGReader.h"
#include "vtkPlaneSource.h"
#include "vtkPolyDataTangents.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
#include "vtkTriangleFilter.h"
//----------------------------------------------------------------------------
int TestNormalMapping(int argc, char* argv[])
{
vtkNew<vtkRenderer> renderer;
renderer->AutomaticLightCreationOff();
vtkNew<vtkLight> light;
light->SetPosition(0.5, 0.5, 1.0);
light->SetFocalPoint(0.0, 0.0, 0.0);
renderer->AddLight(light);
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 600);
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkPlaneSource> plane;
vtkNew<vtkTriangleFilter> triangulation;
triangulation->SetInputConnection(plane->GetOutputPort());
vtkNew<vtkPolyDataTangents> tangents;
tangents->SetInputConnection(triangulation->GetOutputPort());
vtkNew<vtkPNGReader> png;
png->SetFileName(vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/normalMapping.png"));
vtkNew<vtkTexture> texture;
texture->SetInputConnection(png->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(tangents->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetNormalTexture(texture);
renderer->AddActor(actor);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestPBRMapping.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 Interpolation shading
// It renders a cube with custom texture mapping
#include "vtkActor.h"
#include "vtkActorCollection.h"
#include "vtkCamera.h"
#include "vtkCubeSource.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 "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 "vtkOpenGLRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
#include "vtkTriangleFilter.h"
//----------------------------------------------------------------------------
int TestPBRMapping(int argc, char* argv[])
{
vtkNew<vtkOpenGLRenderer> renderer;
renderer->AutomaticLightCreationOff();
vtkNew<vtkLight> light;
light->SetPosition(2.0, 0.0, 2.0);
light->SetFocalPoint(0.0, 0.0, 0.0);
renderer->AddLight(light);
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 600);
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkPBRIrradianceTexture> irradiance = renderer->GetEnvMapIrradiance();
irradiance->SetIrradianceStep(0.3);
vtkSmartPointer<vtkPBRPrefilterTexture> prefilter = renderer->GetEnvMapPrefiltered();
prefilter->SetPrefilterSamples(64);
prefilter->SetPrefilterSize(64);
vtkNew<vtkOpenGLTexture> textureCubemap;
textureCubemap->CubeMapOn();
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<vtkJPEGReader> jpg;
jpg->SetFileName(vtkTestUtilities::ExpandDataFileName(argc, argv, pathSkybox[i].c_str()));
vtkNew<vtkImageFlip> flip;
flip->SetInputConnection(jpg->GetOutputPort());
flip->SetFilteredAxis(1); // flip y axis
textureCubemap->SetInputConnection(i, flip->GetOutputPort());
}
renderer->SetEnvironmentCubeMap(textureCubemap);
renderer->UseImageBasedLightingOn();
vtkNew<vtkCubeSource> cube;
vtkNew<vtkTriangleFilter> triangulation;
triangulation->SetInputConnection(cube->GetOutputPort());
vtkNew<vtkPolyDataTangents> tangents;
tangents->SetInputConnection(triangulation->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(tangents->GetOutputPort());
vtkNew<vtkPNGReader> materialReader;
materialReader->SetFileName(
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Material.png"));
vtkNew<vtkTexture> material;
material->InterpolateOn();
material->SetInputConnection(materialReader->GetOutputPort());
vtkNew<vtkPNGReader> albedoReader;
albedoReader->SetFileName(
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Base_Color.png"));
vtkNew<vtkTexture> albedo;
albedo->InterpolateOn();
albedo->SetInputConnection(albedoReader->GetOutputPort());
vtkNew<vtkPNGReader> normalReader;
normalReader->SetFileName(
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vtk_Normal.png"));
vtkNew<vtkTexture> normal;
normal->InterpolateOn();
normal->SetInputConnection(normalReader->GetOutputPort());
vtkNew<vtkActor> 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()->SetBaseColorTexture(albedo);
actor->GetProperty()->SetORMTexture(material);
actor->GetProperty()->SetNormalTexture(normal);
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;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestPBRMaterials.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 Interpolation shading
// It renders spheres with different materials using a skybox as image based lighting
#include "vtkActor.h"
#include "vtkActorCollection.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkImageData.h"
#include "vtkImageFlip.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkJPEGReader.h"
#include "vtkNew.h"
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkOpenGLSkybox.h"
#include "vtkOpenGLTexture.h"
#include "vtkPBRIrradianceTexture.h"
#include "vtkPBRLUTTexture.h"
#include "vtkPBRPrefilterTexture.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkOpenGLRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkSphereSource.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
//----------------------------------------------------------------------------
int TestPBRMaterials(int argc, char* argv[])
{
vtkNew<vtkOpenGLRenderer> renderer;
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 600);
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkOpenGLSkybox> skybox;
vtkSmartPointer<vtkPBRIrradianceTexture> irradiance = renderer->GetEnvMapIrradiance();
irradiance->SetIrradianceStep(0.3);
vtkSmartPointer<vtkPBRPrefilterTexture> prefilter = renderer->GetEnvMapPrefiltered();
prefilter->SetPrefilterSamples(64);
prefilter->SetPrefilterSize(64);
vtkNew<vtkOpenGLTexture> textureCubemap;
textureCubemap->CubeMapOn();
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<vtkJPEGReader> jpg;
jpg->SetFileName(vtkTestUtilities::ExpandDataFileName(argc, argv, pathSkybox[i].c_str()));
vtkNew<vtkImageFlip> flip;
flip->SetInputConnection(jpg->GetOutputPort());
flip->SetFilteredAxis(1); // flip y axis
textureCubemap->SetInputConnection(i, flip->GetOutputPort());
}
renderer->SetEnvironmentCubeMap(textureCubemap);
renderer->UseImageBasedLightingOn();
vtkNew<vtkSphereSource> sphere;
sphere->SetThetaResolution(100);
sphere->SetPhiResolution(100);
vtkNew<vtkPolyDataMapper> pdSphere;
pdSphere->SetInputConnection(sphere->GetOutputPort());
for (int i = 0; i < 6; i++)
{
vtkNew<vtkActor> actorSphere;
actorSphere->SetPosition(i, 0.0, 0.0);
actorSphere->SetMapper(pdSphere);
actorSphere->GetProperty()->SetInterpolationToPBR();
actorSphere->GetProperty()->SetColor(1.0, 1.0, 1.0);
actorSphere->GetProperty()->SetOpacity(1.0);
actorSphere->GetProperty()->SetMetallic(1.0);
actorSphere->GetProperty()->SetRoughness(i / 5.0);
renderer->AddActor(actorSphere);
}
for (int i = 0; i < 6; i++)
{
vtkNew<vtkActor> actorSphere;
actorSphere->SetPosition(i, 1.0, 0.0);
actorSphere->SetMapper(pdSphere);
actorSphere->GetProperty()->SetInterpolationToPBR();
actorSphere->GetProperty()->SetColor(0.72, 0.45, 0.2);
actorSphere->GetProperty()->SetOpacity(1.0);
actorSphere->GetProperty()->SetMetallic(1.0);
actorSphere->GetProperty()->SetRoughness(i / 5.0);
renderer->AddActor(actorSphere);
}
for (int i = 0; i < 6; i++)
{
vtkNew<vtkActor> actorSphere;
actorSphere->SetPosition(i, 2.0, 0.0);
actorSphere->SetMapper(pdSphere);
actorSphere->GetProperty()->SetInterpolationToPBR();
actorSphere->GetProperty()->SetColor(0.0, 0.0, 0.0);
actorSphere->GetProperty()->SetOpacity(1.0);
actorSphere->GetProperty()->SetMetallic(0.0);
actorSphere->GetProperty()->SetRoughness(i / 5.0);
renderer->AddActor(actorSphere);
}
for (int i = 0; i < 6; i++)
{
vtkNew<vtkActor> actorSphere;
actorSphere->SetPosition(i, 3.0, 0.0);
actorSphere->SetMapper(pdSphere);
actorSphere->GetProperty()->SetInterpolationToPBR();
actorSphere->GetProperty()->SetColor(0.0, 1.0, 1.0);
actorSphere->GetProperty()->SetOpacity(1.0);
actorSphere->GetProperty()->SetMetallic(0.0);
actorSphere->GetProperty()->SetRoughness(i / 5.0);
renderer->AddActor(actorSphere);
}
for (int i = 0; i < 6; i++)
{
vtkNew<vtkActor> actorSphere;
actorSphere->SetPosition(i, 4.0, 0.0);
actorSphere->SetMapper(pdSphere);
actorSphere->GetProperty()->SetInterpolationToPBR();
actorSphere->GetProperty()->SetColor(1.0, 0.0, 0.0);
actorSphere->GetProperty()->SetOpacity(1.0);
actorSphere->GetProperty()->SetMetallic(0.0);
actorSphere->GetProperty()->SetRoughness(i / 5.0);
renderer->AddActor(actorSphere);
}
skybox->SetTexture(irradiance);
renderer->AddActor(skybox);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
be2e31a079320adf95c2980fc263b40809e5c16975b8b05d41104773824d03a0f7ec4afa6091caaa395ff2fba4f73b344bef621c3d81501922af7c1b9df28c42
8764e019bc9cdf2d4b12a548506f90f80ebd19db234461189a5ea88d13467cbcb04165aed06a3772e625c5eccb24f452044f48a79d57b306368f2a06463faa66
860512fe3191873a90e64c2f32c15d2c9e089d6d2962c76e5de46ef9c5102b131d7dcf3242557c67ab483322c4f33cd7d854198572a50fe67de18eb859fd8a2b
......@@ -32,6 +32,9 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLState.h"
#include "vtkOrderIndependentTranslucentPass.h"
#include "vtkPBRIrradianceTexture.h"
#include "vtkPBRLUTTexture.h"
#include "vtkPBRPrefilterTexture.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
......@@ -77,6 +80,10 @@ vtkOpenGLRenderer::vtkOpenGLRenderer()
this->LightingCount = -1;
this->LightingComplexity = -1;
this->EnvMapLookupTable = nullptr;
this->EnvMapIrradiance = nullptr;
this->EnvMapPrefiltered = nullptr;
}
// Ask lights to load themselves into graphics pipeline.
......@@ -209,6 +216,13 @@ void vtkOpenGLRenderer::DeviceRender()
{
vtkTimerLog::MarkStartEvent("OpenGL Dev Render");
if (this->UseImageBasedLighting && this->EnvironmentCubeMap)
{
this->GetEnvMapLookupTable()->Load(this);
this->GetEnvMapIrradiance()->Load(this);
this->GetEnvMapPrefiltered()->Load(this);
}
if(this->Pass!=nullptr)
{
vtkRenderState s(this);
......@@ -233,6 +247,13 @@ void vtkOpenGLRenderer::DeviceRender()
vtkOpenGLCheckErrorMacro("failed after DeviceRender");
}
if (this->UseImageBasedLighting && this->EnvironmentCubeMap)
{
this->GetEnvMapLookupTable()->PostRender(this);
this->GetEnvMapIrradiance()->PostRender(this);
this->GetEnvMapPrefiltered()->PostRender(this);
}
vtkTimerLog::MarkEndEvent("OpenGL Dev Render");
}
......@@ -720,6 +741,24 @@ vtkOpenGLRenderer::~vtkOpenGLRenderer()
this->TranslucentPass->Delete();
this->TranslucentPass = nullptr;
}
if (this->EnvMapLookupTable)
{
this->EnvMapLookupTable->Delete();
this->EnvMapLookupTable = nullptr;
}
if (this->EnvMapIrradiance)
{
this->EnvMapIrradiance->Delete();
this->EnvMapIrradiance = nullptr;
}
if (this->EnvMapPrefiltered)
{
this->EnvMapPrefiltered->Delete();
this->EnvMapPrefiltered = nullptr;
}
}
bool vtkOpenGLRenderer::HaveApplePrimitiveIdBug()
......@@ -980,3 +1019,53 @@ void vtkOpenGLRenderer::SetUserLightTransform(vtkTransform* transform)
{
this->UserLightTransform = transform;
}
void vtkOpenGLRenderer::SetEnvironmentCubeMap(vtkTexture* cubemap)
{
this->Superclass::SetEnvironmentCubeMap(cubemap);
vtkOpenGLTexture* oglCubemap = vtkOpenGLTexture::SafeDownCast(cubemap);
if (oglCubemap)
{
if (oglCubemap->GetCubeMap())
{
this->GetEnvMapIrradiance()->SetInputCubeMap(oglCubemap);
this->GetEnvMapPrefiltered()->SetInputCubeMap(oglCubemap);
}
else
{
vtkErrorMacro("The environment texture is not a cube map");
}
}
}
// ----------------------------------------------------------------------------
vtkPBRLUTTexture* vtkOpenGLRenderer::GetEnvMapLookupTable()
{
if (!this->EnvMapLookupTable)
{
this->EnvMapLookupTable = vtkPBRLUTTexture::New();
}
return this->EnvMapLookupTable;
}
// ----------------------------------------------------------------------------
vtkPBRIrradianceTexture* vtkOpenGLRenderer::GetEnvMapIrradiance()
{
if (!this->EnvMapIrradiance)
{
this->EnvMapIrradiance = vtkPBRIrradianceTexture::New();
}
return this->EnvMapIrradiance;
}
// ----------------------------------------------------------------------------
vtkPBRPrefilterTexture* vtkOpenGLRenderer::GetEnvMapPrefiltered()
{
if (!this->EnvMapPrefiltered)
{
this->EnvMapPrefiltered = vtkPBRPrefilterTexture::New();
}
return this->EnvMapPrefiltered;
}
......@@ -36,6 +36,9 @@ class vtkOpenGLTexture;
class vtkOrderIndependentTranslucentPass;
class vtkTextureObject;
class vtkDepthPeelingPass;
class vtkPBRIrradianceTexture;
class vtkPBRLUTTexture;
class vtkPBRPrefilterTexture;
class vtkShaderProgram;
class vtkShadowMapPass;
......@@ -134,6 +137,20 @@ public:
*/
void SetUserLightTransform(vtkTransform* transform);
//@{
/**
* Get environment textures used for image based lighting.
*/
vtkPBRLUTTexture* GetEnvMapLookupTable();
vtkPBRIrradianceTexture* GetEnvMapIrradiance();
vtkPBRPrefilterTexture* GetEnvMapPrefiltered();
//@}
/**
* Overriden in order to connect the cubemap to the environment map textures.
*/
void SetEnvironmentCubeMap(vtkTexture*) override;
protected:
vtkOpenGLRenderer();
~vtkOpenGLRenderer() override;
......@@ -203,6 +220,10 @@ protected:
*/
vtkSmartPointer<vtkTransform> UserLightTransform;
vtkPBRLUTTexture* EnvMapLookupTable;
vtkPBRIrradianceTexture* EnvMapIrradiance;
vtkPBRPrefilterTexture* EnvMapPrefiltered;
private:
vtkOpenGLRenderer(const vtkOpenGLRenderer&) = delete;
void operator=(const vtkOpenGLRenderer&) = delete;
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPBRIrradianceTexture.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.
=========================================================================*/
#include "vtkPBRIrradianceTexture.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLFramebufferObject.h"
#include "vtkOpenGLQuadHelper.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLState.h"
#include "vtkRenderer.h"
#include "vtkShaderProgram.h"
#include "vtkTextureObject.h"
#include "vtk_glew.h"
#include <sstream>
vtkStandardNewMacro(vtkPBRIrradianceTexture);
vtkCxxSetObjectMacro(vtkPBRIrradianceTexture, InputCubeMap, vtkOpenGLTexture);
//------------------------------------------------------------------------------
vtkPBRIrradianceTexture::~vtkPBRIrradianceTexture()
{
if (this->InputCubeMap)
{
this->InputCubeMap->Delete();
}
}
//------------------------------------------------------------------------------
void vtkPBRIrradianceTexture::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "IrradianceStep: " << this->Ir